[SDL] 2D with openGL & SDL

Sean Middleditch elanthis at awesomeplay.com
Wed Jul 18 10:47:38 PDT 2007


On Wed, 2007-07-18 at 10:38 +0700, benang at cs.its.ac.id wrote:
> Oh yeah, there's also that approach. As a matter of fact, actually my
> current rendering engine already can blit sprites from an image file with
> multiple sprite images inside it. But I determined that the sprite images
> in the BMP file must be of the same width and height (eg. all must be
> 16x16, 40x30, etc). I use this to blit my bitmap fonts. This probably will
> make the 2D artist complains. Well thanks anyway.

::sigh::  Think about it a little more.  You're dismissing a very
elegant and correct solution simply because it isn't the same as your
existing solution.

There is no reason that all of the sprites in one BMP have to be the
same size.  At all.  As I said, each sprite can have its own width,
height, and its own offset within the texture image.  It takes a little
more code than making everything the same size, but it's worth it.

It doesn't take any real additional work on part of the artists, either,
especially if you're already using packed sprite image files.

Note that this is *exactly* how just about any 3D game handles model
textures.  Take a complex model like a medieval knight.  Most engines
will use a single texture bitmap which is packed with the required
patches of chain maille, flesh, cloth, hair, eyes, etc. and map that
single texture over the model's vertexes.  Most professional 2D games
(i.e, the actual SNES golden games) did the same thing.  Most tiled/2D
games get that wrong, because most tile rips you'll find of those old
games are done with screenshots and an image editor, not the actual
image packs from the ROM.  There's a reason the old games did it that
way - it worked, it was memory efficient, and it was easy for artists to
handle.

> 
> Sean Middleditch said:
> >
> > 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>
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at lists.libsdl.org
> > http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
> >
> 
> 
> Fare thee well,
> Bawenang R. P. P.
> 
> ----------------
> ERROR: Brain not found. Please insert a new brain!
> 
> “Do nothing which is of no use.” - Miyamoto Musashi.
> 
> "I live for my dream. And my dream is to live my life to the fullest."
> 
> 
> _______________________________________________
> 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