View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Using Vertex Buffers

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Matthewj234  Members

Posted 27 May 2012 - 05:30 PM

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
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[i]);
}
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);
}


### #2V-man  Members

Posted 27 May 2012 - 08:56 PM

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, 27 May 2012 - 08:56 PM.

Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

### #3Matthewj234  Members

Posted 31 May 2012 - 04:54 AM

Did you remember to bind your VBO and IBO (glBindBuffer)?

Normally, things look like this
http://www.opengl.or...-_just_examples

Sorry for taking so long to respond. But your reply helped, and it now all works Thank you!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.