Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

RuneLancer

OpenGL: To ortho, or not to ortho...

This topic is 5237 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''ve decided to work on a 2D RPG. Think "oldschool" Final Fantasy type of game engine. To benefit from hardware acceleration, I''ve decided to use OpenGL. So far so good. Now, I''ve heard orthographic projection is "the" means of doing 2D in OpenGL. Excellent. That''s exactly what I want. However, having followed NeHe''s tutorials, I have next to no experience with this. The Z coordinate is no longer available in ortho, right? Can things still be overlapped as though they had different depths (ie, can I superpose a window with the rest of my game) or would stuff intersect as though they all had the same Z? And does anyone have experience with this? I''m curious how good using it would be. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Unless OpenGL in this respect is completely different than any other 3D experience I have, then using ortho mode in no way takes away the Z value. Ortho mode should still be fully 3D. The only difference is that things don't appear smaller the farther off they get. This is the only real difference. And because of this, whenever you view surfaces that are completely perpendicular to the camera's line of sight, they appear to be completely 2D. And typically, the camera's line of site is direct along the Z axis. Thus, every surface that has identical Z coordinates for all its vertices appears 2D. But the fact that two surfaces have two different sets of Z coordinates still affects depth and everything.

In fact, there are a good number of games probably that do use ortho mode, but are still 3D. An example from a while back would by Final Fantasy Tactics. It was 3D, but you'll notice that everything is always the same size, regardless of location. Many isometric games are basically simulating 3D ortho mode (even though technically their graphics engine is indeed 2D).

[edited by - Agony on May 20, 2004 5:08:00 PM]

Share this post


Link to post
Share on other sites
(I''ve never really worked with OpenGL, but it''s probably like this..)

The ''Z'' is still available. Ortho means ''perspective''-less. You can still make objects smaller/bigger, by moving the ''Z''-value of an object.

Just try it!

--
You''re Welcome,
Rick Wong
- Google | Google for GameDev.net

+------------+
| Forum FAQ |
| Read it! |
+------------+

Share this post


Link to post
Share on other sites
i have a decent amount of code done for a top down tile RPG in SDL... after seeing what a crappy framerate i was getting (due to software rendering), i decided to learn OpenGL.. anyway im in the process of learning openGL (using 2d Ortho mode) to change my drawing code from SDL... the point is, i have some questions:

if im using ortho mode, i can no longer resize the screen, and things wont scale as i resize? so basically no resizing allowed?

if im using ortho mode, can i give the player a "zoom" key, where he can press, and the screen will zoom in, and zoom out?
(is this what runes asking?)

does drawing things in openGL ortho mode work the same way with SDL, in the fact that (if my code looked like this)

Draw_background()
Draw_player()

the player will appear to be on top of the background ? (again is this similar to runes question?)

what else limitations should i know about, or any general hints for someone with no knowledge on 3d graphics/ openGL moving from SDL ? thanks for any help!!!

Share this post


Link to post
Share on other sites
Using glOrtho, you specify the near and far planes(z-axis). Anything between these planes will be drawn. Those that are closer(a more positive z value) will be visible so you can do layers as you are asking.

There is another command gluOrtho2D that doesn't take any near/far planes. It uses near=0, far=1 but essentially it is expected that you will only use glVertex2? with it.

For what you want to do, glOrtho is the best choice.

karg

Edit: fixed near and far values for gluOrtho2D

[edited by - Karg on May 20, 2004 5:24:03 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Karg
There is another command gluOrtho2D that doesn''t take any near/far planes. I think it just uses 1/-1 but essentially it is expected that you will only use glVertex2? with it.

For what you want to do, glOrtho is the best choice.


Ah! That''s what I got confused with!! I remember reading that you''d use glVertex2 to set vertices and that''s where my concerns with depth came in. Excellent, that makes everything work out just fine then.

Share this post


Link to post
Share on other sites
quote:
Original post by graveyard filla
if im using ortho mode, i can no longer resize the screen, and things wont scale as i resize? so basically no resizing allowed?


You can resize just like you were using glFrustum

quote:
if im using ortho mode, can i give the player a "zoom" key, where he can press, and the screen will zoom in, and zoom out?
(is this what runes asking?)


Sure, just have a variable in your glOrtho call:
glOrtho( left*zoom, right*zoom, top*zoom, bottom*zoom, near, far );
where zoom gets smaller as the user zooms in(not sure on the order of the arguments, but you get the idea).

quote:
does drawing things in openGL ortho mode work the same way with SDL, in the fact that (if my code looked like this)

Draw_background()
Draw_player()

the player will appear to be on top of the background ?


Depends on how you set it up, but you can get it to work that way. Make sure everything is drawn with the same z value(easiest to use glVertex2?) and set the opengl depth test to less than or equal:
glDepthFunc( GL_LEQUAL );

Now, as to if you want to do it that way, it can also be done this way. Have the z be which "layer" the object is on. That way, objects can be drawn in any order and it will still come out correctly. Just another way to get the same result.

karg

Share this post


Link to post
Share on other sites
but how do you effect which z axis to draw on? i thought you were suposed to use glVertex2f() with ortho mode? keep in mind im calling glOrtho2D( make 0,0 top left corner);

so basically your saying, i could draw everything on the same Z plane, and the layers would be whichever order i drew things (my example above with b/g and player, and using vertex2f), OR, the differnt layers would be on different Z planes and i would draw with glVertex3f, but then, wouldnt what gets draw last be on top? im confused....

also, in glOrtho mode, isnt everything in terms of pixels, IE no longer "units", but exact screen pixels?(ie player.yPos += 4 would move the player down 4 pixels) this seems to be whats happening, but im getting confused now.. how could resizing things work if everything is in terms of pixels???

thanks for any further help

Share this post


Link to post
Share on other sites
As I understand it, let''s suppose you have a window and a map.

The map''s Z is 0.

The window''s Z is -1.

This means that, with depth culling on, you''d draw the window in front of the map whenever you render your scene. Not in the order in which you draw them (that is, unless depth culling is off...?)

Share this post


Link to post
Share on other sites
quote:
Original post by Pipo DeClown
You can still make objects smaller/bigger, by moving the ''Z''-value of an object.


No. Foreshortening is a perspective projection feature. With an orthographic projection, objects appear the same for any "Z-value".

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!