c++ - Opengl Texture Mapping of GL_QUADS, got strange result -


i got strange result texture mapping.

i used 128*128 rgba bmp image texture mapping of gl_quads, got following strange result, test other images ok, image, got strange result.

here want map leaf image gl_quads.

the following code:

void init (void) {  glclearcolor(0.6, 0.6, 0.6, 0.0); glcleardepth(1.0); glshademodel(gl_smooth);  gltexparameteri(gl_texture_2d,gl_texture_mag_filter,gl_linear); gltexparameteri(gl_texture_2d,gl_texture_min_filter,gl_linear); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_repeat); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_repeat); glenable(gl_texture_2d);    glutsetcursor(glut_cursor_crosshair); }  void display(){  glclear(gl_color_buffer_bit | gl_depth_buffer_bit); glloadidentity (); glulookat(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);  gluint texture[2];  unsigned int outwidth; unsigned int outheight; unsigned int outdepth;  glgentextures(1, &texture[0]); glbindtexture(gl_texture_2d, texture[0]);  unsigned char * data=loadbmp("leaftest.bmp", outwidth, outheight, outwidth, true);  glubuild2dmipmaps(gl_texture_2d, 4, outwidth, outheight, gl_bgra, gl_unsigned_byte, data);  glbindtexture(gl_texture_2d, texture[0]);  gltexenvf(gl_texture_env,gl_texture_env_mode,gl_replace);     gltranslatef(0, 0, 2);     glrotatef(90, 1, 0, 0);      glbegin(gl_quads);         gltexcoord2f(0.0,0.0);         glvertex3f(0.0,-0.6,-0.3);          gltexcoord2f(0.0,1.0);         glvertex3f(0.0,0.0,-0.3);          gltexcoord2f(1.0,1.0);         glvertex3f(0.0,0.0,0.3);          gltexcoord2f(1.0,0.0);         glvertex3f(0.0,-0.6,0.3);      glend(); glutswapbuffers(); } 

it maybe because do

gltexparameteri(gl_texture_2d,gl_texture_mag_filter,gl_linear); gltexparameteri(gl_texture_2d,gl_texture_min_filter,gl_linear); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_repeat); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_repeat); 

before binding any texture target, plainly wrong , wounder why examples work.

check out tutorials before guys code, example this or buy book or something.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -