[SDL] 2D with openGL & SDL

Sean Middleditch elanthis at awesomeplay.com
Tue Jul 17 08:31:16 PDT 2007


On Mon, 2007-07-16 at 22:08 -0700, Mike Powell wrote:
> benang at cs.its.ac.id wrote:
> > 4. AFAIK, to add a texture, the width & height of the image should be a
> > power of 2. So how do I make a sprite with width and/or height not of
> > power of 2?
> 
> This was true in the old versions of OpenGL, but I know it's been
> fixed by OpenGL 2.0. Not sure, offhand, exactly which version made the
> shift, but if your version is up to date, you should be able to use
> any texture size. Provided, of course, it's not larger then your
> implementation's maximum texture size. These days, that's usually
> either 512 or 1024, so you probably won't have a problem there.

I think OpenGl 1.5 also has this restriction removed, and it's quite
possible the driver supports 1.5 but not 2.0.  (2.0 makes GLSL
required.)

There are various things you can do to alleviate the texture
limitations, though.  One trick is to pack multiple
tiles/images/textures into a single OpenGL texture, which if done
carefully, will let you use a max sized texture with little wasted
space.  You then just have to remember the texture ID, width, height,
x/s offset, and y/t offset of your image in the texture, and pass those
various parameters in when rendering your quads.  It can also help to
just design your graphics around powers of two dimensions if at all
possible.  Especially if you're making a tile-based game and not some
other kind of app, splitting up your tiles into smaller 16x16 or 32x32
bits would be a good idea.  (Few people realize this, but the tiles in
old 2D Nintendo games were actually very very small - most of the tile
"rips" you find online don't actually rip the tiles, but larger squares
made of multiple tiles, so a lot of people think they're bigger than
they really are.)

> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
-- 
Sean Middleditch <elanthis at awesomeplay.com>



More information about the SDL mailing list