Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL Index Buffers ( IBO )

Started by yoshscout Oct 1, 2007 at 3:20 AM 5 replies 14.3k views
Original Post
yoshscout
yoshscout
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
yoshscout
yoshscout
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)
yoshscout
yoshscout
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
vibe3d
vibe3d
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
MENTAL
MENTAL
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.
V-man
V-man
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
vibe3d
vibe3d
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 ;-)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.