Reputation: 23
So I asked my professor to look at this already and he doesn't know why it doesn't work. I am currently working from my laptop, which is having the issue. I also tried running my program on a lab computer and it fully worked as intended. I recently updated all of my graphics stuff. Here is my code below:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <FreeImage.h>
int main()
{
if (glfwInit() == GL_FALSE)
return -1;
GLFWwindow* GLFWwindowPtr = glfwCreateWindow(800, 600, "Name Name DSA1 Engine", NULL, NULL);
if (GLFWwindowPtr != nullptr)
glfwMakeContextCurrent(GLFWwindowPtr);
else
{
glfwTerminate();
return -1;
}
if (glewInit() != GLEW_OK)
{
glfwTerminate();
return -1;
}
while (!glfwWindowShouldClose(GLFWwindowPtr))
{
glfwPollEvents();
}
glfwTerminate();
return 0;
}
All I am trying to do is make a blank window appear on my screen with openGL. It all runs fine and dandy, but when a window is drawn to my screen it copies whatever was behind it instead of being a blank white screen. The most perplexing bit about this is that my professor has the same code on his laptop and it works fine, and it works for me when I run it on a lab machine.
I initially thought it was something in my graphics drivers and such so I updated those but it still doesn't work. I have provided some of my system specs just in case that might help.
Manufacturer MSI_NB
Model GT70 2OC/2OD
Total amount of system memory 32.0 GB RAM
System type 64-bit operating system
Number of processor cores 4
Display adapter type NVIDIA GeForce GTX 770M
Total available graphics memory 1824 MB
Dedicated graphics memory 192 MB
Dedicated system memory 0 MB
Shared system memory 1632 MB
Display adapter driver version 10.18.13.6200
Primary monitor resolution 1920x1080
DirectX version DirectX 10
I know this isn't really a code related question, but I would really appreciate anyone who can help me with this issue. If I need to provide any additional information I am more than happy to provide it!
Upvotes: 0
Views: 687
Reputation: 11706
The issue is that you never clear the screen or call glfwSwapBuffers
.
When the window first appears, its client area is invalidated which means it needs to be redrawn. GLFW doesn't clear the screen automatically because it would just be overwritten with your graphics scene (so the extra clear would be redundant). But since you don't draw anything, you're left with the equivalent of uninitialized data. Whether or not you get a blank screen or copies of windows behind it is configuration-dependent.
To fix this, you need to register a window refresh callback via glfwSetWindowRefreshCallback
that does your rendering (in this case, just call glClear(GL_COLOR_BUFFER);
) and calls glfwSwapBuffers
.
Upvotes: 2