Jump to content
  • Advertisement
Sign in to follow this  
Gothmog

Dissappearing textures

This topic is 4992 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
It could very well be a z precision issue. How are you constructing the projection matrix (more precisely, with which values)?

-Nik

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Comment the scaling and rotating stuff and check if it still happens. I think the rotation is based on the camera's view right?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!