Jump to content
  • Advertisement
Sign in to follow this  
yoshscout

OpenGL OpenGL Index Buffers ( IBO )

This topic is 4066 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

i have really been having a hard time trying to build an index buffer in opengl. it is fairly trivial in direct x. i have created a vbo which contains the indices.
	glGenBuffers(1, &m_IndexBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, m_IndexBuffer);
	glBufferData(GL_ARRAY_BUFFER, 2*m_numIndices, m_pIndices, GL_STATIC_DRAW);

the problem is where to go from here. i found arb information that suggest not putting this in the same buffer as my main vbo because the graphics card may not allow ibo in vram, id prefer to do it by the book and not screw up caching of some section of the pipeline

Share this post


Link to post
Share on other sites
Advertisement
after a wild guess i fixed it with the key enum mode GL_ELEMENT_ARRAY_BUFFER.

i titled my post so that it would come up on search because i searched for this and all i got was mess... so here it is solution i spent way too long on

you can bind a vertex buffer and index buffer both. the vbo is bound as the GL_ARRAY_BUFFER and the ibo is bound as the GL_ELEMENT_ARRAY_BUFFER. then in your glDrawElements call you have to specify the number of indices as the 2nd param, and the 4th param is an offset from the ibo start (0 if your just using one draw call in one ibo)

Share this post


Link to post
Share on other sites
here is a rough D3D9(almost the same as 8 and 10) to OpenGL translation also

CreateVertexBuffer -> glGenBuffers
CreateIndexBuffer -> glGenBuffers

SetStreamSource -> glBindBuffer( GL_ARRAY_BUFFER, ...
SetIndices -> glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ...
SetFVF -> gl*Pointer + glEnableClientState
DrawIndexedPrimitive-> glDrawElements

i hope this helps people in there transition to opengl from d3d

Share this post


Link to post
Share on other sites
no offense but it really is a trivial task in OpenGL too, had you read the official VBO documentation you would have found it in no time. Calling it an IBO is only confusing for other newbies too because there is no such thing.

Offical Spec

Share this post


Link to post
Share on other sites
initialization...

glGenBuffers (1, &m_IndexBuffer);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, m_IndexBuffer);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, 2 * m_numIndices, m_pIndices, GL_STATIC_DRAW);

when drawing...

/* setup your gl*Pointers as usual */
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER_ARB, m_IndexBuffer);
glDrawElements (shapes, m_numIndices, GL_UNSIGNED_SHORT, 0);
glBindBuffer (GL_ARRAY_BUFFER_ARB, 0);

Only call the last glBindBuffer function if you want to disable buffering. Otherwise, just leave it as it is and bind the new buffers as and when needed.

Share this post


Link to post
Share on other sites
There is a lot of documentation at www.opengl.org
No need to guess how GL works.
At the top, put mouse on documentation, click on specification

Download the OpenGL 2.1 Specification
VBOs have become part of GL since 1.5 so you'll find it in the older docs as well.
Advice : when you do a search, remove the gl or GL_
For example, search for GenBuffers instead of glGenBuffers

I say IBO as well because these buffers are distinct from VBO.

Like vibe3d said, the extension can be found at www.oepngl.org/registry

Share this post


Link to post
Share on other sites
o yeah i must admit that IBO actually makes more sense but the powers that be obviously didn't think so. I just thought I would point it out that the reason there is no documentation on IBO's in gl is because there is no such thing according to gl documentation, im sure you get what i mean.

I can just picture someone new to gl coming on here and seeing the word IBO and than going out trying to find documentation on it ;-)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!