OpenGL mipmap 问题
我的 mipmap 工作正常。但由于某种原因,在应用纹理后,应用程序中的所有其他对象都呈现出纹理的平均颜色。甚至平视显示器。有什么我需要考虑的吗?这是代码:
GLuint LoadTexture( const char * filename, int width, int height )
{
GLuint texture;
unsigned char * data;
FILE * file;
file = fopen( filename, "rb" );
if ( file == NULL ) return 0;
data = (unsigned char *)malloc( width * height * 3 );
fread( data, width * height * 3, 1, file );
fclose( file );
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_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, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
free( data );
return texture;
}
在循环之前调用并在循环后释放。代码的下一部分发生在我的 while 循环内。它在场景中的所有其他对象之前被调用。
void makeGround() {
glBindTexture( GL_TEXTURE_2D, texture );
GLfloat mat_specular[] = { 0.5, 0.5, 0.5, 1.0 };
GLfloat mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat mat_shininess[] = { 100.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
//glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
glTranslatef(-(size/2), 0.0f, -(size/2));
glCallList(LIST1);
glPopMatrix();
}
在绘制不同的元素之间我应该做什么来防止这种情况发生?
I have mipmapping working properly. But for some reason, after I apply the texture, all other objects in my application take on what seems to be the average color of the texture. Even the HUD. Is there something i need to account for? Here is the code:
GLuint LoadTexture( const char * filename, int width, int height )
{
GLuint texture;
unsigned char * data;
FILE * file;
file = fopen( filename, "rb" );
if ( file == NULL ) return 0;
data = (unsigned char *)malloc( width * height * 3 );
fread( data, width * height * 3, 1, file );
fclose( file );
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_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, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
free( data );
return texture;
}
That gets called before the loop and freed afterwords. This next portion of code happens inside my while loop. It is called before all other objects in the scene.
void makeGround() {
glBindTexture( GL_TEXTURE_2D, texture );
GLfloat mat_specular[] = { 0.5, 0.5, 0.5, 1.0 };
GLfloat mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat mat_shininess[] = { 100.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
//glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
glTranslatef(-(size/2), 0.0f, -(size/2));
glCallList(LIST1);
glPopMatrix();
}
What should I be doing between drawing my different elements to keep this from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你在完成渲染应该纹理化的部分后忘记解除纹理绑定或禁用纹理化。当您尝试渲染无纹理的对象时,它们仍然会获取纹理,但由于缺乏纹理坐标,它们都使用相同的纹理坐标,因此它只会从纹理中获取一种颜色。
I would guess that you fogot to unbind the texture or disable texturing after you finished rendering the parts which should be textured. When you try to render untextured Objects they still get the texture, but due to the lack of texture coordinates they all use the same texcoord, so it will get just one color from the texture.