[英]OpenGL mipmap issues
我有mipmapping正常工作。 但由於某些原因,在我應用紋理之后,我的應用程序中的所有其他對象都采用了似乎是紋理的平均顏色。 甚至是HUD。 有什么我需要考慮的嗎? 這是代碼:
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();
}
在繪制我的不同元素以防止這種情況發生之間我應該做些什么?
在完成渲染應該紋理化的部分之后,我猜你會在解開紋理或解除紋理的問題。 當你嘗試渲染無紋理的對象時,它們仍然會得到紋理,但是由於缺少紋理坐標,它們都使用相同的texcoord,所以它只從紋理中獲得一種顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.