Permalink
Browse files

switched filling in of buffer data to array to prep for models

  • Loading branch information...
1 parent 738e45c commit 3e902325999c562a4315bc02ab0f9109a2f48089 @alihelmy committed Sep 26, 2011
Showing with 12 additions and 13 deletions.
  1. +12 −13 LessonTwo/com/onehandstand/lwjgltutorial/lessontwo/ShaderTriangle.java
@@ -25,6 +25,8 @@
import static org.lwjgl.opengl.GL12.glDrawRangeElements;
import java.nio.ByteBuffer;
+import org.lwjgl.opengl.GL11;
+
public class ShaderTriangle {
private int shader, vertexShader, fragmentShader;
@@ -57,14 +59,12 @@ private void initBuffers() {
GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB,
vboVertexAttributesSize, null);
//put int vertex position data
- vertexPositionAttributes.putFloat(0.0f);
- vertexPositionAttributes.putFloat(0.8f);
-
- vertexPositionAttributes.putFloat(0.8f);
- vertexPositionAttributes.putFloat(-0.8f);
-
- vertexPositionAttributes.putFloat(-0.8f);
- vertexPositionAttributes.putFloat(-0.8f);
+ float[] vertexPositions=new float[] {
+ 0.0f, 0.8f, //v1
+ 0.8f, -0.8f, //v2
+ -0.8f, -0.8f //v3
+ };
+ vertexPositionAttributes.asFloatBuffer().put(vertexPositions);
//flip buffer, unmap and unbind
vertexPositionAttributes.flip();
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
@@ -73,15 +73,14 @@ private void initBuffers() {
// set size of vertex index buffer
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, this.vboVertexIndices);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vboVertexIndicesSize, GL_STATIC_DRAW_ARB);
- ByteBuffer vertexIndexes = glMapBufferARB(
+ ByteBuffer vertexIndeces = glMapBufferARB(
GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB,
vboVertexIndicesSize, null);
//put in vertex index data
- vertexIndexes.putInt(0);
- vertexIndexes.putInt(1);
- vertexIndexes.putInt(2);
+ int[] indeces=new int[] {0, 1, 2};
+ vertexIndeces.asIntBuffer().put(indeces);
//flip buffer, unmap and unbind
- vertexIndexes.flip();
+ vertexIndeces.flip();
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}

0 comments on commit 3e90232

Please sign in to comment.