diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..349855f --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +g++ main.cpp -lGL -lglfw -lGLEW diff --git a/main.cpp b/main.cpp index 93531af..f0f299b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include 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(); } +