Basic OpenGL questions - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Basic OpenGL questions (/thread-2007.html)
Basic OpenGL questions - Mercy - Dec 22, 2008 05:39 PM
Hi all, I'm finally getting around to programming my first real OpenGL-animated game (or trying to at least) and had some basic questions I was hoping you might be kind enough to answer, to help me avoid any pitfalls. I think I've got the basics of texture loading and quads down but in planning my game I've come up with some new conceptual puzzles. Any help with these is greatly appreciated, thank you very much (and sorry for how long this is).
1. First off I'm wondering how to decide in certain cases the best way to store textures (ie, multiple 'sprite' graphics in a single image and/or a single texture)? For instance, on the splash screen I wanted to have my buttons (New Game/Load Game/Preferences/etc.) actually act as sprites and move around a bit.
Should I have these particular textures in one big .PNG, load them into one texture, and somehow apply only a portion of the texture to each quad? Or should I load portions of the .PNG into individual textures for each quad?
2. I was wondering if anyone could provide me the basic rule of thumb regarding power of 2 texture size. My textures should ideally be some power of 2 in both width and height? Do they need to be square? If this is the case what would be the best way to draw a 1024x768 background image? Should I make the texture 1024x1024 and just chop off the bottom?
3. This game will be mac-only. Are there any special considerations I need to take into account in terms of graphic card capabilities? Do I need to check the card and make sure it has enough graphics memory, for instance, so I don't load too many textures or anything like that? Or are these things abstracted and handled at a lower layer automatically?
4. One of my sprites I plan on having a kind of 'on fire' flaming effect. Was wondering if anyone could just point me in the direction of the OpenGL technique that might be best for this. Should I just use lots of small quads with semi-transparent 'puffs' of fire or should I use some other method of producing particle effects? I know this is probably an involved topic so any keyword pointers I can google would be appreciated.
Thanks very much
Basic OpenGL questions - CarbonX - Dec 22, 2008 10:28 PM
1. Really this is a matter of preference, having them all in one texture produces less loading overhead, but a lot of people use many smaller files with one frame each.
2. All textures must be PoT unless you are using GL_EXT_TEXTURE_RECTANGLE, however they do not need to be square. So a texture like 1024 x 512 is fine.
3. For a 2D game checking things like VRAM are probably not necessary as most modern computers have plenty of VRAM to support any manner of 2D sprites. Unless you will have more than say 256 MB of content in VRAM at once. If that's the case checking might be a good idea to warn users that it might run slow on older hardware.
4. A particle system should do just fine there. Lots of resources for that on gamedev.net and google.
Hope that helps
Basic OpenGL questions - DoG - Dec 23, 2008 01:43 AM
CarbonX Wrote:2. All textures must be PoT unless you are using GL_EXT_TEXTURE_RECTANGLE, however they do not need to be square. So a texture like 1024 x 512 is fine.
That is incorrect. All Macs 10.5 or 10.4(Intel) forward support ARB_texture_non_power_of_two, so textures can be any size, unless you want to be further backwards compatible. The only caveat is mipmapping, which isn't supported for NPOT textures on some hardware (where it's also not supported for EXT_TEXTURE_RECTANGLE), like the ATI X1600 and cohorts.
Basic OpenGL questions - AnotherJake - Dec 23, 2008 08:57 AM
Whether you use a sprite sheet (or atlas, or whatever you want to call it) may depend on a few factors, but as CarbonX said, it's ultimately up to you. Having many sprites on one sheet means you won't have to bind a new texture for every object which can be advantageous for performance, but then you have to have a system of breaking up the coordinates and managing sprites within/across sheets. Sprite sheets on Mac aren't nearly as important as they used to be, unless you someday decide to do some iPhone development where performance is limited.
Adding further to what has already been said: POT is only *required* on iPhone and ancient hardware like Rage128. On Mac, use rectangle textures and you can do 1024 x 768. Do take note that the texture coordinates will need to be specified as pixel dimensions and not normalized (i.e. 0 to 1024 and 0 to 768 in your case, not 0 to 1 as you've probably already been using).
The newer MacBooks have 144 MB VRAM, but the (slightly) older ones, including Mac Minis, only have like 64 MB IIRC. In my experience, you have to be plowing through a whole heck of a lot of graphics before you start bumping into those limits in practice. It's hard to know exactly what VRAM is being used though since it's virtualized across the entire system, so VRAM usage is a hazy subject.
"lots of small quads with semi-transparent 'puffs' of fire" will probably work fine for a fire effect (I've done that and it works great for me). There are no rules as to how you do your effects.
Basic OpenGL questions - DoG - Dec 23, 2008 10:11 AM
AnotherJake Wrote:Adding further to what has already been said: POT is only *required* on iPhone and ancient hardware like Rage128. On Mac, use rectangle textures and you can do 1024 x 768. Do take note that the texture coordinates will need to be specified as pixel dimensions and not normalized (i.e. 0 to 1024 and 0 to 768 in your case, not 0 to 1 as you've probably already been using).
Just to clear up the apparent confusion, ARB_texture_non_power_of_two != ARB_texture_rectangle.
ARB_texture_non_power_of_two simply allows rectangle textures with the TEXTURE_2D target , so you don't have to deal with the rectangle extension's silliness, eg. tex coords *are* normalized.
ARB_texture_non_power_of_two is apparently not available on 10.3 or 10.4(PPC) or earlier, but ARB_texture_rectangle is.
ARB_texture_non_power_of_two is the way forward, ARB_texture_rectangle should be considered obsolete, as far as the Mac is concerned.
Basic OpenGL questions - AnotherJake - Dec 23, 2008 10:25 AM
Thanks for the clarification DoG. Yes, it can be easy to confuse. I was referring to ARB_texture_rectangle, and have not used ARB_texture_non_power_of_two yet because I still figure I'm developing for 10.4 for at least a little longer. I have to agree that ARB_texture_non_power_of_two looks easier to use (swap into existing TEXTURE_2D code) since it keeps the normalized tex coords.