summaryrefslogtreecommitdiff
path: root/src/example/03_texture/03_texture.c
blob: 23597c954148c33e13a3b440b0a2596484ca620a (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "../example.h"
#include "../../extend/mesh.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 Vertex verts[] = {
	{0, {1, 1, 1}, {1, 1, 1}, zerovec3, {1, 1}, 0xffff0000},
	{1, {-1, 1, 1}, {-1, 1, 1}, zerovec3, {0, 1},0xff00ff00},
	{2, {-1, -1, 1}, {-1, -1, 1}, zerovec3, {0, 0}, 0xff0000ff},
	{3, {1, -1, 1}, {1, -1, 1}, zerovec3, {1, 0}, 0xffff00ff},
	{4, {1, 1, -1}, {1, 1, -1}, zerovec3, {1, 0} , 0xffaa28aa},
	{5, {-1, 1, -1}, {-1, 1, -1}, zerovec3, {0, 0},0xffFFC58E},
	{6, {-1, -1, -1}, {-1, -1, -1}, zerovec3, {0, 1}, 0xffA100FF},
	{7, {1, -1, -1}, {1, -1, -1}, zerovec3, {1, 1} , 0xffFAFF00},
};

extern Program ssr_built_in_shader_pbr;

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

static Texture* mech_albedo;
static Texture* mech_normal;
static Texture* mech_roughness;
static Texture* mech_metalness;
static Mesh* mech_mesh;

static Texture* ground_albedo;
static Mesh* ground_mesh;

static Texture* yingham_albedo;
static Mesh* yingham_mesh;

static Texture* cyborg_albedo;
static Mesh* cyborg_mesh;

static Texture* ball_albedo; 
static Mesh* ball_mesh;

Texture* base_color_texs[];

EXAMPLE void onload_texture(void* data) {
	CameraConfig* conf = (CameraConfig*)data;

	//mech_albedo = texture_loadfromfile("res/dieselpunk/mech_basecolor.tga");
	//mech_albedo = texture_loadfromfile("res/station/textures/projekt_Gas_BaseColor.png");
	mech_albedo = texture_loadfromfile("res/townscaper/town_diffuse.jpg");
	mech_normal = texture_loadfromfile("res/dieselpunk/mech_normal.tga");
	mech_roughness = texture_loadfromfile("res/dieselpunk/mech_roughness.tga");
	mech_metalness = texture_loadfromfile("res/dieselpunk/mech_metalness.tga");
	mech_mesh = mesh_loadfromobj("res/townscaper/town.obj");
	//mech_mesh = mesh_loadfromobj("res/gun/gun.obj");
	//mech_mesh = mesh_loadfromobj("res/station/station.obj");
	//mech_mesh = mesh_loadfromobj("res/gun/triangle.obj");
	ground_albedo = texture_loadfromfile("res/dieselpunk/ground_basecolor.tga");
	ground_mesh = mesh_loadfromobj("res/dieselpunk/ground.obj");
	yingham_albedo = texture_loadfromfile("res/dieselpunk/yingham_basecolor.tga");
	yingham_mesh = mesh_loadfromobj("res/dieselpunk/yingham.obj");

	cyborg_albedo = texture_loadfromfile("res/cyborg/cyborg_diffuse.png");
	cyborg_mesh = mesh_loadfromobj("res/cyborg/cyborg.obj");
}

EXAMPLE void onevent_texture(void* data) {
	wog_Event* e = (wog_Event*)data;
}

EXAMPLE void onupdate_texture(void*data) {
	ssr_matrixmode(MATRIX_MODEL);
	ssr_loadidentity();
	ssr_scale(100,100,100);
	
	Vec3 light = {1, 0, 0};
	ssr_setuniformvec3(0, &light);

	Mat4 world2object;
	ssr_getm(&world2object);

	ssr_setuniformmat4(0, &world2object);
}

EXAMPLE void ondraw_texture(void*data) {
	//ssr_bindvertices(verts, 8, cube, 12);
	ssr_useprogram(&ssr_built_in_shader_pbr);
	ssr_enable(ENABLE_BACKFACECULL | ENABLE_DEPTHTEST | ENABLE_WRITEDEPTH | ENABLE_BLEND);

	ssr_setblendfunc(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);

	ssr_clearcolor(0xff202020);
	ssr_cleardepth();
	ssr_clearstencil(0);
/*
	ssr_enable(ENABLE_STENCILTEST);
	ssr_setstencilfunc(STENCILFUNC_ALWAYS, 1, 0xff);
	ssr_setstencilop(STENCILOP_KEEP, STENCILOP_KEEP, STENCILOP_REPLACE);
*/

	/*render mech*/
	ssr_setuniformtex(0, mech_albedo);
	ssr_setuniformtex(1, mech_normal);
	ssr_setuniformtex(2, mech_roughness);
	ssr_setuniformtex(3, mech_metalness);
	ssr_bindvertices(mech_mesh->vertices, mech_mesh->vert_count);
	for (int i = 0; i < mech_mesh->submesh_count; ++i) {
		ssr_bindindices(mech_mesh->submesh[i].triangles, mech_mesh->submesh[i].tris_count);
		ssr_draw(PRIMITIVE_TRIANGLE);
	}

	ssr_unbindvertices();
	ssr_unbindindices();

/*
	ssr_setstencilfunc(STENCILFUNC_EQUAL, 1, 0xff);
	ssr_setstencilop(STENCILOP_KEEP, STENCILOP_KEEP, STENCILOP_KEEP);
*/
	/*render yingham*/
	//ssr_setuniformtex(0, yingham_albedo);
	//ssr_bindvertices(yingham_mesh->vertices, yingham_mesh->vert_count, yingham_mesh->triangles, yingham_mesh->tris_count);
	//ssr_draw(PRIMITIVE_TRIANGLE);

	/*render ground*/
	//ssr_setuniformtex(0, ground_albedo);
	//ssr_bindvertices(ground_mesh->vertices, ground_mesh->vert_count, ground_mesh->triangles, ground_mesh->tris_count);
	//ssr_draw(PRIMITIVE_TRIANGLE);

	//draw_tbn(mech_mesh, VISUAL_ALL, 4);

	//ssr_setuniformtex(0, cyborg_albedo);
	//ssr_bindvertices(cyborg_mesh->vertices, cyborg_mesh->vert_count, cyborg_mesh->triangles, cyborg_mesh->tris_count);
	//ssr_draw(PRIMITIVE_TRIANGLE);

}