Done with segfault checking, now I’m having trouble getting my triangles to draw, atm I can only verify that the values in the CPU side vertex array are being filled correctly, I know I’m overlooking something but I just don’t know what. here’s the output of checking the vertex contents:
./d.out
[OPENGL ERROR 0x8251 (33361)] GL_DEBUG_TYPE_OTHER hunt empty_model from GL_DEBUG_SOURCE_SHADER_COMPILER, weight GL_DEBUG_SEVERITY_NOTIFICATION:
Shader Stats: SGPRS: 8 VGPRS: 28 Code Size: 32 LDS: 0 Scratch: 0 Max Waves: 8 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
[OPENGL ERROR 0x8251 (33361)] GL_DEBUG_TYPE_OTHER hunt empty_model from GL_DEBUG_SOURCE_SHADER_COMPILER, weight GL_DEBUG_SEVERITY_NOTIFICATION:
Shader Stats: SGPRS: 16 VGPRS: 8 Code Size: 64 LDS: 0 Scratch: 0 Max Waves: 8 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
Memory leak in crafters list!
main.c:143: desc = char0_model, rot = { 0, 0 }
main.c:150: pos = { 0.000000, 0.000000, 0.000000 }, dye = { 0.000000, 0.000000, 0.000000 }, rot = { 1.000000, 1.000000, 0.000000 }
main.c:172: pos0 = { 0.000000, 0.500000, 0.000000 }, dye0 = { 0.500000, 0.500000, 1.000000 }
main.c:172: pos1 = { 0.250000, 0.000000, 0.000000 }, dye1 = { 0.500000, 1.000000, 1.000000 }
main.c:172: pos2 = { 0.750000, 0.000000, 0.000000 }, dye2 = { 1.000000, 1.000000, 1.000000 }
main.c:143: desc = view0_model, rot = { 0, 0 }
main.c:150: pos = { 0.000000, 0.000000, 0.000000 }, dye = { 0.000000, 0.000000, 0.000000 }, rot = { 1.000000, 1.000000, 0.000000 }
main.c:172: pos0 = { 0.000000, 0.000000, 0.000000 }, dye0 = { 0.000000, 0.000000, 0.000000 }
main.c:172: pos1 = { 0.000000, 0.000000, 0.000000 }, dye1 = { 0.000000, 0.000000, 0.000000 }
main.c:172: pos2 = { 0.000000, 0.000000, 0.000000 }, dye2 = { 0.000000, 0.000000, 0.000000 }
main.c:143: desc = char1_model, rot = { 0, 0 }
main.c:150: pos = { 0.000000, 0.000000, 0.000000 }, dye = { 0.000000, 0.000000, 0.000000 }, rot = { 1.000000, 1.000000, 0.000000 }
main.c:172: pos0 = { 0.000000, 0.500000, 0.000000 }, dye0 = { 0.500000, 1.000000, 0.500000 }
main.c:172: pos1 = { 0.250000, 1.000000, 0.000000 }, dye1 = { 0.500000, 1.000000, 1.000000 }
main.c:172: pos2 = { 0.750000, 1.000000, 0.000000 }, dye2 = { 1.000000, 1.000000, 1.000000 }
main.c:143: desc = char0_model, rot = { 0, 0 }
main.c:150: pos = { 0.000000, 0.000000, 0.000000 }, dye = { 0.000000, 0.000000, 0.000000 }, rot = { 1.000000, 1.000000, 0.000000 }
main.c:172: pos0 = { 0.000000, 0.500000, 0.000000 }, dye0 = { 0.500000, 0.500000, 1.000000 }
main.c:172: pos1 = { 0.250000, 0.000000, 0.000000 }, dye1 = { 0.500000, 1.000000, 1.000000 }
main.c:172: pos2 = { 0.750000, 0.000000, 0.000000 }, dye2 = { 1.000000, 1.000000, 1.000000 }
And here’s the function that deals with everything after the crafters/shaders have been compiled, linked, buffer IDs generated and variable locations from them retrieved
int draw_opengl()
{
CRAFTER *program = app.crafters->addr
, *builder = program + 1
, *painter = program + 2;
MODEL
*models = app.models->addr,
*empty_model = models
, *char0_model = empty_model + 1
, *view0_model = char0_model + 1
, *char1_model = view0_model + 1
;
JOINT
*empty_joint = nth_joint( empty_model, 1 )
, *char0_joint = nth_joint( char0_model, 1 )
, *view0_joint = nth_joint( view0_model, 1 )
, *char1_joint = nth_joint( char1_model, 1 )
;
ALTER
*empty_triad = empty_joint->points->addr
, *char0_triad = char0_joint->points->addr
, *view0_triad = view0_joint->points->addr
, *char1_triad = char1_joint->points->addr;
empty_model->desc = "empty_model";
char0_model->desc = "char0_model";
view0_model->desc = "view0_model";
char1_model->desc = "char1_model";
empty_joint->desc = "empty_joint";
char0_joint->desc = "char0_joint";
view0_joint->desc = "view0_joint";
char1_joint->desc = "char1_joint";
memcpy( empty_triad, &empty_triangle, sizeof(empty_triangle) );
memcpy( char0_triad, &char0_triangle, sizeof(char0_triangle) );
memcpy( char1_triad, &char1_triangle, sizeof(char1_triangle) );
void update_altered( uint loc, ALTER *o )
{
if ( loc < (uint)-1 )
{
uint off = 1;
glExec( NULL, glUniform3fv( loc + off + 0, 1, o->pos ) );
glExec( NULL, glUniform3fv( loc + off + 1, 1, o->dye ) );
glExec( NULL, glUniform3fv( loc + off + 2, 1, o->rot ) );
}
}
void init_model( MODEL *model )
{
JOINT *joints = model->joints->addr, *joint = joints + 1;
glExec( NULL, glBindVertexArray( model->id ) );
glExec( NULL, glBindBuffer( GL_ARRAY_BUFFER, joint->id ) );
glExec
(
NULL
, glBufferData
(
GL_ARRAY_BUFFER
, sizeof(ALTER)
, joints->points->addr
, GL_STATIC_DRAW
)
);
//glVertexAttribDivisor( model->self_id, sizeof(TRIANGLE) / sizeof(VERTEX) );
glExec( NULL, glEnableVertexAttribArray( app.loc_point ) );
glExec( NULL, glVertexAttribPointer
(
app.loc_point, // location
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
sizeof(ALTER), // stride
(void*)offsetof(ALTER,pos) // vertex offset
) );
glExec( NULL, glEnableVertexAttribArray( app.loc_color ) );
glExec( NULL, glVertexAttribPointer
(
app.loc_color, // location
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
sizeof(ALTER), // stride
(void*)offsetof(ALTER,dye) // vertex offset
) );
glBindVertexArray(0);
}
glExec( NULL, glUseProgram( program->id ) );
init_model( empty_model );
init_model( char0_model );
init_model( char1_model );
fill_model( char0_model, 0, 0, 0, 0, 0, char0_triad );
fill_model( view0_model, 0, 0, 0, 0, 0, view0_triad );
fill_model( char1_model, 0, 0, 0, 0, 0, char1_triad );
update_altered( app.loc_model, &(char0_model->mod) );
update_altered( app.loc_joint, &(char0_joint->mod) );
void draw_model( MODEL *model )
{
LIST *list = model->joints;
JOINT *joints = list->addr, *joint;
//glExec( NULL, glEnableVertexAttribArray( model->self_id ) );
glExec( NULL, glBindVertexArray( model->id ) );
update_altered( app.loc_model, &(model->mod) );
for ( INDEX n = 1; n < list->used; ++n )
{
joint = joints + n;
update_altered( app.loc_joint, &(joint->mod) );
glExec( NULL, glDrawArrays( GL_TRIANGLES, 0, 3 ) );
}
//glVertexAttrib3fv( model->self_id, (float*)(&user_trirot) );
glExec( NULL, glBindVertexArray( empty_model->id ) );
//glExec( NULL, glDisableVertexAttribArray( model->self_id ) );
}
while ( !glfwWindowShouldClose( app.window ) )
{
float ratio = (float)(app.span[VEC_X]) / (float)(app.span[VEC_Y]);
FMAT4X4 m = {0}, p = {0}, mvp = {0};
app.frame = glfwGetTime();
app.deltaFrame = app.frame - app.lastFrame;
app.lastFrame = app.frame;
/* Make sure GFX card or GPU knows which of it's programs it's using */
glExec( NULL, glUseProgram( program->id ) );
/* Clear the screen */
glExec( NULL, glViewport( 0, 0, app.span[VEC_X], app.span[VEC_Y] ) );
glExec( NULL, glClearColor( 0, 0, 0, 0 ) );
glExec( NULL, glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) );
#ifdef USE_MATRIX
fmat4x4_identify( m );
fmat4x4_rotate_Z( m, m, app.frame );
fmat4x4_ortho( p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f );
fmat4x4_mul( mvp, p, m );
glExec
(
NULL
, glUniformMatrix4fv
(
app.mvp_location
, 1
, GL_FALSE
, (float*)mvp
)
);
#endif
draw_model( char0_model );
/* Hand over to the GFX card or GPU */
glExec( NULL, glfwSwapBuffers( app.window ) );
/* Get any new position data before constructing the next frame */
glExec( NULL, glfwPollEvents() );
}
return 0;
}
Can anyone see what I’ve overlooked?