2D w/ OpenGL - Beginner Questions

Started by
3 comments, last by Radagar 20 years, 2 months ago
Ok, I''ve went through the first few NeHe Tutorials, and I know how to draw Triangles and Quads on the screen and color them. Now, to solidify my knowledge to this point, I want to make a 2D Breakout Clone w/ OpenGL. I have a few questions right off the bat, and I''m hoping a few of you can help me out. 1) Is there anything special I should set in OpenGL if I''m using it to draw 2D and not 3D? Anything to give me the best perspective or view? 2) For Collision detection, is there a way to convert to and from OpenGL Coords and Screen Coords? 3) Any other hints on how to do 2D in OpenGL? Anything I need to know? Any words of Wisdom? thanks if you can help me out.
WyrmSlayer RPG - In Early Development
Advertisement
quote:Original post by Radagar
1) Is there anything special I should set in OpenGL if I''m using it to draw 2D and not 3D? Anything to give me the best perspective or view?

glOrtho gives you an orthographic projection which is best for 2d graphics (ie, no perspective!)

quote:2) For Collision detection, is there a way to convert to and from OpenGL Coords and Screen Coords?

It depends how you setup your view (via glOrtho or not). A really simple way to do things is to set up the screen with one gl unit to one pixel. Or you can use gluUnproject to get world coords from screen coords. Or you can do the math yourself manually.

But you don''t want to convert for collision detection. Do all your game logic / collision etc. in your own world coords, then only convert when drawing to screen. Separate your game logic and information from your actual graphical output.
OrangyTang, thanks for the reply.

I''ll look into using GlOrtho, and doing the 1 unit per pixel thing sounds like a great way to do it to me.
WyrmSlayer RPG - In Early Development
Hi, start with lesson2.pdf and go through all these lessons. One of the lessons has collision. It will walk you through making a 2d game in opengl and is a pretty decent tutorial for beginners. it has some other stuff in there as well. I hope this helps what you are looking for or maybe you can use the extra info anyway.
2d Open GL


[edited by - dischord333 on February 20, 2004 2:51:57 PM]
Thanks dischord333, I''ll look through that.
WyrmSlayer RPG - In Early Development

This topic is closed to new replies.

Advertisement