View Full Version : OpenGL core and 2d graphics (sprites)

12-21-2009, 10:31 AM
What is the best way to render sprites with 3.2? (for GUI and the likes)

I am currently storing multiple sprites in a single texture.

This is how I used to do it:
-load list of sprites (x,y,w,h,texid) from txt file.
-draw_sprite(sprite* spr, x,y)...
--render quad with coords/texture coords according to spr.

This is how I am thinking of doing it:
-load one texture holding sprite graphics
-load one texture holding sprite info (x,y,w,h)
-send uniform with sprite info index
-send uniform with sprite pos
-render a vbo containing one quad corners (0,0) and (1,1)...
--vertex shader scales and translates points and calcs uv's
--fragment shader looks up sprite texture

I presume that a more clever solution might exist, so pointers a most welcome :)

12-21-2009, 04:54 PM
Well, IMHO using a texture to hold sprite info is a bit overkill.

instead what you could do is to upload an array of all the possible sprites into the VBO.
Then just update the position and render the vertics in question.

12-22-2009, 07:42 AM
hmm yeah ok, I guess that is more simple.. like

void myDrawSpriteFunction(unsigned int id,float x, float y)
setup shaders and bind vbos etc..
setup a uniform matrix for x and y translation
// wasn't there a way to store and recall this information in one function call?

glDrawArrays(GL_QUADS, id*4, 4 );