KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
So I'm working on a game and I need to draw a lot of the same object. Same shape, same size, same color, just different locations. Right now my setup is like this. I have some class Renderer where object that want to draw on the screen can call static void addVertex(float x, float y, float z); which will store the vertex into an std::vector . When everyone is done drawing static void draw(); in Renderer is called where everything is stuffed into a VBO and drawn onto the screen. draw looks like this: void Renderer::draw() { glBindBufferARB(GL_ARRAY_BUFFER_ARB, _quadID); glBufferSubDataARB(GL_QUADS, 0, _vertexBuffer.dataSize(), _vertexBuffer.toArray()); glColorPointer(4, GL_FLOAT, 0, _colorBuffer.toArray()); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 0, _vertexBuffer.toArray()); glDrawArrays(GL_QUADS, 0, (_vertexBuffer.size() / 3)); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); _vertexBuffer.clear(); _colorBuffer.clear(); } Where _vertexBuffer and _colorBuffer are of a class template <class T> Buffer which is more or less a managed std::vector<T> for my purposes. With this setup I can get about 300 things on screen before I start slowing down. Right now everything is a GL_QUAD. Bear in mind I'm a little new to OpenGL, if the above is embarrassing I'm sorry. How can I improve this to account for like polygons?
Tags (comma-separated)
Save Edits
Cancel