With the following strcuture in the logic:
- Generate VAO and bind it
- Generate Buffer and bind it
- Fill data into buffer
- Create and use program (the shader)
- DrawArrays.
I can draw as spected, but, if add a 3.5 point, between 3 and 4, using glClearBufferSubData, the program dont draw anymore.
I tried other approach like call glClearBufferSubData in random moment (when I press one key of the keyboard) and the program neither doesn not work.
glClearBufferSubData function itself works as I spected I think, when I call glGetBufferSubData the data received is the spected and OpenGL don’t throw any error with glGetError().:
The static global declarations are:
static GLfloat vertices_pos1[] = {
1.0f,-1.0f,0.0f ,
-1.0f,-1.0f,0.0f ,
0.0f,1.0f,0.0f
};
static GLfloat vertices_pos2[] = {
-0.5f, -0.5f, 0.0f, // left
0.5f, -0.5f, 0.0f, // right
0.0f, 0.5f, 0.0f // top
};
static const char* vertexSource =
"#version 430 core\n"
"layout (location = 0) in vec3 pos;\n"
"void main() {\n"
" gl_Position = vec4(pos, 1.0);\n"
"}\n";
static const char* fragmentSource =
"#version 430 core\n"
"out vec4 outColor;\n"
"void main() {\n"
" outColor = vec4(1.0, 0.0, 0.0, 1.0);"
"}\n";
In the startup stage I do:
glClearColor(0.0f, 0.1f, 0.2f, 0.0);
program = shader::createPorgramFromString(vertexSource, fragmentSource);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*9, vertices_pos1, GL_STATIC_DRAW);
glClearBufferSubData(GL_ARRAY_BUFFER, GL_RGB32F, 0, sizeof(vertices_pos2), GL_RGB, GL_FLOAT, vertices_pos2);
float o[9];
glGetBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices_pos1), o);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, 0);
glEnableVertexAttribArray(0);
glUseProgram(program);
And in the render stage I do:
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
The lines glClearBufferSubData and glGetBufferSubdata said me that the new data is correct, but OpenGL doesn’t draw anything.
If I resend the same data (put again vertices_pos1 instead vertices_pos2) the program neither doesn’t work.
The only way to get the triangle is comment the line glClearBufferSubData.
Anybody can light me a little in this? Thanks