Advertisement Jump to content
Sign in to follow this  
Matthewj234

Using Vertex Buffers

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

Hey guys, So Ive been pondering this for a while, and its annoying me. I am using LWJGL and I am trying to render a simple cube, buy using an array of verticies. Can anyone offer some help as to how to do this. I think im close, but its just wont seem to work :)

Anyway, the code is below, thanks in advance for any help offered!


public Voxel(float x, float y, float z) {
// Set the location
this.xOffs = x;
this.yOffs = y;
this.zOffs = z;
// _initVertex();
// Set the coordinates
Float[] v = {
// abccda
// Top
xp, yp, zm, xm, yp, zm, xm, yp, zp, xm, yp, zp, xp, yp, zp, xp, yp, zm,
// Bottom
// hgffeh
xp, ym, zp, xm, ym, zp, xm, ym, zm, xm, ym, zm, xp, ym, zm, xp, ym, zp,
// Front
// dcgghd
xp, yp, zp, xm, yp, zp, xm, ym, zp, xm, ym, zp, xp, ym, zp, xp, yp, zp,
// Back
// baeefb
xm, yp, zm, xp, yp, zm, zp, ym, zp, xp, ym, zm, xm, ym, zm, xm, yp, zm,
// Left
// cbffgc
xm, yp, zp, xm, yp, zm, xm, ym, zm, xm, ym, zm, xm, ym, zp, xm, yp, zp,
// Right
// adhhea
xp, yp, zm, xp, yp, zp, xp, ym, zp, xp, ym, zp, xp, ym, zm, xp, yp, zm };
vbo = BufferUtils.createFloatBuffer(v.length);
for (int i = 0; i < v.length; i++) {
vbo.put(v);
}
vertices = v;
System.out.println("" + vbo);
}
public void render() {
glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vbo);
// draw a cube
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, 0);
// deactivate vertex arrays after drawing
glDisableClientState(GL_VERTEX_ARRAY);
}

Share this post


Link to post
Share on other sites
Advertisement
Did you remember to bind your VBO and IBO (glBindBuffer)?

Normally, things look like this
http://www.opengl.org/wiki/VBO_-_just_examples Edited by V-man

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!