PDA

View Full Version : 2D Sprites in OpenGL



Eggman
12-21-2003, 07:15 PM
I am considering working on a game interface using OpenGL. I want it to be a 2D sprite based interface (for simplicity) and I am wondering if OpenGL is a good language to do it in.

Also, is there a best way to do this? Does OpenGL have built in tools for 2D? I was thinking of either using a Pixel map, or using texture mapped rectangles (so I can also use some funky 3D effects). Is there a better way?

Thanks, Eggman

JanHH
12-21-2003, 08:42 PM
yes you can use textured rectangles. OpenGL has a projection mode that is orthogonal (no "perspective"I), you can very easily do it with that. look at gluOrtho2D and glOrtho.

dorbie
12-22-2003, 03:01 AM
Yes you can do sprites, alpha blended textured geometry is probably the best way to go. "Alien Flux" is an example of this, do a search and download the demo.
http://www.soft14.com/Games/Action/Alien_Flux_3180_Review.html

In addition you can draw 3D objects with a 2D projection.

You can also draw 3D objects in 3D in a 2D style shooter, this can really make it look like a top quality title with the right particle effects, models & gameplay.

"Space Tripper" is a great example of this go download the demo & check it out:
http://www.pompom.org.uk/spacetripper.htm

Yea they're both defender inspired.


[This message has been edited by dorbie (edited 12-22-2003).]

Eggman
12-22-2003, 06:56 AM
Okay, so it would appear texture mapped polygons would be the way to go. Next question. What is the most effective way of painting the background image? Would I do a very large texture mapped rectangle, or is there some way to actually draw a background image? Perhaps it would help if I were to say that I am looking for a Zelda type interface for an RPG. I would like to have the character centered in the middle and have the background move as the character stays centered. Although in some areas I may prefer to have the character move and anchor the backround.

Thanks again,
Eggman

12-22-2003, 07:27 AM
Instead of drawing the whole background once on one quad, you can draw individual tile on its own quad, and glTranslate them when you need to.

dorbie
12-22-2003, 10:20 AM
You probably want a series of textured tiles for the background that you draw before the characters. You can't do the whole thing in one go if you're scrolling because you'd need to generate your texture each time you scrolled or at leas when you moved off the edge (and textures have size limitations that are hardware dependent).

So imaging how you construct your map, as a series of elements, like grass, path, rock, water. Then place each feature in a texture or a small part of one texture, next draw your map directly to the screen as a series of polygons for each terrain type at each region of the map. This way as the character moves you only draw what is visible and have the flexibility to have large maps for a small texture budget while retaining acceptable graphics performance.

[This message has been edited by dorbie (edited 12-22-2003).]

12-26-2003, 06:58 PM
I have a question related to this. Is it possible to store sprite textures in memory as 8-bit textures referencing different palettes, and draw them to a 24-bit screen?