Anonymous avatar Anonymous committed 0ec7af5

ported HelloShader to new VBO class

Comments (0)

Files changed (1)

src/main/java/sandbox/misc/HelloShader.java

 import sandbox.common.BaseApp;
 import sandbox.util.ShaderProgram;
 import sandbox.util.VBO;
+import sandbox.util.Vertex;
 
 import java.nio.ByteBuffer;
 import java.nio.IntBuffer;
     protected void setup() {
         // This uses our VBO class, which is a quick hack to hide details, but not anything I
         // recommend for real-world use.
-        vbo.addVertex(
-                new Vector3f(-50, -50, 0),  // position
-                new Vector3f(0, 1, 0),      // normal
-                new Vector4f(1, 0, 0, 1),   // color
-                new Vector2f(0, 0)          // texture coord
-        );
+        vbo.addVertex(new Vertex().position(-50,-50,0).color(1,0,0,1));
+        vbo.addVertex(new Vertex().position(50, -50, 0).color(1, 0, 0, 1));
+        vbo.addVertex(new Vertex().position(50,50,0).color(1,0,0,1));
+        vbo.addVertex(new Vertex().position(-50,50,0).color(1,0,0,1));
+        vbo.bake();
 
-        vbo.addVertex(
-                new Vector3f(50, -50, 0),
-                new Vector3f(0, 1, 0),
-                new Vector4f(1, 0, 0, 1),
-                new Vector2f(0, 0)
-        );
-
-        vbo.addVertex(
-                new Vector3f(50, 50, 0),
-                new Vector3f(0, 1, 0),
-                new Vector4f(1, 0, 0, 1),
-                new Vector2f(0, 0)
-        );
-
-        vbo.compile();
         shader = new ShaderProgram();
         shader.addVertexShader(VERTEX_SHADER);
         shader.addFragmentShader(FRAGMENT_SHADER);
         glClear(GL_COLOR_BUFFER_BIT);
 
         glEnableClientState(GL_VERTEX_ARRAY);
-        glEnableClientState(GL_NORMAL_ARRAY);
         glEnableClientState(GL_COLOR_ARRAY);
 
         vbo.bind();
-        glDrawElements(GL_TRIANGLES, vbo.getSize(), GL_UNSIGNED_INT, 0);
+        glDrawArrays(GL_TRIANGLES, 0, 3);
 
         glDisableClientState(GL_VERTEX_ARRAY);
-        glDisableClientState(GL_NORMAL_ARRAY);
         glDisableClientState(GL_COLOR_ARRAY);
         glPopMatrix();
         shader.stopUsing();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.