#49 - Simple GL window with GLFW & GLEW
Data: 2019-02-23 12:00 - C++
Simple snippet for basic window with GLFW and GLEW to use OpenGL.
#include <GL\glew.h>
#include <GLFW\glfw3.h>
#pragma comment(lib, "glew32.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glfw3.lib")
int main() {
GLFWwindow* window;
if (!glfwInit())
return -1;
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
glfwTerminate();
return -1;
}
glGetError(); // discard an error
glClearColor(1.0f, 0.5f, 0.0f, 0.0f);
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
}