I'm gonna cut straight to the chase; I'm writing in c++ and I'm using glew (openGL). A recurring problem however is that when I first open the window and clear it, the 'glClear' doesn't fill the window with white as expected. It starts with an offset from the top left corner. This offset happens to be the exact same offset as the distance between my window and the top left corner of my screen so I suspect something funky about that. However, I haven't found anything online about it for 3 hours, so I decided to ask the question myself. Attached is the code and a screenshot of the problem. Screen capture of the window here, the red lines are the same length and added after the screenshot.
#define GLEW_STATIC
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main(int argc, char **argv){
if(!glfwInit()) std::cout << "glfw failed to init" << std::endl;
window = glfwCreateWindow(400, 400, "firstWindow", NULL, NULL);
if(!window) std::cout << "window creation failed" << std::endl;
while (!glfwWindowShouldClose(window)){
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwMakeContextCurrent(window);
}
UPDATE:
I'm really new to the whole GL thing, I was told that glfwMakeContextCurrent should be called straight after glfwWindowCreate. Once i did this, the whole thing became less wrong. I now get a grey (NOT a white) background, partly atleast. However the problem persists. I cleared glew from the code since it wasn't used.
#include <iostream>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main(int argc, char **argv){
if(!glfwInit()) std::cout << "glfw failed to init" << std::endl;
window = glfwCreateWindow(400, 400, "firstWindow", NULL, NULL);
if(!window) std::cout << "window creation failed" << std::endl;
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)){
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
}