OpenGL / SDL 2d Interface: Preferred Method?

I am currently working on a 2d interface system for a MacOSX game I am writing, in which the graphics engine is based on an OpenGL / SDL combination and written in C++. Among this community, what is the preferred method for implementing 2d graphics and text? I am currently struggling to choose between the following options:

- Load and draw bitmaps straight onto the screen, using glDrawPixels. This would require writing my own image loading functions, but would have low overhead and do everything I wanted to.

- Draw bitmap textures onto GL polygons. Again, this would require image loading functions, but there is more support / documentation out there for this approach. However, text support wouldn't be worth the trouble.

- Spending some quality time picking up Quartz and hashing it into my C++ engine. While Quartz has tons and tons of fantastic 2d graphical and text features, the overhead and learning curve would be relatively high. Also, there is the potential for compatibility issues between my C++ code and the Obj-C in the Quartz framework, and this part of the graphics engine would need to be completely re-written if the code eventually gets ported to Windows or Linux.

- Dedicated use of DevIL, which I just came across today. At the moment, this seems like it might be the best option, since it covers nearly all of my needs (I would use a bitmap font for text rendering), it supports tons and tons of image formats, and supports OpenGL / SDL. Has anybody used this library before? (I've seen it mentioned on the forum before, but without many comments or details.) Can anybody comment on overhead, ease of use, cross-platform support etc. from their own experience?

For 2D graphics, there's no question -- mapping textures onto quads using OpenGL is definitely the way to go. It goes great with SDL.

One pitfall you'll probably run into with using texture mapping for 2D games is the power-of-two size restriction. However, getting around that is pretty easy: use GL_TEXTURE_RECTANGLE_EXT instead of GL_TEXTURE_2D. Your game won't be able to run on anything older than an ATI Rage128, but I think the tradeoff is worth it. Search the forums for more details on how to use rectangular textures.

As for text, well, you could use something like FTGL or Freetype, or you could just go with an image-based font. Personally, I like the image font method for its flexibility and relative ease.

In terms of image loading, there's unfortunately no clear-cut best way to do it. Some people use Quartz; I personally use a library called glpng. In essence, all you need is something that can give you raw image data to feed to OpenGL's texture mapping functions, and glpng does that in a nice and simple manner. The only drawback, of course, is that you can only load PNGs.

I'll address the other options as well:

- glDrawPixels() is much slower than texture mapping, since it uploads the image data to the GPU each time it is called. With texture mapping, the image data gets uploaded only once, and is displayed as needed, making it much faster.

- Quartz can be great for image loading, but it is horrid for actual frame rendering. It's designed more for making things look really cool and snazzy (at the expense of performance). I'm not sure about CoreAnimation, since I haven't worked with it, but Quartz's slowness is unacceptable for games.

- I looked into DevIL once. It seems nice on the surface, but in my opinion, it's too overblown for the purposes of a game. Personally, I ran into a lot of trouble when trying to install and incorporate it into my project. Of course, you're definitely welcome to try it out -- I just didn't think it was worth it, myself.

Najdorf Wrote:@Wowbagger: do you use a library for image based fonts or did you roll your own?

I rolled my own. Right now, I'm using a simple one-file-per-char method. But I'm thinking about maybe rewriting it sometime to use a single texture with all the chars packed onto it. Mainly for performance reasons.

Wowbagger Wrote:I rolled my own. Right now, I'm using a simple one-file-per-char method. But I'm thinking about maybe rewriting it sometime to use a single texture with all the chars packed onto it. Mainly for performance reasons.

I have a program based on SDL_font that packs font textures, and prints out the metrics. It's about as simple as you could possibly get, weighing in at about 90 lines of code. If it doesn't do exactly what you want, you should be able to figure out how it works without any trouble.