Converting over from Ortho to Frustum

I have always used Ortho projection for my OpenGL programs. But half-way through my current project I have realised that I should instead be using Perspective(Frustrum) projection.

My current reshape function is as follows:

void Reshape(void)
	glViewport(0, 0, WIN_WIDTH, WIN_HEIGHT);
	glOrtho(0, WIN_WIDTH, WIN_HEIGHT, 0, -1, 1);

I tried swapping the word Ortho to Frustum and a few other ways but none work.

What do I need to do to change it to Perspective projection. Is it just a matter of chopping and changing a few lines or do I have to change the way I draw object?


Replace glOrtho() w/ “gluPerspective(30.0, WIN_WIDTH / WIN_HEIGHT, 1.0, 2000.0);”

I just get a black screen :(. Do i have to draw objects differently. At the moment they are drawn like this for example

	glDisable( GL_TEXTURE_2D );
	glColor4f(0.7, 0.7, 0.5, 1);
    glVertex3d(x,y, 0);
	glVertex3d(prevx,prevy, 0);
	glColor4f(1, 1, 1, 1);

Why do you think you should be using a perspective projection, when you’re clearly doing 2D line drawing?

this is just part of the code that would be used for part of the UI overlay. I guess that was a bad example. Because I’m making a top down shooter, I need the camera to follow the player and the UI overlay to remain on the same position on the screen.
Would I not use perspective projection for this?

Would I not use perspective projection for this?


A perspective projection is for providing, well, perspective. What you want is a camera, which is a different thing.

For a top-down 2D game, all you want is to provide a simple translation offset (possibly a rotation if you want to rotate the view). Just stick that in the MODELVIEW matrix before putting any other transforms into it.

Thanks, Alfonse.

As you can probobly tell I’m quite new to OpenGL and programming so advice like this really helps