Greetings earthlings of JGO.
I’ve been i little stuck on this problem for a while now.
I want to know if there is there a way to transform the individual vertices of the model without needing to change the vertices array and then reload it to the vao. Also whenever i do a transformation it applies it to the whole model.
I am also aware that there might be a way to do this in the vertex shader.
vertices and indices:
// defines a triangle
private static float[] vertices = {
-0.5f, 0.5f, 0,
-0.5f, -0.5f, 0,
0.5f,-0.5f, 0,
};
private static int[] indices = {
0,1,2
};
and i load them to a vbo and vao, after which i load to shader, render etc.
private List<Integer> vaos = new ArrayList<Integer>();
private List<Integer> vbos = new ArrayList<Integer>();
public Shape loadToVao(float[] positions, int[] indices) {
int vaoId = glGenVertexArrays();
vaos.add(vaoId);
glBindVertexArray(vaoId);
bindIndicesBuffer(indices);
dataInAttribList(0, positions);
glBindVertexArray(0);
return new Shape(vaoId, indices.length);
}
private void dataInAttribList(int attribNum, float[] d) {
int vboId = glGenBuffers();
vbos.add(vboId);
glBindBuffer(GL_ARRAY_BUFFER, vboId);
FloatBuffer b = BufferUtils.createFloatBuffer(d.length);
b.put(d);
b.flip();
//GL_DYNAMIC_DRAW the vertices will change
glBufferData(GL_ARRAY_BUFFER, b, GL_DYNAMIC_DRAW);
glVertexAttribPointer(attribNum, 3, GL_FLOAT, false, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
private void bindIndicesBuffer(int[] indices) {
int vboID = glGenBuffers();
vbos.add(vboID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID);
IntBuffer b = BufferUtils.createIntBuffer(indices.length);
b.put(indices);
b.flip();
glBufferData(GL_ELEMENT_ARRAY_BUFFER, b, GL_STATIC_DRAW);
}
also i want to note that i have seen this thread: http://www.java-gaming.org/topics/applying-transformations-to-vertices/34070/view.html