Sign in to follow this  
YoureNext

OpenGL 2D sprites in opengl

Recommended Posts

I started making a simple game in 2d. The way I go about it is i have a huge bitmap with all the sprites in it. Unfortunatly, it doesn't seem to like to map the texture coordinates if the bmp is too big. When i have a bmp of 64x64 the game runs at 6000 fps while a 768x256 bmp runs at 11. What could I be doing wrong ? is using a bmp that big asking for trouble? Thanks.

Share this post


Link to post
Share on other sites
Video cards prefer textures that are power of twos dimension wise and (most) prefer square textures as well.

32x32
64x64
128x128
256x256
512x512
1024x1024 (not really recommended for older card's sake)
2048x2048 (not really recommended for older card's sake)

Split up your sprite sheet into multiple sheets and it'll perform fine.

Share this post


Link to post
Share on other sites
768 is not a pwoer of 2 like 512 or 1024.
some cards support non power of 2 texture eg gffx but only in software (hence slow rendering)

Share this post


Link to post
Share on other sites
By definition a number that is a power of two is a number n, such as
----------------------
|2^x = n <=> lg n = x|
----------------------

where lg = logarithm of base 2

So 768 isn't a power of two... So that maybe what's causing your problem... I know that at least OpenGL 1.1 isn't very into all that "non power of 2 textures" kind of thing...

EDIT: Sorry... I had read that you said that 768 was a power of two :x

Share this post


Link to post
Share on other sites
What you can do is adding extra white space to the texture so that it becomes a power of two... You can also split into several textures...

Share this post


Link to post
Share on other sites
Quote:
Original post by GroZZleR
Video cards prefer textures that are power of twos dimension wise and (most) prefer square textures as well.

32x32
64x64
128x128
256x256
512x512
1024x1024 (not really recommended for older card's sake)
2048x2048 (not really recommended for older card's sake)

Split up your sprite sheet into multiple sheets and it'll perform fine.


Seconded. You do have the right idea though in keeping your sprites/tiles/graphics together in one texture as much as possible. Doing so, with approapriate batching, will reduce the number of texture state changes as much as possible which will reduce a ton of overhead, as texture changes are one of the most expensive ops you can do on a GPU.

Basically you want to batch all your calls to each sprite together, then to other sprites within that texture, and only when necessary load in another texture. Even though the API makes loading textures (onto the GPU) pretty transparent, you should still be thinking about it. To optimize your sprite/tile sheets, group graphics into sets that will likely have each other nearby during the rendering process. IE - group background textures together, foreground textures together and sprite textures together.

Share this post


Link to post
Share on other sites
Btw... In my sprite engine I was having an, I think, error... Everytime I want to draw something I have to first glLoadIdentity on the matrixes and then call glOrtho.. At every sprite that's drawn.... glLoadIdentity I can understand... But glOrtho?! Don't know why...

Share this post


Link to post
Share on other sites
Quote:
Original post by k0ns0l3
Btw... In my sprite engine I was having an, I think, error... Everytime I want to draw something I have to first glLoadIdentity on the matrixes and then call glOrtho.. At every sprite that's drawn.... glLoadIdentity I can understand... But glOrtho?! Don't know why...
Post some code, you must be doing something wrong somewhere because that sort of driver bug would be caught very quickly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this