PDA

View Full Version : 2D OpenGL



Lster
August 17th, 2007, 10:33 AM
Hi all

This is an OpenGL problem related to layering textures over each other. Anyhow, I have set up OpenGL like this:

...

Now when I draw, everything appears on top of what was previously drawn. However I want it so that I can choose what is behind or in front. I can see, perhaps a couple of ways of doing this.

...

Can you advise me on either of these methods? Are they possible? Anything else I could consider?

Thank you lots,
Lster

moshy
August 17th, 2007, 12:13 PM
I reckon, using OpenGL, you could render in 3D, with no transformation, so you're looking directly down the z-axis, and set the perspective to orthogonal-perspective, so things stay the same size even if they are further away. Then you would have to set arbitrary z-coordinates for each object, and of course enable depth testing.

Lster
August 17th, 2007, 12:41 PM
I reckon, using OpenGL, you could render in 3D, with no transformation, so you're looking directly down the z-axis, and set the perspective to orthogonal-perspective, so things stay the same size even if they are further away. Then you would have to set arbitrary z-coordinates for each object, and of course enable depth testing.

Great! This would rock! I have no idea how to do this, however. What should my ortho be? And how do I enable orthogonal-perspective?

After that, would I render things like this:


...

instead of:


...

Thank you lots,
Lster

Lster
August 17th, 2007, 03:42 PM
*Bump* :)

Mirrorball
August 17th, 2007, 06:13 PM
I'm new to OpenGL, but I have the red book 5th edition and it doesn't say anything about orthogonal perpective, but it has a whole section on ortographic projection. Are they the same thing? If it is, the relevant functions are glOrtho and gluOrtho2D.

Wybiral
August 17th, 2007, 06:36 PM
> And how do I enable orthogonal-perspective?

You have your near/far planes set up for a lack of depth (-1 to 1). I've never used ortho with depth, so I can't suggest a better range, I guess just experiment.


>I'm new to OpenGL, but I have the red book 5th edition and it doesn't say anything about orthogonal perpective, but it has a whole section on ortographic projection. Are they the same thing? If it is, the relevant functions are glOrtho and gluOrtho2D.

Perspective projection is when there is size distortion with object further away, orthogonal has no distance based distortion. I assume ortho perspective is just another way to say ortho projection (albeit confusing). glOrtho and gluOrtho2d are basically the same thing except glOther allows you to specify the near/far clipping planes and gluOrtho2d sets them to (-1, 1).

moshy
August 18th, 2007, 09:57 AM
yeah, sorry about the confusion with perspective/projection

Lster
August 18th, 2007, 10:25 AM
You have your near/far planes set up for a lack of depth (-1 to 1). I've never used ortho with depth, so I can't suggest a better range, I guess just experiment.

EDIT: I did eventually get all this working! :)

Wybiral
August 18th, 2007, 07:06 PM
Have you tried "glEnable(GL_DEPTH_TEST);" by chance?

Also, you will need to clear your depth buffer when you clear the color buffer if you plan to use it.

mikesofty
April 18th, 2008, 12:57 PM
Hi everyone..
I want to configure opengl or glut in ubuntu..
Is opengl and glut are same.?
I got all the header files ..
But how to link the library functions ..?
Which IDE can i use for opengl..

Larrxi
April 18th, 2008, 01:38 PM
GLUT handles the window and stuff like that.

You link with -lGL.

Anjuta, Eclipse and Kdevelop are possible IDE:s, i prefer to use the console :)