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;
}
The primary purpose of GLFW is to provide a simple interface to window management and OpenGL and OpenGL ES context creation. GLFW supports multiple windows, which can be either a normal desktop window or a full screen window.
Explicit creation of OpenGL contexts of version 3.0 and above on Windows and X11, including profiles and flags, is supported by GLFW 2.7 and later.
Be sure to include GLAD before GLFW. The include file for GLAD includes the required OpenGL headers behind the scenes (like GL/gl. h ) so be sure to include GLAD before other header files that require OpenGL (like GLFW).
When the user attempts to close the window, for example by clicking the close widget or using a key chord like Alt+F4, the close flag of the window is set.
Probably this is not related to the initial issue of this question since it was published 1.5 years ago but if you face this on Mac OS X Mojave then there is an issue opened on GLFW GitHub: https://github.com/glfw/glfw/issues/1334
You can check temporary workarounds there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With