Jump to content
  • Advertisement
Sign in to follow this  
PC-maniak

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

This topic is 3862 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! 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.vertex, 0, m_pFaces.n_verts, m_pFaces.index, m_pFaces.n_indexes); [Edited by - PC-maniak on November 25, 2007 4:05:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
Firt I think you would have to pass m_pFaces.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
Thank for your fast reply. Ok, I can set vertex buffer start position calling glVertexPointer, but how to set index buffer start position?

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!