Recommended Posts

Hi all,
as I've already wrote in another thread I'm developing a 2d game. What I would ask you, is if it's better to use glOrtho or glFrustum for my application. In other words, it's better orthographic view or perspective view? I give you more information about this project.
There is a background map (using opengl lists) that can be zoomed in and out via mouse scrolling, and some information over the map itself. These information are
1) text
2) Icons (some lines)
The size of map depend on zoom, so the map must be drawn bigger or smallest based on zoom level.
The text and the icons must be always with the same size (they DON'T change when the zoom change).
Last but not least, i need to do mouse picking.
My considerations are:
- If i use glOrtho, i simply need to change its parameters to change the map's size, but every time the user change the zoom level, i need to change the font's size and redraw the text. The picking would be really simple: mouse coordinates multiplied by the zoom factor.
- If i use glFrustum, when the user change the zoom, i just need to redraw the map in another z coordinate to change it's size, while keeping text and icons always at the same z position. The negative point is that it's more difficult mouse picking, because the view now is a frustum of a pyramid rather than a cube (perspective rather than orthographic), so more math is involved.
What do you suggest me, and why?
Thank you,
Erik

0

Share this post

Link to post

Share on other sites

I think glOrtho is more intuitive for a 2D game. You don’t need to change the parameters of glOrtho to zoom in and out. I think it’is better to enlarge the map. And for picking you simply use the mouse coordinates.

0

Share this post

Link to post

Share on other sites

Ortho is easier, perspective is more flexible. I prefer perspective for almost everything.

On a side note, after some help I posted a relatively easy solution to picking in perspective mode at the last post in http://www.gamedev.net/community/forums/topic.asp?topic_id=454859 (note that I have inverted my y coordinate, which might not be the case for you).

0

Share this post

Link to post

Share on other sites

Original post by TRWhiteDragonThere is a background map (using opengl lists) that can be zoomed in and out via mouse scrolling, and some information over the map itself. These information are1) text 2) Icons (some lines)

The size of map depend on zoom, so the map must be drawn bigger or smallest based on zoom level.The text and the icons must be always with the same size (they DON'T change when the zoom change).

Last but not least, i need to do mouse picking.

I would draw the map in perspective and then switch to orthographic to draw the text. If you draw the text in perspective then it will appear warped depending on where on the screen it is.

Picking in opengl is relatively simple so you shouldn't have to worry about it being difficult. It's also something that you should learn.

Share this post

Link to post

Share on other sites

Original post by apatriarcaYou don’t need to change the parameters of glOrtho to zoom in and out. I think it’is better to enlarge the map.

Do you think it's better to change the glOrtho parameters or to re create the map opengl list everytime the zoom is changed?

Quote:

Original post by HnefiI posted a relatively easy solution to picking in perspective mode at the last post in http://www.gamedev.net/community/forums/topic.asp?topic_id=454859

Thank you, I'll take a look this evening

Quote:

Original post by CrimsonSunI would draw the map in perspective and then switch to orthographic to draw the text.

This is mean that i can use both of them? In this case, could i make a mix of two orthographic view: the first with variable parameter (to change the map) and the second with fixed parameter to show the text?

Quote:

Original post by CrimsonSunPicking in opengl is relatively simple so you shouldn't have to worry about it being difficult. It's also something that you should learn.

Really I'm too lazy to study the opengl picking, when I'm already able to use mouse coordinate in orthographic view... I hope this is not a problem for you...

To end this reply, I'm continuing to ask you about the orthographic view because it's seems to me more simple to use it to make a 2D game.

Thank you again,Erik

0

Share this post

Link to post

Share on other sites

I suggest using glOrtho for projection, and zooming by scaling the model/view matrix, because it's simpler to pick coordinates for 2D graphics when the zooming is orthographic and linear. I'll try to explain why.

When you render vertices in OpenGL, they are transformed by the current model/view transformation, and the current projection transformation. When you call glOrtho or glFrustum, the current transformation is modified, and typically you choose to modify the projection transformation when calling glOrtho/glFrustum, since they specify how the world should be projected on the display area. To set the current transformation to modify, you can first call glMatrixMode, with either GL_PROJECTION or GL_MODELVIEW as parameter.

Basically you can keep the same glOrtho-setting while rendering both the background map and the text/icons, but to scroll and zoom you can modify the model/view transformation to scale the background map larger/smaller.

So you only need to modify the projection transformation once to set the display area (call glMatrixMode(GL_PROJECTION) then glOrtho). Then to render the zoomed map, call glMatrixMode(GL_MODELVIEW), then glLoadIdentity to set reset the model/view transformation to none, then glScalef(scaleX, scaleY, scaleZ) to zoom by scaling the transformation, then the calls needed to display the map (glVertex3f etc.). The scale-parameters are 1 by default, if you set for example scaleX to 2 the map will be magnified to twice its original size along the x-axis. This is were you would simply use your zoom factor. To render the text/icons, call glLoadIdentity once again to reset the model/view transformation (since the text shouldn't be zoomed/scaled), then do the necessary calls to render the text in the orthographic coordinate system. The glOrtho setting still applies.

Quote:

Original post by TRWhiteDragonDo you think it's better to change the glOrtho parameters or to re create the map opengl list everytime the zoom is changed?

The current model/view transformation can be used to zoom/scale the whole map display list.

Quote:

Original post by TRWhiteDragonThis is mean that i can use both of them? In this case, could i make a mix of two orthographic view: the first with variable parameter (to change the map) and the second with fixed parameter to show the text?

Yes, you can, choose whether you want to modify the glOrtho setting, or if you want to set a separate scaling for the map and then the text/icons. Just remember to compute your zoom factor accordingly.