[英]openGL texture mapping
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.. 嘿,我正在尝试使用c ++中的openGL创建游戏,当我尝试将纹理映射到对象时,它将更改我绘制的所有其他对象的颜色,例如,所有对象变为透明的红色或绿色。
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() 在glBegin()和glEnd()之间不应调用glEnable
Other then that, use glGetError and see which exactly call fails. 除此之外,请使用glGetError并查看确切的调用失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.