summaryrefslogtreecommitdiff
path: root/src/example/03_texture.c
blob: 395acfb7a1a09b7c2f08cd1372a8ae55d8066853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "example.h"

static int cube[] = {
	0, 1, 2, 0, 2, 3,
	1, 5, 2, 2, 5, 6,
	4, 6, 5, 4, 7, 6,
	0, 3, 7, 0, 7, 4,
	0, 4, 1, 1, 4, 5,
	2, 6, 3, 3, 6, 7
};

static Vert verts[] = {
	{0, {1, 1, 1}, {1, 1, 1}, zerovec3, zerovec2, 0xffff0000},
	{1, {-1, 1, 1}, {-1, 1, 1}, zerovec3, zerovec2,0xff00ff00},
	{2, {-1, -1, 1}, {-1, -1, 1}, zerovec3, zerovec2, 0xff0000ff},
	{3, {1, -1, 1}, {1, -1, 1}, zerovec3, zerovec2, 0xffff00ff},
	{4, {1, 1, -1}, {1, 1, -1}, zerovec3, zerovec2, 0xffaa28aa},
	{5, {-1, 1, -1}, {-1, 1, -1}, zerovec3, zerovec2,0xffFFC58E},
	{6, {-1, -1, -1}, {-1, -1, -1}, zerovec3, zerovec2, 0xffA100FF},
	{7, {1, -1, -1}, {1, -1, -1}, zerovec3, zerovec2, 0xffFAFF00},
};

extern Program ssr_built_in_shader_unlit;

static Vec3 light = {-1, -1, -1};

void onloadtexture(void* data) {
	ssr_matrixmode(MATRIX_PROJECTION);
	ssr_loadidentity();
	ssr_perspective(90, 1.25f, 0.1f, 10);
	//ssr_ortho(-5, 5, -4, 4, 0.1, 10);
	ssr_matrixmode(MATRIX_VIEW);
	ssr_loadidentity();
	Vec3 p = { 0, 0, 0 }, target = { 0, 0, -1 };
	ssr_lookat(&p, &target, &vec3up);

	ssr_bindvertices(verts, 8, cube, 12);
	ssr_useprogram(&ssr_built_in_shader_unlit);
	ssr_enable(ENABLEMASK_BACKFACECULL);
	ssr_enable(ENABLEMASK_DEPTHTEST);
}

void oneventtexture(void* data) {
	SDL_Event* e = (SDL_Event*)data;
}

static float _t = 0;
static Quat q;

void onupdatetexture(void*data) {
	uint dt = *(uint*)data;
	ssr_matrixmode(MATRIX_MODEL);
	ssr_loadidentity();
	ssr_translate(0, 0, -3);
	ssr_rotate(_t -= dt / 50.f, 1, 0.3, 1);

	Vec3 rot = { 1,1,0 }; vec3_normalize(&rot, &rot);
	quat_fromaxisangle(&rot, 10, &q);
	quat_applytovec3(&q, &light, &light);
	ssr_setuniformvec3(0, &light); /*set light direction*/
}

void ondrawtexture(void*data) {
	ssr_clearcolor(0x00);
	ssr_cleardepth();

	ssr_draw(PRIMITIVE_TRIANGLE);
}