I suppose that this question is more related to my lack of understanding of OpenGL than anything else, but I figured I'd ask away.
So I have a program that draws some things using functions native SFML, and I am trying to draw a three dimensional shape in the same window using OpenGL.
I am able to get both APIs to render their images independently but not concurrently.
When I initialize and draw the graphics from OpenGL to the window, the entire screen appears back, and then a few lines that I defined are drawn in the lower-left corner (where I set the viewport).
My guess is that the entire OpenGL buffer is being rendered to the entire screen, as opposed to the few lines that I would like to draw, and in the process prints over the images drawn by SFML. I suspect that I need to render the buffer to only a small section of the window instead.
Let me post a couple snip-its of code that include the rendering and initialization of OpenGL and the rendering of the SFML and OpenGL graphics.
bool Simulation::Initialize()
{
// Allows us to render both SFML and OpenGL functions
MainWindow.PreserveOpenGLStates(true);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClearDepth(1.f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.f, 1.f, 1.f, 500.f);
glViewport(0, 0, MainWindow.GetWidth()/2, MainWindow.GetHeight()/2);
//more stuff
}
void Simulation::Render()
{
// These functions draw to the MainWindow using SFML
DrawVariableLabelValues();
DrawTextNames();
DrawTextCursor();
// This is function draws using OpenGL functions
DrawGraph();
// Render the graphics drawn onto the MainWindow
MainWindow.Display();
}
//Below I try to simply draw the coordinate system on which I will display a dynamics plotting system
void Simulation::DrawGraph()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -1.f);
// Draw the axes of the graph
glBegin(GL_LINES);
// x-axis
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(200.0f, 0.0f, 0.0f);
// y-axis
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 200.0f, 0.0f);
// z-axis
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 200.0f);
glEnd();
}
Another thing I would like to mention is that when I try to call glTranslate using x and y arguments other than 0, the lines that I want to draw disappear. Can anyone give me a hand here. I just starting using OpenGL for the first time today.
Lastly, do I need to call clear on the MainWindow anymore? It seems that like that clears out everything that I have told OpenGL to draw.
Thank you