Figured while I wait for a response I’d try implement uniforms (which thanks to the wiki you directed me to has made clear that uniforms are constants, and from compile errors I found out the vertex data is constant too) as structs, that failed somewhere along the line but I still have the triangle, just no movement, (partly because I forgot to update the key callback function to update the objects their using and partly because I’ve obviously got some code wrong somewhere).
Here’s the code I used for the crafter/shader
#version 330
in vec3 vPoint;
in vec3 vColor;
struct object
{
int rx, ry;
int cx, cy, cz;
float x, y, z;
};
uniform object uChar0;
uniform object uView0;
varying vec4 color;
void main()
{
float x = vPoint.x + uChar0.x;
float y = vPoint.y + uChar0.y;
float z = vPoint.z + uChar0.z;
gl_Position = vec4(x, y, z, 1.0);
color = vec4(vColor,1.0);
}
Here’s the code I used for updating uniforms
void init_vao
(
struct _VAO *vao
)
{
glExec( NULL, glGenVertexArrays( 1, &(vao->self_id) ) );
glExec( NULL, glGenBuffers( 1, &(vao->buff_id) ) );
glExec( NULL, glBindVertexArray( vao->self_id ) );
glExec( NULL, glBindBuffer( GL_ARRAY_BUFFER, vao->buff_id ) );
glExec
(
NULL
, glBufferData
(
GL_ARRAY_BUFFER
, sizeof(TRIANGLE)
, vao->buff
, GL_STATIC_DRAW
)
);
//glVertexAttribDivisor( vao->self_id, sizeof(TRIANGLE) / sizeof(VERTEX) );
glExec( NULL, glEnableVertexAttribArray( app.vPoint_location ) );
glExec( NULL, glVertexAttribPointer
(
app.vPoint_location, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
sizeof(VERTEX), // stride
(void*)offsetof(VERTEX,vPoint) // array buffer offset
) );
glExec( NULL, glEnableVertexAttribArray( app.vColor_location ) );
glExec( NULL, glVertexAttribPointer
(
app.vColor_location, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
sizeof(VERTEX), // stride
(void*)offsetof(VERTEX,vColor) // array buffer offset
) );
glUniform2i( app.uChar0_location + 0, app.char0.rx, app.char0.ry );
glUniform3i( app.uChar0_location + 2, app.char0.cx, app.char0.cy, app.char0.cz );
glUniform3f( app.uChar0_location + 5, app.char0.cx, app.char0.cy, app.char0.cz );
glUniform2i( app.uView0_location + 0, app.view0.rx, app.view0.ry );
glUniform3i( app.uView0_location + 2, app.view0.cx, app.view0.cy, app.view0.cz );
glUniform3f( app.uView0_location + 5, app.view0.cx, app.view0.cy, app.view0.cz );
glBindVertexArray(0);
}
vao_null.buff = &null_triangle;
vao_user.buff = &user_triangle;
init_vao( &vao_null );
init_vao( &vao_user );
void draw_vao( struct _VAO *vao )
{
//glExec( NULL, glEnableVertexAttribArray( vao->self_id ) );
glExec( NULL, glBindVertexArray( vao->self_id ) );
glUniform2i( app.uChar0_location + 0, app.char0.rx, app.char0.ry );
glUniform3i( app.uChar0_location + 2, app.char0.cx, app.char0.cy, app.char0.cz );
glUniform3f( app.uChar0_location + 5, app.char0.cx, app.char0.cy, app.char0.cz );
glUniform2i( app.uView0_location + 0, app.view0.rx, app.view0.ry );
glUniform3i( app.uView0_location + 2, app.view0.cx, app.view0.cy, app.view0.cz );
glUniform3f( app.uView0_location + 5, app.view0.cx, app.view0.cy, app.view0.cz );
//glVertexAttrib3fv( vao->self_id, (float*)(&user_triangle) );
glExec( NULL, glDrawArrays( GL_TRIANGLES, 0, 3 ) );
glExec( NULL, glBindVertexArray( vao_null.self_id ) );
//glExec( NULL, glDisableVertexAttribArray( vao->self_id ) );
}
Edit: Just realised I didn’t post the error:
[OPENGL ERROR 0x824C (33356 - 1)] source 33350, gravity, 37190:
GL_INVALID_OPERATION in glUniform(program not linked)
...
[OPENGL ERROR 0x824C (33356 - 1)] source 33350, gravity, 37190:
GL_INVALID_OPERATION in glUniform3("uChar0.ry"@1 has 1 components, not 3)
[OPENGL ERROR 0x824C (33356 - 1)] source 33350, gravity, 37190:
GL_INVALID_OPERATION in glUniform3("uChar0.cz"@4 has 1 components, not 3)
[OPENGL ERROR 0x824C (33356 - 1)] source 33350, gravity, 37190:
...
Edit 2: Looking through the output turned out there was more than one error, updated the above to reflect all the ones I found
Edit 3: Resolved the uniform problem with this:
void update_object( uint loc, object *obj )
{
glUniform1i( loc + 1, obj->rx );
glUniform1i( loc + 2, obj->ry );
glUniform1i( loc + 3, obj->cx );
glUniform1i( loc + 4, obj->cy );
glUniform1i( loc + 5, obj->cz );
glUniform1f( loc + 6, obj->x );
glUniform1f( loc + 7, obj->y );
glUniform1f( loc + 8, obj->z );
}
Haven’t resolved the “program not linked” yet, gotta go to that interview in a few minutes so I’ll try debugging the linkage after I come back, I never expected it to have issues when the crafters compiled fine.