Hey, I am creating a game using openGL in c++ when I try and map a texture to an object it changes the colour of everything else I have drawn eg everything goes a transparent red or green..
glEnable (GL_TEXTURE_2D);
Bitmap image;
image.loadBMP ("Texture.bmp");
glGenTextures(1, &m_TextureID);
glBindTexture ( GL_TEXTURE_2D, m_TextureID);
glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_MODULATE);
glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
gluBuild2DMipmaps ( GL_TEXTURE_2D, 3, image.width, image.height, GL_RGB, GL_UNSIGNED_BYTE, image.data);
glEnd();
this is my texture code and here is how i am mapping the texture
glBegin(GL_QUADS);
glEnable (GL_TEXTURE_2D);
//glColor3d(1, 0, 0);
glTexCoord2f (0.0f,0.0f);
glVertex3f(0, 0, 0); // bottom left
glTexCoord2f (1.0f,0.0f);
glVertex3f(10, 0, 0); // bottom right
glTexCoord2f (1.0f,1.0f);
glVertex3f(10, 0.6, 0);// top right
glTexCoord2f (0.0f,1.0f);
glVertex3f(0, 0.6, 0); // top left
glEnd();
etc...
all my non textured objects are drawn like this
glBegin(GL_QUADS);//BACK
glColor3d(1,0,0);
glVertex3f(10, 0, 0);
glVertex3f(10, 0, -5.6);
glVertex3f(10, 0.6, -5.6);
glVertex3f(10, 0.6, 0);
glEnd();
etc... am i missing something really obvious ? thanks
You need to disable texture mapping for your other objects if you don't want them to be textured.
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
...
You switched these two :
glBegin(GL_QUADS);
glEnable (GL_TEXTURE_2D);
glEnable should not be called between glBegin() and glEnd()
Other then that, use glGetError and see which exactly call fails.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.