Sign in to follow this  
PC-maniak

OpenGL OpenGL - render a polygon using vertex and index buffers with offsets SOLVED

Recommended Posts

Hi! I have some beginner's problem. Can anybody explain me how to render polygon with vertex and index buffer with start offset? I want to render Quake III BSP using triangle list. I have start_vertex, num_verts, start_index and num_indices. Using DirectX it looks like this: g_pD3DDevice->DrawIndexedPrimitive (D3DPT_TRIANGLELIST, m_pFaces[i].vertex, 0, m_pFaces[i].n_verts, m_pFaces[i].index, m_pFaces[i].n_indexes); [Edited by - PC-maniak on November 25, 2007 4:05:24 PM]

Share this post


Link to post
Share on other sites
Firt I think you would have to pass m_pFaces[i].n_indexes/3 as the last parameter to your DX call as that specifies the number of primitives and not indexes.

In OpenGL there is no real notion of a base vertex. You would simply have to set your vertex array pointers through gl*Pointer calls to the base vertex then draw with glDrawElements or glDrawRangeElements.

Share this post


Link to post
Share on other sites
You specify the index buffer start position e.g. in the last parameter to the call to glDrawElements, where you pass a pointer to the indices.

Share this post


Link to post
Share on other sites
I managed to write this code, but nothing is rendered:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(TBspVertex), &m_ptBspVertex[p_bsp_face->i_start_vert_index].pf_position);
glDrawElements(GL_TRIANGLES, p_bsp_face->i_num_indices, GL_INT, &m_ptIndices[p_bsp_face->i_start_index]);

m_ptIndices are type of int.

What I am doing wrong?

Share this post


Link to post
Share on other sites
At first glance it seems correct, but it really depends on the numbers inside the values and the arrays. For instance the indices inside m_ptIndices should have values from 0 to i_num_indices at most.

I assume m_ptBspVertex is the vertex array and p_bsp_face->i_start_vert_index is the index of the base vertex. If so the call to glVertexPointer looks correct at first sight.

If p_bsp_face->i_start_index is the index offset and m_ptIndices the array of all indices then this call also looks correct.

Maybe there is some logic error hidden somewhere which depends on the actual values in the arrays.

Share this post


Link to post
Share on other sites
Look at
http://opengl.org/sdk/docs/man/

and look for glDrawElements.
It says

type


Specifies the type of the values in indices. Must be one of
GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or
GL_UNSIGNED_INT.

indices

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this