• Advertisement
Sign in to follow this  

opengl batch rendering

This topic is 3364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi there i searched the gamedev but seems no perfect match : single vertex buffer and let the driver to decide where to place the buffer, directx equalient : D3DUSGAE_DYNAMIC | D3DUSAGE_WRITEONLY、D3DPOOL_DEFAULT, create an index buffer in the same way as above vertex buffer. in each frame, lock and fill the vertex buffer with vertices have same rendering property, then render. here is my opengl implementation : 1. on initialization, create the vertex buffer
    glGenBuffers(1, &myVB);
    glBindBuffer(GL_ARRAY_BUFFER, myVB);
    glBufferData(GL_ARRAY_BUFFER, 2500_verts, 0, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glGenBuffers(1, &myIB);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, myIB);

2. in each frame :

    // vertex buffer
    glBindBuffer(GL_ARRAY_BUFFER, myVB);
    glBufferData(GL_ARRAY_BUFFER, teapot_vert_num, teapot_vb, GL_DYNAMIC_DRAW);


    // index buffer
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ib);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, teapot_indices_num, teapot_ib, GL_DYNAMIC_DRAW);

    // draw
    glDrawElements(GL_TRIANGLES, teapot_face_num, GL_UNSIGNED_SHORT, 0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

the program crashed when executing 'glDrawElements', what's missing here? what's the correct way to batch render with VBO's ? thank you very much. p.s. the program will be running on a mobile device, so its should be openGLES.

Share this post

Link to post
Share on other sites
Show us how you are setting up glVertexPointer, glTexCoordPointer and glColorPointer.

Also you probably want to use glBufferSubData instead of glBufferData in each frame. Every BufferData call will allocate new memory, but SubData will only fill up already allocated memory block.

Share this post

Link to post
Share on other sites
thanks bubu LV, that's a great hint about using 'glBufferSubData', i'll try it as soon as possible.
it draws perfect when not using VBO, anyway the way to setup pointers are as follows :

struct vertex_t
float3 pos;
float2 uv;
unsigned long clr;

vertex_t vb[4];
vb[0].set(float3(-1, 1, 0), float2(0, 0), 0xFFFFFFFF);
vb[1].set(float3( 1, 1, 0), float2(1, 0), 0xFFFFFFFF);
vb[2].set(float3( 1, -1, 0), float2(1, 1), 0xFFFFFFFF);
vb[3].set(float3(-1, -1, 0), float2(0, 1), 0xFFFFFFFF);

// remember to use glBufferSubData' instead
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(vertex_t), vb, GL_DYNAMIC_DRAW);

glVertexPointer(3, GL_FLOAT, sizeof(vertex_t), vb);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex_t), &vb->uv);
glColorArray(4, GL_UNSIGNED_BYTE, sizeof(vertex_t), &vb->clr);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement