Terrain Flickering
Hi,
If you could point me in the right direction, I would appreciate it.
As I move around the terrain, the texture flickers (even with the lights off)
The only thing I can think of is that its related somehow to the depth testing or the mipmapping (but I also try without mipmapping and it does the same thing)And it flickers no mateer what distance I am from the terrain, but only when it moves.
Here are the relevant lines:
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
at each frame I:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
and I load the texture both ways:
if (mip==0){
glTexImage2D(GL_TEXTURE_2D, 0, 3, Image->sizeX, Image->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, Image->data);
}else{
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Image->sizeX, Image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, Image->data);
}
with
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,FilterTypeNear);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,FilterTypeFar);
where I have tried differents parameters eg GL_LINEAR, GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR
thanx
Pretty much as in the nehe tutorials
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovy,(GLfloat)width/(GLfloat)height,znear,zfar);
glMatrixMode(GL_MODELVIEW);
where
float fovy=45.0;
float znear=0.1f;
float zfar=5000.0f; ( large, I know....)
width=640
height=480
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovy,(GLfloat)width/(GLfloat)height,znear,zfar);
glMatrixMode(GL_MODELVIEW);
where
float fovy=45.0;
float znear=0.1f;
float zfar=5000.0f; ( large, I know....)
width=640
height=480
I changed the zfar to 1000 but it still does it.
I should add (I have just discovered this) that the flickering
is not as bad if I move in the -x direction, but is equally bad if I move in the +x,+z,-z directions.......
Haha, thanx for the hint: I set the znear to 1.0f and no more flickering- why it works, I don''t know.
here''s an explanation.
basically, you want the zFar/zNear ratio to be as low as reasonably possible. from the link above: "Empirically it has been observed that ratios greater than 1000 have this undesired result."
-steve.
basically, you want the zFar/zNear ratio to be as low as reasonably possible. from the link above: "Empirically it has been observed that ratios greater than 1000 have this undesired result."
-steve.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement