setup: switched from glut to glfw as windowing backend
This commit is contained in:
52
main.cpp
52
main.cpp
@@ -1,5 +1,5 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GL/freeglut.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstdio>
|
||||
|
||||
void display() {
|
||||
@@ -20,20 +20,54 @@ void display() {
|
||||
glViewport(0, 0, width, height);
|
||||
}*/
|
||||
|
||||
void processInput(GLFWwindow *window)
|
||||
{
|
||||
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
|
||||
glutInitWindowSize(800, 600);
|
||||
glutCreateWindow("OpenGL Example");
|
||||
|
||||
GLFWwindow* window;
|
||||
|
||||
if (!glfwInit())
|
||||
return -1;
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
|
||||
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
GLenum err = glewInit();
|
||||
if (GLEW_OK != err) {
|
||||
fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
glViewport(0, 0, 800, 600);
|
||||
//glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glutDisplayFunc(display);
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
processInput(window);
|
||||
/* Render here */
|
||||
|
||||
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
||||
/* Poll for and process events */
|
||||
glfwPollEvents();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user