PDA

View Full Version : OpenGL for 2d purposes...



WILL
28-10-2003, 10:44 PM
How easy/hard would it be to use OpenGL for 2D graphics like you would use DirectX3D for 2D?

I'm considering making my feature 360<sup>o</sup> Space Shooter type game cross-platform compatable, with the option to use either OpenGL/AL or DirectX, but not sure if existing libraries will do that for me and how smooth a time durring development will I have.


Any ideas, hints or suggestions?

Paulius
29-10-2003, 07:09 AM
Very easy, once you get used to the style of OpenGl that is, and it?¢_Ts easy enough to not use any libraries.

Alimonster
29-10-2003, 09:06 AM
It's pretty straightforward - you just need to set a 2d ortho view for the projection matrix (glMatrixMode(GL_PROJECTION); glOrtho(...)).

If I remember then I'll email you some of my code when I get home (after 5, UK time).

WILL
29-10-2003, 10:08 AM
That would be great. I've been eyeing OpenGL for some time, but only slightly. Wantering into the unknown isn't easy sometimes. However considering that so far the games that I have seen on the commercial side of the coin(Unreal Tournament/2003 , Quake 2&3, etc) have all ran really fast and smooth, I see not a reason to stay away if it isn't too hard. Cross platform capability doesn't suck either. ;)

Can I mix and match 3D effects with 2D? Or is that pretty much as taboo as Direct3D with 2D?

Paulius
29-10-2003, 10:20 AM
As there?¢_Ts no special 2D mode or something that would disable 3D, you can really do anything, just remember to turn depth test and depth mask on/off where needed.

WILL
29-10-2003, 11:21 AM
Hmm... someones really gotta lay out all of the settings of a basic OpenGL enviroment for me at some point. Perhaps a OpenGL for Beginners 101. :)

Alimonster
29-10-2003, 11:37 AM
Hmm... someones really gotta lay out all of the settings of a basic OpenGL enviroment for me at some point. Perhaps a OpenGL for Beginners 101. :)
I'm on it (and have been for a while, sigh). I've been meaning to do this recently but I've been smote with a cold over the past few days. :roll: I'll get back to writing stuff tomorrow with luck (today = maybe tidying up some code before letting you get your grubby mitts on it, tomorrow = coding, Friday = drinking, Saturday and Sunday afternoon = going back home to parents' house).

It will get done "real soon now".

WILL
29-10-2003, 07:40 PM
Groovyness... :)

Tanks Ali. ;)

{MSX}
24-01-2004, 01:24 PM
If I remember then I'll email you some of my code when I get home (after 5, UK time).

I'm interested in 2d opengl too, could you please post your example here ?

Thanks a lot!

Alimonster
27-01-2004, 12:54 AM
No problem. I'll post a link to the code tomorrow (edit: hmm, today, actually - I mean Tuesday) night sometime around 6-ish GMT, hopefully. I've still got a little bit of tidying up to do (both of the code and of my flat in real life, doh), but it's just about there.

Alimonster
27-01-2004, 07:47 PM
Right, here's the example: http://www.alistairkeys.co.uk/download/opengl_2d.zip (238K). You need Tom Nuyden's gl units for it (http://www.delphi3d.net/dot/). Also, the .dcus should be dumped into the temp subdirectory to keep things cleaner.

You'll need Delphi 6 or better to compile as-is because I did stuff like the following:

TTextureDimension = (td1D = GL_TEXTURE_1D,
td2D = GL_TEXTURE_2D,
td3D = GL_TEXTURE_3D_EXT);
(Notice the "= whatever" in that type.)

You can of course use earlier Delphi versions by getting rid of the declared types and just using Cardinals/Integers and the usual constants, if that's your thing -- I just wanted a more "Delphi" feel.

There are quite a few units in the example, which is just because I ripped it out of my general framework and made it a bit more tidy (there are still a few things that need sorted, esp. the texture class, but they're not that bad). You're interested in screen.pas, which shows the use of 2d. The idea is straightforward: you push the projection matrix onto the stack so that the 2d projection doesn't fark it up. Then, you use an ortho view set to whatever coordinates you need. After that, it's pretty straightforward. I've just added a few nice touches (like the
T2dTo3dSwitch and T3dTo2dSwitch classes).

The example is totally straightforward: it just draws a texture somewhere on the screen at the given coordinates, as if you were doing a 2d draw (this happens in TPlayingGameState.Update, probably). It's pretty easy to get the idea of what it's doing, I hope.

Anyway, feel free to comment on it if you feel a bit lost or if you notice something noteworthy.