Reputation: 123
Upon execution, the background should be rendered as a darker-blue, but I have clearly missed something. The window is instead rendered with a background that is identical to the image immediately behind it (e.g. other open windows or the desktop, etc.). I cannot identify the problem.
Currently I am not using any -std
during compilation and I am utilizing the following linkages with the output executable:
-lGL -lGLU -lGLEW -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi -ldl -lXcursor -lXinerama
Here are the contents of my .cpp file:
#include <stdio.h>
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
#include <glm/glm.hpp>
using namespace glm;
int main( void )
{
//Initialize GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failes to intialize GLFW\n" );
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Open a Window and create it's OpenGL context
window = glfwCreateWindow( 1024, 768, "playground", NULL, NULL);
if( window == NULL) {
fprintf( stderr, "Failed to open GLFW window.\n" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
// Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
do{
glfwSwapBuffers(window);
glfwPollEvents();
}
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
glfwTerminate();
return 0;
}
I am an OpenGL newcomer. Feel free to remark on the over-all structure or if anything should/must be rewritten entirely. Thanks!
Upvotes: 1
Views: 417
Reputation: 5917
You just forgot to clear your window in your render loop:
do{
glClear(GL_COLOR_BUFFER_BIT); // Clear background with clear color.
glfwSwapBuffers(window);
glfwPollEvents();
}
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
glClear is often one of the first call of every render loop using OpenGL, giving you a new fresh frame to work on.
Upvotes: 4