As the title says…. :( nothing is drawn on screen… is there something I'm missing?
Mesh *Mesh_Create(GLfloat vertices[], GLuint indices[], GLfloat uvs[], GLfloat colors[])
{
Mesh *mesh = (Mesh*)malloc(sizeof(Mesh));
mesh->vertices = (GLfloat*)malloc(sizeof(vertices));
memcpy(mesh->vertices, vertices, sizeof(vertices));
mesh->indices = (GLuint*)malloc(sizeof(indices));
memcpy(mesh->indices, indices, sizeof(indices));
mesh->elementCount = sizeof(indices) / sizeof(GLuint);
glGenVertexArrays(1, &mesh->vao);
glBindVertexArray(mesh->vao);
glGenBuffers(1, &mesh->vbo[VERTEXBUFFER]);
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo[VERTEXBUFFER]);
glBufferData(GL_ARRAY_BUFFER, sizeof(mesh->vertices), &mesh->vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(0);
/*glGenBuffers(1, &mesh->vbo[TEXTUREBUFFER]);
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo[TEXTUREBUFFER]);
glBufferData(GL_ARRAY_BUFFER, sizeof(uvs), uvs, GL_STATIC_DRAW);
glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(1);
*/
glGenBuffers(1, &mesh->vbo[INDICESBUFFER]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->vbo[INDICESBUFFER]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(mesh->indices), &mesh->indices, GL_STATIC_DRAW);
/*glGenBuffers(1, &mesh->vbo[COLORBUFFER]);
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo[COLORBUFFER]);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
glVertexAttribPointer(3, 4, GL_FLOAT, false, 4 * sizeof(GLfloat), NULL);
glEnableVertexAttribArray(3);*/
/*glBindVertexArray(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);*/
return mesh;
}
Mesh *Mesh_CreateQuad()
{
GLfloat vertices[] = { -0.5, -0.5,
0.5, -0.5,
0.5, 0.5,
-0.5, 0.5 };
GLuint indices[] = { 0,1,2,
0,2,3 };
GLfloat uvs[] = { 0 , 1,
1, 1,
1, 0,
0, 0 };
GLfloat colors[] = { 1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1 };
return Mesh_Create(vertices, indices, uvs, colors);
}
void Mesh_Render(Mesh *mesh)
{
glBindVertexArray(mesh->vao);
glDrawElements(GL_TRIANGLES, mesh->elementCount, GL_UNSIGNED_INT, &mesh->indices);
}
glGetError()
or to use tools likeRenderDoc
. \$\endgroup\$ – user115399 Nov 30 '18 at 10:40