Hello !
I am confused about the way I should transfer attributes values to a Vertex Shader using buffers. In the shader I defined this:
// The vertex position
attribute vec3 Vertex;
// The normal
attribute vec3 Normal;
// The color
attribute vec3 Color;
// The bones index attributes
attribute vec2 Index;
// The bones weight for each indexed bone
attribute vec2 Weight;
in java I use this code to render (the 3D model may dynamically update):
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexID);
if (faces == null)
{ faces = faces(resolution);
size = 3*faces.size();
int bufferSize = size*VSIZE;
if (vbuf == null || vbuf.capacity() < bufferSize) vbuf = BufferUtils.createFloatBuffer(bufferSize);
if (colors) for (Triangle3D f : faces) f.loadrgb(vbuf); else for (Triangle3D f : faces) f.load(vbuf);
System.out.println(size+" points loaded in buffers.");
vbuf.flip();
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuf, GL15.GL_DYNAMIC_DRAW);
}
//GL11.glVertexPointer(3, GL11.GL_FLOAT, VSIZE, VOF);
//GL11.glNormalPointer(GL11.GL_FLOAT, VSIZE, NOF);
//GL11.glColorPointer(3, GL11.GL_FLOAT, VSIZE, COF);
GL20.glVertexAttribPointer(VERTEX, 3, GL11.GL_FLOAT, false, VSIZE, VOF);
GL20.glVertexAttribPointer(NORMAL, 3, GL11.GL_FLOAT, false, VSIZE, NOF);
GL20.glVertexAttribPointer(COLOR, 3, GL11.GL_FLOAT, false, VSIZE, COF);
GL20.glVertexAttribPointer(INDEX, 2, GL11.GL_FLOAT, false, VSIZE, IOF);
GL20.glVertexAttribPointer(WEIGHT, 2, GL11.GL_FLOAT, false, VSIZE, WOF);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size);
As you can see I tried different methods (commented) and I read here and there that there is old and modern ways to do this, but I still don’t know what is the modern and best solution ! All I get with this code for now is nothing rendered !
I know how to use vbo buffers correctly with the default openGL vertex shader variables, I also know how to use attributes without vbo, for example with GL20.glVertexAttrib2f(weight, a, b), but I don’t understand how to do both !