Hi,
So I've restructured my program to have the OpenGL and SFML share the same window, but I'm having trouble getting the GUI to display. I am using a different method than that shown in the OpenGL sample project in the SDK, so I wonder if there is something I am forgetting to do. My GUI will show up until I initialize my VBO (even if I don't render it), and then I can't isolate where things are going on. Just to clarify - my OpenGL cube is appearing properly, but any 2D elements fail to appear.
I am still fairly new to OpenGL, so I'm afraid that I may just be missing something small.
void CreateVBO()
{
OpenGLObject new_obj;
Vertices = &(new_obj.aux_vertices[0]);
Indices = &(new_obj.aux_indices[0]);
//Create a VAO and make it active
glGenVertexArrays(1, &VaoId);
glBindVertexArray(VaoId);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
GLenum ErrorCheckValue = glGetError();
const size_t BufferSize = (sizeof(*Vertices))*new_obj.aux_vertices.size();
const size_t VertexSize = sizeof(*Vertices);
fprintf(stderr, "Full vertex size: %d\n",sizeof(*Vertices));
const size_t RGBOffset = sizeof((*Vertices).XYZW);
fprintf(stderr, "RGB offset: %d\n",sizeof((*Vertices).XYZW));
glGenBuffers(1, &BufferId);
glBindBuffer(GL_ARRAY_BUFFER, BufferId);
glBufferData(GL_ARRAY_BUFFER, BufferSize, Vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, VertexSize, (GLvoid *)0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, VertexSize, (GLvoid*)RGBOffset);
//Create buffers for vertex indices.
glGenBuffers(1, &IndexBufferId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBufferId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(*Indices)*new_obj.aux_indices.size(), Indices, GL_STATIC_DRAW);
}
void Initialize(sf::RenderWindow &window) {
glEnable(GL_DEPTH_TEST);
OnGLError("Depth test");
glDepthMask(GL_TRUE);
CreateShaders();
CreateVBO();
}
void RenderFunction(sf::RenderWindow &window){
window.SetActive();
glDisable(GL_COLOR_ARRAY);
glDisable(GL_TEXTURE_COORD_ARRAY);
glUseProgram(ProgramId);
OnGLError("DRAW_ERROR: Could not use the shader program");
glClear(/*GL_COLOR_BUFFER_BIT | */GL_DEPTH_BUFFER_BIT);
glUniformMatrix4fv(ModelMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ModelMatrix));
glUniformMatrix4fv(ViewMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ViewMatrix));
glUniformMatrix4fv(ProjectionMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ProjectionMatrix));
OnGLError("ERROR: Could not set the shader uniforms");
glBindVertexArray(VaoId);
OnGLError("ERROR: Could not bind the VAO for drawing purposes");
glDrawElements(GL_TRIANGLES, 10000, GL_UNSIGNED_INT, (GLvoid*)0);
OnGLError("ERROR: Could not draw the cube");
}
int main(){
// Create main window
sf::RenderWindow window(sf::VideoMode(800, 600), "Sculptor");
window.EnableVerticalSync(true);
window.SetActive();
...
Initialize(window);
sf::Clock clock;
// start game loop
while(window.IsOpen()){
...
//display rendered frame on screen
RenderFunction(window);
window.PushGLStates();
//this does not show up
sf::Text text("testing");
window.Draw(text);
window.PopGLStates();
//display rendered frame on screen
window.Display();
}
...
}