Hello. I am currently executing a simple OGL program. The only thing it should output is a simple triangle over the background. However, only the background is renderer, no triangle shows up. I checked it many times and cannot find the cause.
Some possibly relevant code:
glClearColor (0.0f,0.66f,1.0f,1.0f);
GLuint programID = loadShaders ("/media/34GB/demos/Ogl/SimpleVertexShader.vs","/media/34GB/demos/Ogl/SimpleFragmentShader.fs");
GLuint vertex_pos_modelspace_id = glGetAttribLocation(programID, "vertexPosition_modelspace");
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
//static const GLushort g_element_nuffer_data [] = {0, 1, 2};
GLuint vertex_buffer;
glGenBuffers (1, &vertex_buffer);
glBindBuffer (GL_ARRAY_BUFFER, vertex_buffer);
glBufferData (GL_ARRAY_BUFFER, sizeof (g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
do {
display (programID,0,vertex_pos_modelspace_id,vertex_buffer);
running = glfwGetWindowParam (GLFW_OPENED);
} while (running);
void display (GLuint matrix_id, GLuint programID, GLuint vertex_pos_modelspace_id, GLuint vertex_buffer/*GLfloat * model_view_projection_mat_row1_x*/) {
glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glUseProgram (programID);
glEnableVertexAttribArray (vertex_pos_modelspace_id);
glBindBuffer (GL_ARRAY_BUFFER, vertex_buffer);
glVertexAttribPointer(
vertex_pos_modelspace_id, // The attribute we want to configure
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
glDrawArrays(GL_TRIANGLES, 0, 3); // 3 indices starting at 0 -> 1 triangle
glDisableVertexAttribArray(vertex_pos_modelspace_id);
glfwSwapBuffers();
}
#version 120
attribute vec3 vertexPosition_modelspace;
//uniform mat4 MVP;
void main(){
gl_Position = vec4(vertex_position_modelspace, 1.0);
}
#version 120
void main()
{
// Output color = red
gl_FragColor = vec4(1,0,0,1);
}