nuclear@0: #include nuclear@0: #include nuclear@0: #include "spycam.h" nuclear@0: #include "sdr.h" nuclear@0: nuclear@0: static unsigned int sdr_prog, tex; nuclear@0: static Mat4 world_matrix, view_matrix, proj_matrix; nuclear@0: static int win_width, win_height; nuclear@0: nuclear@0: bool app_init() nuclear@0: { nuclear@0: glClearColor(0.2, 0.2, 0.2, 1); nuclear@0: nuclear@0: if(!(sdr_prog = create_program_load("sdr/vertex.glsl", "sdr/pixel.glsl"))) { nuclear@0: fprintf(stderr, "failed to load shader program\n"); nuclear@0: return false; nuclear@0: } nuclear@0: glUseProgram(sdr_prog); nuclear@0: glBindAttribLocation(sdr_prog, 0, "a_vertex"); nuclear@0: glBindAttribLocation(sdr_prog, 1, "a_texcoord"); nuclear@0: nuclear@0: unsigned char *pixels = new unsigned char[256 * 256 * 3]; nuclear@0: unsigned char *pptr = pixels; nuclear@0: for(int i=0; i<256; i++) { nuclear@0: for(int j=0; j<256; j++) { nuclear@0: bool chess = ((i >> 4) & 1) == ((j >> 4) & 1); nuclear@0: *pptr++ = chess ? 255 : 64; nuclear@0: *pptr++ = 128; nuclear@0: *pptr++ = chess ? 64 : 255; nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: glGenTextures(1, &tex); nuclear@0: glBindTexture(GL_TEXTURE_2D, tex); nuclear@0: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); nuclear@0: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); nuclear@0: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); nuclear@0: glGenerateMipmap(GL_TEXTURE_2D); nuclear@0: delete [] pixels; nuclear@0: nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: void app_cleanup() nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: void app_draw() nuclear@0: { nuclear@0: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); nuclear@0: nuclear@0: glUseProgram(sdr_prog); nuclear@0: set_uniform_matrix4(sdr_prog, "world_mat", world_matrix[0]); nuclear@0: set_uniform_matrix4(sdr_prog, "view_mat", view_matrix[0]); nuclear@0: set_uniform_matrix4(sdr_prog, "proj_mat", proj_matrix[0]); nuclear@0: nuclear@0: glBindTexture(GL_TEXTURE_2D, tex); nuclear@0: nuclear@0: static const float quad_verts[] = {-1, -1, 1, -1, 1, 1, -1, 1}; nuclear@0: static const float quad_texcoords[] = {0, 0, 1, 0, 1, 1, 0, 1}; nuclear@0: static const unsigned int quad_idx[] = {0, 1, 2, 0, 2, 3}; nuclear@0: nuclear@0: glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, quad_verts); nuclear@0: glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, quad_texcoords); nuclear@0: glEnableVertexAttribArray(0); nuclear@0: glEnableVertexAttribArray(1); nuclear@0: nuclear@0: glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, quad_idx); nuclear@0: nuclear@0: glDisableVertexAttribArray(0); nuclear@0: glDisableVertexAttribArray(1); nuclear@0: } nuclear@0: nuclear@0: void app_reshape(int x, int y) nuclear@0: { nuclear@0: win_width = x; nuclear@0: win_height = y; nuclear@0: glViewport(0, 0, x, y); nuclear@0: } nuclear@0: nuclear@0: void app_keyboard(int key, bool press) nuclear@0: { nuclear@0: if(press) { nuclear@0: switch(key) { nuclear@0: case 27: nuclear@0: app_quit(); nuclear@0: break; nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: void app_mouse_button(int bn, bool press, int x, int y) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: void app_mouse_motion(int x, int y) nuclear@0: { nuclear@0: }