source: opengl-game/game01.cpp@ 669c4e6

feature/imgui-sdl points-test
Last change on this file since 669c4e6 was 8a6d19d, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 7 years ago

Implement movement in a basic 3D scene and add some examples from the new OpenGL tutorials site

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[8a6d19d]1// Include standard headers
2#include <stdio.h>
3#include <stdlib.h>
4#include <iostream>
5
6// Include GLEW
7#include <GL/glew.h>
8
9// Include GLFW
10#include <GLFW/glfw3.h>
11GLFWwindow* window;
12
13// Include GLM
14#include <glm/glm.hpp>
15#include <glm/gtc/matrix_transform.hpp>
16using namespace glm;
17
18#include "common/controls.hpp"
19
20using namespace std;
21
22void framebuffer_size_callback(GLFWwindow* window, int width, int height);
23void processInput(GLFWwindow *window);
24
25// settings
26const unsigned int SCR_WIDTH = 800;
27const unsigned int SCR_HEIGHT = 600;
28
29int main()
30{
31 // glfw: initialize and configure
32 // ------------------------------
33 glfwInit();
34 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
35 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
36 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
37 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // uncomment this statement to fix compilation on OS X
38
39 // glfw window creation
40 // --------------------
41 GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
42 if (window == NULL)
43 {
44 cout << "Failed to create GLFW window" << endl;
45 glfwTerminate();
46 return -1;
47 }
48 glfwMakeContextCurrent(window);
49 glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
50
51 // Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
52 glewExperimental = GL_TRUE;
53 // Initialize GLEW to setup the OpenGL Function pointers
54 if (glewInit() != GLEW_OK) {
55 cout << "Failed to initialize GLEW" << endl;
56 return EXIT_FAILURE;
57 }
58
59 // render loop
60 // -----------
61 while (!glfwWindowShouldClose(window))
62 {
63 // input
64 // -----
65 processInput(window);
66
67 glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
68 glClear(GL_COLOR_BUFFER_BIT);
69
70 // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
71 // -------------------------------------------------------------------------------
72 glfwSwapBuffers(window);
73 glfwPollEvents();
74 }
75
76 // glfw: terminate, clearing all previously allocated GLFW resources.
77 // ------------------------------------------------------------------
78 glfwTerminate();
79 return 0;
80}
81
82// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
83// ---------------------------------------------------------------------------------------------------------
84void processInput(GLFWwindow *window)
85{
86 if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
87 glfwSetWindowShouldClose(window, true);
88}
89
90// glfw: whenever the window size changed (by OS or user resize) this callback function executes
91// ---------------------------------------------------------------------------------------------
92void framebuffer_size_callback(GLFWwindow* window, int width, int height)
93{
94 // make sure the viewport matches the new window dimensions; note that width and
95 // height will be significantly larger than specified on retina displays.
96 glViewport(0, 0, width, height);
97}
Note: See TracBrowser for help on using the repository browser.