opengl - My texture keeps showing up white on screen -


i cant seem load image , use texture program: image 512*512 in size , dont know im doing wrong, can me?

main function:

int main(int argc, char** argv) {   glutinit (&argc, argv);   glutinitwindowsize (800,600);   glutinitdisplaymode (glut_single | glut_rgb);   glutcreatewindow ("cs248 glut example");   glutdisplayfunc (display);   glutreshapefunc (reshape);   glutmainloop ();   return 0; } 

the display function:

void display() {     glclear(gl_color_buffer_bit);     glenable(gl_texture_2d);     glcolor3f(1.0f,1.0f,1.0f);     texture = loadtexture("space.bmp");     glbindtexture(gl_texture_2d, texture);     glbegin(gl_quads);         gltexcoord2f(0.0, 0.0); glvertex3f(-20.0,-20.0,0);         gltexcoord2f(0.0, 1.0); glvertex3f(-20.0, 20.0, 0.0);         gltexcoord2f(1.0, 1.0); glvertex3f(20.0, 20.0, 0.0);         gltexcoord2f(1.0, 0.0); glvertex3f(20.0, -20.0, 0.0);        glend();     glflush(); } 

so, call here loadtexture function gluint texture, way:

gluint loadtexture( const char* texture ) {     gluint textureid = soil_load_ogl_texture( texture, soil_load_auto, soil_create_new_id, soil_flag_mipmaps );      glgentextures(1,&textureid);     glbindtexture( gl_texture_2d, textureid );     gltexparameteri( gl_texture_2d, gl_texture_min_filter, gl_linear );     gltexparameteri( gl_texture_2d, gl_texture_mag_filter, gl_linear );     gltexparameteri( gl_texture_2d, gl_texture_wrap_s, gl_repeat );     gltexparameteri( gl_texture_2d, gl_texture_wrap_t, gl_repeat );      return textureid; } 

reshape function:

void reshape(glsizei w, glsizei h) { glviewport(0, 0, 800, 600); glmatrixmode(gl_projection); glloadidentity(); glortho(-20.0f, 20.0f, -20.0f, 20.0f, -20.0f, 20.0f); glmatrixmode(gl_modelview); glloadidentity(); } 

includes,etc:

#include <glut.h> #include <soil.h>  gluint texture; 

gluint textureid = soil_load_ogl_texture( texture, soil_load_auto, soil_create_new_id, soil_flag_mipmaps );  glgentextures(1,&textureid); 

soil_load_ogl_texture creates opengl texture object. generating new 1 (which glgentextures does) after creating 1 counter-productive.

ditch line, , you'll ok.

however, should not reloading texture on every display. should creating texture once, during initialization, using texture glbindtexture call.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -