Gustavo
Gustavo

Reputation: 795

OpenGL ES code to revise

I´m creating an opengl ES project and I´m trying to show some textures, all works good but the problem is the use of the memory, every 5 seconds increments almost 1 Mb, I think I´m doing something wrong, I´m not using any of this apple recommendations I will tray for sure, but I want to know if my code have some bug, there is how I´m paiting:

    // Generate the vertex buffer object (VBO)
glGenBuffers(1, &ui32Vbo);

// Bind the VBO so we can fill it with data
glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo);

// Set the buffer's data
// Calculate verts size: (3 vertices * stride (3 GLfloats per each vertex))

glBufferData(GL_ARRAY_BUFFER, uiSize, verts, GL_STATIC_DRAW);

// Bind the VBO so we can fill it with data
glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 20, 0);    // Stride = 20 bytes

glBindTexture(GL_TEXTURE_2D, textID);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);    
glTexCoordPointer(2, GL_FLOAT, 20, (void *)12);

glDrawArrays(GL_TRIANGLE_FAN, 4, 4);

// Bind the VBO so we can fill it with data
glBindBuffer(GL_ARRAY_BUFFER, 0);

Thank you very much!!!

Upvotes: 0

Views: 73

Answers (1)

crazyjul
crazyjul

Reputation: 2539

You should generate the vertex buffer object only once, the use it draw.

It seems you create a new one each frame.

Upvotes: 3

Related Questions