Jump to content
  • Advertisement
Sign in to follow this  
speciesUnknown

OpenGL SDL Opengl Z buffer Fighting [FIXED]

This topic is 4163 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

Hi all, Im using SDL and OpenGL. I have a serious problem with Z buffer fighting. Ive define my near plane as 8, and my far plane as 512, but i still get a lot of fighting between polygons. You can see the blocky edges where the green poly passes through the yellow poly. I also have this problem with more complex geometry, ill post some more screens if that helps. The two polygons in the image are intersecting each other, im using them to test my collision detection system. The camera is about 10 opengl units away from the two polygons. Here is how im initializing my SDL:
int graphics_control::initialize(int X, int Y, int B, int F)
{
	int parameters = SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_OPENGL;

	if(F)
		parameters += SDL_FULLSCREEN;
	
	main_screen = SDL_SetVideoMode(X, Y, B, parameters);
	x=X; y=Y; b=B; f=F;
	glEnable(GL_DEPTH_TEST);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(10,(X/Y),8,512);
	glMatrixMode(GL_MODELVIEW);

	camera = new camera_control();
	camera->initialize();
	fog = new fog_control();fog->off();
	text_tool = new text_control();
	lighting = new light_control(); lighting->initialize();
	skybox = new background_control();
	
	return 1;
};



can anybody see what im doing wrong? edit:corrected some numbers [Edited by - speciesUnknown on July 27, 2007 7:40:56 PM]

Share this post


Link to post
Share on other sites
Advertisement
u shouldnt see that

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); <- most (all?) cards dont have 32 bit depthbuffers

gluPerspective(10,float(X)/float(Y),8,512);

Share this post


Link to post
Share on other sites
FIXED!

I tried 24 and it was just as bad. Then i tried 8 and it wasnt any worse.
Thats because you have to set the OpenGL attributes BEFORE initializing your SDL_Surface. I changed my code to this:


int graphics_control::initialize(int X, int Y, int B, int F)
{
int parameters = SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_OPENGL;

if(F)
parameters += SDL_FULLSCREEN;

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

main_screen = SDL_SetVideoMode(X, Y, B, parameters);
x=X; y=Y; b=B; f=F;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(10,(X/Y),8,512);
glMatrixMode(GL_MODELVIEW);

camera = new camera_control();
camera->initialize();
fog = new fog_control();fog->off();
text_tool = new text_control();
lighting = new light_control(); lighting->initialize();
skybox = new background_control();

return 1;
};


and now it works. No Jaggies as far as I can see. Thanks for your help.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!