[Top] [All Lists]

Re: [SDL] 2D with openGL & SDL

Subject: Re: [SDL] 2D with openGL & SDL
From: Kuon
Date: Tue, 17 Jul 2007 17:57:45 +0200
On 17 Jul 2007, at 5:31 PM, Sean Middleditch wrote:

> On Mon, 2007-07-16 at 22:08 -0700, Mike Powell wrote:
>> benang@xxxxxxxxxxxx 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 2048 is common.

In our game, we use only power of two textures to be more compatible  
and we also noticed a speed boost on some platforms/card.

We simply fill the texture with transparent pixels and we adjust the  
coordinates to display the image correctly.

> 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.)

Also, for animations (sprites), having one texture is faster, as you  
can keep it and only change the coordinates.

For tiles, I once worked on one engine, and we used one texture for a  
couple of reasons:
- A bit faster
- Able to create bigger tiles, or pre-joined tiles (like a mountain  
with a forest around, let's say its 5 tiles, you would be able to  
draw this in one pass)
- Code is easier to manager, for example, let's take the night  
filter, you apply it once to the texture and you are done.


"Don't press that button."

SDL mailing list

<Prev in Thread] Current Thread [Next in Thread>