[programming] Info on 2D games using OpenGL

For topics that do not fit in another sub-forum.

Moderator: Oberlus

Post Reply
Message
Author
leiavoia
Space Kraken
Posts: 167
Joined: Sun Jul 20, 2003 6:22 pm

[programming] Info on 2D games using OpenGL

#1 Post by leiavoia »

To the programmers:

I'm diverting my AXIS project for a while to get into some other things. I'm wanting to create a 2D side-scrolling game but my inital tests show a serious lack of framerate for any realistically playable game @ 1024x768 using SDL. Some have suggested i use OpenGL instead.

Are there any resources on the net for making 2D games with OpenGL? I can't find much on the topic. I ask because i know that's basically what FO is already doing.

Thanks for any tips.

Tyreth
FreeOrion Lead Emeritus
Posts: 885
Joined: Thu Jun 26, 2003 6:23 am
Location: Australia

#2 Post by Tyreth »

Basically you want to be using glOrtho instead of glPerspective iirc. You can find tutorials here on OpenGL:
http://nehe.gamedev.net/

And in particular this one on 2D:
http://nehe.gamedev.net/data/lessons/le ... ?lesson=21

leiavoia
Space Kraken
Posts: 167
Joined: Sun Jul 20, 2003 6:22 pm

#3 Post by leiavoia »

Much obliged. I guess i'll have to start learning OpenGL today. Wish me luck!

Marijn
Space Squid
Posts: 65
Joined: Thu Feb 19, 2004 10:26 am
Location: Nijmegen (NL)

#4 Post by Marijn »

It is not that hard!

OpenGL programming guide: http://fly.cc.fer.hr/~unreal/theredbook/
NeHe's OpenGL tutorials: http://nehe.gamedev.net/

Daveybaby
Small Juggernaut
Posts: 724
Joined: Mon Sep 01, 2003 11:07 am
Location: Hastings, UK

#5 Post by Daveybaby »

lev, you said somewhere on your axis page that you were finding SDL too slow (at least w.r.t. alpha channel PNGs). For a turn based strategy game i find this worrying, since i'm about to start porting my project over to SDL.

Just how bad is it? I'm planning on using alpha channel PNGs quite a lot, and while i'm not expecting to produce anything quite as eye catching as FO, i'd still like it to look pretty polished on the starmap screen while keeping a high framerate when scrolling, zooming and rotating (i may include the option for 3-d maps at some point).

Do you think SDL is going to be up to the job, or should i be looking at OpenGL myself?
The COW Project : You have a spy in your midst.

leiavoia
Space Kraken
Posts: 167
Joined: Sun Jul 20, 2003 6:22 pm

#6 Post by leiavoia »

for a TBS game, SDL is plenty good. For an action game with high resolutions, it's not. However, the game i want to make (one of, i should say :-) would include lots of eye-candy like multiple parallax background (like the FO map), particle effects (what i'm working on now), lighting, etc. I can fake a lot of that with SDL, but OpenGL has very good framerates for simple textured-quads right out of the gate.

I'll send you my framerate SDL particle demo (it's cool besides) and you can test for yourself. It's simple to compile. When blitting a 1024x768 BMP converted to the screen format, plus simulating ~1000 particles, i get fps of about 30-45+. (not bad)

For a PNG image with no conversion, i only get 20-25.

That's with no game logic (collision checking, sprite blitting, AI, GUI, etc).

For AXIS, i converted all my map tiles to BMP format and noticed an emmediate jump in performance since i draw all tiles overy time the map moves. Now i learned that you need to convert the surface to screen format for optimum performance. That will get me going even faster.

For your game, SDL is the perfect solution. GL is too much overkill for that kind of project (unless you want some extreme eye-candy) for sure.

Also, ParaGUI has resumed active development which is pretty exciting. They are focusing on speeding up the library. Current tests put the new version 25-50% faster than what i'm using now. Grab PG and SDL and you'll have graphics in a matter of minutes, really.

NOTE: it is possible to integrate SDL and OpenGL (FO does it) and it's slicker'n snot. SDL handles all the windowing and OpenGL handles the actual graphics. It's MUCH simpler than trying to manage windows with the native MSWindows / X Server commands. So learning basic SDL is to your benefit anyway.

Daveybaby
Small Juggernaut
Posts: 724
Joined: Mon Sep 01, 2003 11:07 am
Location: Hastings, UK

#7 Post by Daveybaby »

Smart... i guess you are drawing a lot more stuff than i would be - youre having to blit every tile whereas i would be effectively drawing over a black background. I will start with SDL and see how it goes. Thanks.
The COW Project : You have a spy in your midst.

leiavoia
Space Kraken
Posts: 167
Joined: Sun Jul 20, 2003 6:22 pm

#8 Post by leiavoia »

That's actually a good point. I'm drawing 22x24= 488? tiles every scroll. Then, add on top of that vision circles, pods, and map items (which are all still PNGs by the way).

For your game, the map window is just:

1) draw stary black background
2) draw each star, and how many of them can there be at once? Even if you use the full zoom, that's still only a couple hundred.

I would say feel free to use PNG graphics for that. It's no problem. Did you get the demo i sent?

Daveybaby
Small Juggernaut
Posts: 724
Joined: Mon Sep 01, 2003 11:07 am
Location: Hastings, UK

#9 Post by Daveybaby »

Ah, yes - just checked my home account and there is a rather large file waiting for me - thanks.

Will hopefully have a look at it tonight - if i manage to get out of work in time.
The COW Project : You have a spy in your midst.

luckless666
Pupating Mass
Posts: 90
Joined: Thu Nov 06, 2003 3:16 am
Location: West Sussex, United Kingdom

#10 Post by luckless666 »

leiavoia wrote:Also, ParaGUI has resumed active development which is pretty exciting.
On the subject of ParaGUI, does anyone know why their website takes a heck of a long time to load in the browser? I've only managed to do it once recently, the rest of the time i get bored...
Chris Walker
| c.walker (at) mgt.hull.ac.uk |

WorldForge.org

leiavoia
Space Kraken
Posts: 167
Joined: Sun Jul 20, 2003 6:22 pm

#11 Post by leiavoia »

loads OK for me. Makes sure it is .org not .com

http://www.paragui.org/

Daveybaby
Small Juggernaut
Posts: 724
Joined: Mon Sep 01, 2003 11:07 am
Location: Hastings, UK

#12 Post by Daveybaby »

Nah, there is something very wrong with that domain, always has been.
I can load it at home just fine, but if i try to access it from work i just sits there. Something is wrong with its something or other thingy. Thats the problem.

Maybe try accessing it through a proxy service or somthing? (i would try, but i cant cos i'm at work and such things get blocked :roll: )
The COW Project : You have a spy in your midst.

luckless666
Pupating Mass
Posts: 90
Joined: Thu Nov 06, 2003 3:16 am
Location: West Sussex, United Kingdom

#13 Post by luckless666 »

Maybe try accessing it through a proxy service or somthing? (i would try, but i cant cos i'm at work and such things get blocked)
Thats it. I access through a Uni proxy. My brother says it loads fine at homw too. Damn Halls with their shody internet connections!!! LOL. Well at least its free...
Chris Walker
| c.walker (at) mgt.hull.ac.uk |

WorldForge.org

Yoghurt
Programmer
Posts: 376
Joined: Sat Jun 28, 2003 8:17 pm
Location: Heidelberg, Germany

Re: [programming] Info on 2D games using OpenGL

#14 Post by Yoghurt »

leiavoia wrote:Some have suggested i use OpenGL instead.
Thanks for any tips.
(Better reply late than never ;))
I find allegro very suited for 2D-games. It is cross-platform, and uses Hardware-accel wherever possible. It also has a midi-sequencer, zooming and a (small) GUI built in.
http://alleg.sourceforge.net (!)

leiavoia
Space Kraken
Posts: 167
Joined: Sun Jul 20, 2003 6:22 pm

#15 Post by leiavoia »

too late. I've already converted to OpenGL. It took me the whole weekend to get my crash-course, but i know enough now to reconstruct my demo in OpenGL instead of SDL. Here are some relatively recent screenshots:

http://forum.orionsector.com/viewtopic.php?t=1300

Right now i'm working on the collision detection backend and streamlining some quadtree structures. fun!

Post Reply