I'm just trying to draw a line between the bottom left corner and the top right corner of the screen. The result is quite annoying since it renders a line that goes from the bottom left corner to the middle point of the screen... However if I move the window position with the mouse, it suddenly changes and renders properly! What is happening and how can I solve this?
I'm running the code on a macOS system and it's being builded using Xcode.
Before moving the window:
After moving the window:
This is the code:
#include <GLFW/glfw3.h>
#define SCREEN_W 640
#define SCREEN_H 480
int main(int argc, char * argv[]) {
glfwInit();
GLFWwindow* window = glfwCreateWindow(SCREEN_W, SCREEN_H, "GLFW Window", NULL, NULL);
glfwMakeContextCurrent(window);
float lineVertices[] = {
0, 0, 0,
SCREEN_W, SCREEN_H, 0
};
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0.0f, 0.0f, SCREEN_W, SCREEN_H);
glOrtho(0, SCREEN_W, 0, SCREEN_H, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, lineVertices);
glDrawArrays(GL_LINES, 0, 2);
glDisableClientState(GL_VERTEX_ARRAY);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}

