X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fopengl.c;h=80f712d1b36396581bf8679b29698b98aeaf9465;hp=796144c70ca18245dcf2f43351539b1ed659b4c9;hb=da8e3a1dd04a5ac29bcaa9582430c58a769ac571;hpb=794a378d5c8e07c815814324da8142be137406d0 diff --git a/src/opengl.c b/src/opengl.c index 796144c..80f712d 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -1,3 +1,4 @@ +#include #include "opengl.h" #include "logger.h" @@ -16,6 +17,7 @@ int init_opengl(void) glewInit(); glcaps.debug = GLEW_ARB_debug_output; + glcaps.draw_range = GLEW_EXT_draw_range_elements; #ifndef NDEBUG if(glcaps.debug) { @@ -27,6 +29,33 @@ int init_opengl(void) return 0; } +void dump_gl_texture(unsigned int tex, const char *fname) +{ + FILE *fp; + int i, width, height; + unsigned char *pixels; + + glBindTexture(GL_TEXTURE_2D, tex); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); + + if(!(pixels = malloc(width * height * 3))) { + return; + } + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + if(!(fp = fopen(fname, "wb"))) { + free(pixels); + return; + } + fprintf(fp, "P6\n%d %d\n255\n", width, height); + for(i=0; i