Dissappearing textures

Started by
17 comments, last by MARS_999 19 years, 6 months ago
I have a problem. Some of the textures in my app dissappear while rotating the camera. Here are some example images: Before...


...and after


Has anybody got an idea what causes this problem? [Edited by - Gothmog on November 7, 2004 12:39:06 PM]
Advertisement
maybe post some rendering source?
It could very well be a z precision issue. How are you constructing the projection matrix (more precisely, with which values)?

-Nik

Niko Suni

Quote:
maybe post some rendering source?


	glMatrixMode(GL_TEXTURE);	glActiveTextureARB(GL_TEXTURE1_ARB);	glEnable(GL_TEXTURE_2D);	glBindTexture(GL_TEXTURE_2D,wdetail->texid);	glLoadIdentity();	glRotatef(t*0.01,0.0f,0.0f,1.0f);	glTranslatef(-deltaX,-deltaY,0.0f);	glScalef(100.0f,100.0f,1.0f);	glActiveTextureARB(GL_TEXTURE0_ARB);	glEnable(GL_TEXTURE_2D);	glBindTexture(GL_TEXTURE_2D,waterTex->texid);	glLoadIdentity();	glTranslatef(deltaX,deltaY,0.0f);	glScalef(5.0f,5.0f,5.0f);	glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);	glColor4f(1.0f,1.0f,1.0f,0.9f);	glNormal3f(0.0f,1.0f,0.0f);	glBegin(GL_QUADS);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0f,0.0f);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.0f,0.0f);	glVertex3f(-1000.0f,wlev+wdelta,-1000.0f);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1.0f,0.0f);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1.0f,0.0f);	glVertex3f(1000+world->tilesX*world->tileSize,wlev+wdelta,-1000.0f);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1.0f,1.0f);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1.0f,1.0f);	glVertex3f(1000+world->tilesX*world->tileSize,wlev+wdelta,world->tilesY*world->tileSize+1000);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0f,1.0f);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.0f,1.0f);	glVertex3f(-1000.0f,wlev+wdelta,world->tilesY*world->tileSize+1000);	glEnd();	glActiveTextureARB(GL_TEXTURE0_ARB);	glLoadIdentity();	glActiveTextureARB(GL_TEXTURE1_ARB);	glLoadIdentity();	glMatrixMode(GL_MODELVIEW);


Quote:
How are you constructing the projection matrix (more precisely, with which values)?


The whole world has about 400x400 units on the XZ plane. The water (a single quad, which causes this problem has 2400x2400 units on the XZ plane), the camera is about 2.0 units above the ground.
im not sure what u mean bt disappearing textures ( the pictures look ok) but perhaps it is a depth precision problem, make the near clip plane 100x bigger
Comment the scaling and rotating stuff and check if it still happens. I think the rotation is based on the camera's view right?
Quote:im not sure what u mean bt disappearing textures ( the pictures look ok)


Look at the water in the 2nd picture, i don't think it looks ok [smile]

Quote:make the near clip plane 100x bigger


Nah, it doesn't work.

Quote:Comment the scaling and rotating stuff and check if it still happens


It gives no effect.

Quote:I think the rotation is based on the camera's view right?


No, the transformations affect the texture matrix, to create animation of the water. It has nothing to do with the camera.
Quote:Original post by Gothmog
No, the transformations affect the texture matrix, to create animation of the water. It has nothing to do with the camera.


Maybe the texture matrix causes the problems. Does the water texture still disappear if you set the texture matrix to identity? Can you post more details on the texture matrix transformation?
Quote:Does the water texture still disappear if you set the texture matrix to identity?


Yes.

Quote:Can you post more details on the texture matrix transformation?


Here is the full code of the water rendering function:

void DrawWater(){	static texture * waterTex=NULL,*wdetail=NULL;	static const float wlev=50.0f;	static float wdelta=0.0f;	static float t=0.1;	static float deltaX=0.0f,deltaY=0.0f;	if(!waterTex)	{		waterTex=Engine->AddTexture("water.bmp",GE_AT_BUILD|GE_AT_GLUBUILD2DMIPMAPS|GE_AT_STDTEXFILTERS|GE_AT_STDLINEARFILTERS);	}	if(!wdetail)	{		wdetail=Engine->AddTexture("water017.bmp",GE_AT_BUILD|GE_AT_GLUBUILD2DMIPMAPS|GE_AT_STDTEXFILTERS|GE_AT_STDLINEARFILTERS);	}	glPushAttrib(0xFFFFFFFF);	glMatrixMode(GL_TEXTURE);	glActiveTextureARB(GL_TEXTURE1_ARB);	glEnable(GL_TEXTURE_2D);	glBindTexture(GL_TEXTURE_2D,wdetail->texid);	glLoadIdentity();	glRotatef(t*0.01,0.0f,0.0f,1.0f);	glTranslatef(-deltaX,-deltaY,0.0f);	glActiveTextureARB(GL_TEXTURE0_ARB);	glEnable(GL_TEXTURE_2D);	glBindTexture(GL_TEXTURE_2D,waterTex->texid);	glLoadIdentity();	glTranslatef(deltaX,deltaY,0.0f);	glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);	glColor4f(1.0f,1.0f,1.0f,0.9f);	glNormal3f(0.0f,1.0f,0.0f);	glBegin(GL_QUADS);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0f,0.0f);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.0f,0.0f);	glVertex3f(-1000.0f,wlev+wdelta,-1000.0f);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB,5.0f,0.0f);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB,100.0f,0.0f);	glVertex3f(1000+world->tilesX*world->tileSize,wlev+wdelta,-1000.0f);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB,5.0f,5.0f);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB,100.0f,100.0f);	glVertex3f(1000+world->tilesX*world->tileSize,wlev+wdelta,world->tilesY*world->tileSize+1000);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0f,5.0f);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.0f,100.0f);	glVertex3f(-1000.0f,wlev+wdelta,world->tilesY*world->tileSize+1000);	glEnd();	glActiveTextureARB(GL_TEXTURE0_ARB);	glLoadIdentity();	glActiveTextureARB(GL_TEXTURE1_ARB);	glLoadIdentity();	glMatrixMode(GL_MODELVIEW);	deltaX+=0.0001f;	deltaY+=0.0001f;	if(t<360.0f)		t+=0.05f;	else t=0.05f;	wdelta=sinf(t)*0.5f;	glPopAttrib();}


The textures are translated, and then the second texture is also rotated on the ST plane. In the prev. version of this code, the textures were scaled, but I removed it, and changed the tex coordinates manually.
Some things I noticed:

glPushAttrib(0xFFFFFFFF);
I've never seen this. Are you sure this works and is fast?
The GPU has to push every attrib (also the non-used ones), so it might be slow.

waterTex=Engine->AddTexture("water.bmp",GE_AT_BUILD|GE_AT_GLUBUILD2DMIPMAPS|GE_AT_STDTEXFILTERS|GE_AT_STDLINEARFILTERS);
I just wanted to ask whether you load the textures every frame, but then I noticed that waterTex and wdetail are static...

Does the problem only occur after a certain time, say 1 or 2 minutes? If so, set deltaX and deltaY back to 0 if they exceed 1.

Do the textures reappear if you rotate the camera back?

I've actually no idea what could cause the problem, the code looks OK so far. But maybe you can find the reason for the problem by successively simplifying the code:
1) Don't use blending
2) Don't use multitexture (only the water texture)
3) Disable lighting
and so on. Maybe this helps.

This topic is closed to new replies.

Advertisement