0

I'm trying to load a PNG texture in OpenGL using the SOIL libray, and show the texture in GL QUAD, but when I call the function, the image is loaded correctly, but change the color of entire screen!

if a blue image, the screen changes to blue pigment! if red, changes to red! Anyone know what is causing this

Right colours without image loaded: http://i.stack.imgur.com/OHroq.jpg

Wrong colours with image loaded: http://i.stack.imgur.com/LyRwJ.jpg

CODE:

int LoadGLTextures()     {              

  texture[0] = SOIL_load_OGL_texture("test.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);

  glBindTexture(GL_TEXTURE_2D, texture[0]);

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);}

and the square code:

  glBindTexture(GL_TEXTURE_2D, texture[0]);

  glBegin(GL_QUADS);

  glColor3f(1.0f, 1.0f, 1.0f);

  glTexCoord2f(0.0f, 0.0f); glVertex3f(mover, 11.0f,  1.0f);
  glTexCoord2f(1.0f, 0.0f); glVertex3f( mover+44,11.0f,  1.0f);
  glTexCoord2f(1.0f, 1.0f); glVertex3f(mover+44,  44.0f,  1.0f);
  glTexCoord2f(0.0f, 1.0f); glVertex3f(mover,  44.0f,  1.0f);

  glEnd();
}
4

1 回答 1

2

You seem to never disable texturing again. OpenGL is a state machine, so anything you set or enable stays this way until you set something else/disable it. In your case, it looks like you texture this one quad and specify texcoords as you should. But for all other objects, texturing is still on. And texcoords are GL state too. But as you intend to draw untextured, you seem to not set new texcoords for the other quads, all the vertices will use 0.0,1.0 as texcoords, so you basically use an edge texel of your texture to modify the color of all other objects.

于 2013-05-04T13:24:33.860 回答