2D sprites in opengl

Started by
9 comments, last by k0ns0l3 18 years, 7 months ago
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.
Advertisement
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.
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)
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
aah :S
ok thanks. That was simple enough.
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...
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.

throw table_exception("(? ???)? ? ???");

...ok...and remember also to use texture objects ( glBindTexture() ) if you are not using them already
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...
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.

This topic is closed to new replies.

Advertisement