Original Post
Hi, This is my first time posting here, normally I just spend a lot of time on Google or whatever to figure something out, but I'm having trouble understanding something that is pretty OpenGL related, and I figured this would be one of the better places to sign up and ask. I've tried searching to see if anyone else asked this, but I don't think anyone has. Okay, onto the question. I have a 2D sprite rendering engine that works fine as is, it uses vertex arrays to get better performance than immediate mode, though I still see there's a lot of time being spent in the draw code. Here's a rough view of what I'm doing for every sprite: glPushMatrix glMultMatrix(current sprite's transform matrix) CalculateVertexCoords for this sprite CalculateTextureCoords for this sprite glVertexPointer(load coords) glTexCoordPointer(load coords) glDrawArrays(5 points, using Triangle_Fan) glPopMatrix This all works fine, but with profiling and such I've noticed that DrawArrays was taking a long time, so I did research on batching and such, and lots of people have said (on other forum boards for sprite batching) that if you could compile all the coords into one set, and then make one call to DrawArrays, it would be faster. They also said to use screen or world coordinates for 2D since it's simpler that way. Here's the problem though, the vertex coordinates that are calculated are done from 0,0,0, so they're obviously not absolute coordinates. glDrawArrays gets a quad that is based on the origin, yet because of the local to world transform that happens behind the scenes, it puts the sprite in the right place. What I'd like to do is give glDrawArrays the absolute coordinates and remove the need for the Push/Pop matrix calls. Everything is just sprites so I don't think I really need to have multiple levels of matrices anyway. The transform matrix that is multiplied already stores position, up, view, and side vectors, and game specific code changes it (rotate, translate, etc gets concatenated into it). I'm not really sure what to call this problem, aside from, "How do I change that above repeated call to DrawArrays into a batch form, but keep the transformations". Maybe this is a math specific problem, but I figured OpenGL would be a place to start. If specific code is necessary, I can post it, but I figured this would be a general enough question. Maybe someone has already done this in their engine before? I appreciate any help I can get, thanks!