I have create a triangle using a shader which successfully renders on a green background.
(This is a code example from the superbible 6 book)
There is a value on the shader which is suppose to make the triangle move.
But I am unable to assign a floatbuffer to that value.
Here is the shader.
#version 430 core
// "offset" is an input vertex attribute
layout (location = 0) in vec4 offset;
void main(void)
{
const vec4 vertices[3] = vec4[3](vec4( 0.25, -0.25, 0.5, 1.0),
vec4(-0.25, -0.25, 0.5, 1.0),
vec4( 0.25, 0.25, 0.5, 1.0));
// Add "offset" to our hard-coded vertex position
gl_Position = vertices[gl_VertexID] + offset;
}
And here is my (failed) attempt at assigning a value to that shader.
FloatBuffer attrib = BufferUtils.createFloatBuffer(4);
float[] move = new float[] { //
(float) Math.sin(getCurrentTime()) * 0.5f, //
(float) Math.cos(getCurrentTime()) * 0.6f, 0.0f,//
0.0f };
attrib.put(move);
attrib.flip();
GameUtils.exitOnGLError("set vertex");
// Update the value of input attribute 0
System.out.println(attrib.get(0));
GL20.glVertexAttrib4f(0, attrib.get(0) * 100, attrib.get(1), 0.0f, 0.0f);
GameUtils.exitOnGLError("set shader variable");
// Draw triangle
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
Here is the code to the whole object.
http://pastebin.java-gaming.org/360f7340b97