Using Vertex Buffers

Started by
1 comment, last by Matthewj234 11 years, 10 months ago
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);
}

- Numprt

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

Normally, things look like this
http://www.opengl.org/wiki/VBO_-_just_examples
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

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 :D Thank you!

- Numprt

This topic is closed to new replies.

Advertisement