Loading attributes in a packed buffer?
Posted by Braindrool on Dec 08, 2012; 12:58am
URL: https://forum.jogamp.org/Loading-attributes-in-a-packed-buffer-tp4027450.html
So, I have returned. Hello once again. I saw a nice and dandy tutorial for loading attributes with shaders on learnopengles.com. But that uses a separate buffer. I was wondering if anyone could point me to an example or a tutorial (even better, an explanation!) on how to use vertex attributes in a packed buffer (e.g. X Y X NX NY NZ .)
package com.braindrool.game;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.fixedfunc.GLPointerFunc;
public class Renderer implements GLEventListener {
GL2 gl;
Model model;
Program program;
int shaderProgram;
Resourcer resourcer;
int MVPMatrix;
int LightPos;
int Color;
int Position;
int Normal;
float rotation;
public void display(GLAutoDrawable drawable) {
rotation += 0.01;
int[] data = model.load(gl, "passion_flower.ply");
gl.glClearColor(0, 0.6f, 0, 1);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, data[0]);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, data[1]);
gl.glDrawElements(GL.GL_TRIANGLES, data[2], GL.GL_UNSIGNED_SHORT, 0);
gl.glRotated(Math.sin(rotation) * 5, Math.cos(rotation) * 5, 0, 1);// Temp
gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
}
public void dispose(GLAutoDrawable arg0) {
}
public void init(GLAutoDrawable drawable) {
gl = drawable.getGL().getGL2();
model = new Model();
resourcer = new Resourcer();
program = new Program(gl);
shaderProgram = program.program("ambient");
gl.glUseProgram(shaderProgram);
MVPMatrix = gl.glGetUniformLocation(shaderProgram, "MVPMatrix");
LightPos = gl.glGetUniformLocation(shaderProgram, "LightPos");
Color = gl.glGetUniformLocation(shaderProgram, "Color");
Position = gl.glGetAttribLocation(shaderProgram, "Positon");
Normal = gl.glGetAttribLocation(shaderProgram, "Position");
gl.glUniform4f(Color, 0.5f, 0.5f, 0.5f, 0.5f);
gl.glUniform3f(LightPos, 1f, 1f, 1f);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height) {
}
}
The uniform / attribute locations are done, but how to actually implement them I could use help with!
Help appreciated ~ Braindrool