Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1.  
  2. #include <GLFW/glfw3.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. static void keyCallback(GLFWwindow* win, int key, int scancode, int action, int mode) {
  7.  
  8.     switch(action) {
  9.         case GLFW_RELEASE:
  10.             printf("Released %c\n", key);
  11.             break;
  12.         case GLFW_PRESS:
  13.             printf("Press %c\n", key);
  14.             break;
  15.         case GLFW_REPEAT:
  16.             printf("Repeat %c\n", key);
  17.             break;
  18.         default:
  19.             exit(0);
  20.     }
  21.  
  22.     if(key == GLFW_KEY_Q && action == GLFW_PRESS)
  23.         glfwSetWindowShouldClose(win, GL_TRUE);
  24. }
  25.  
  26. int main() {
  27.  
  28.     GLFWwindow* win;
  29.  
  30.     if(!glfwInit())
  31.         return -1;
  32.  
  33.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  34.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  35.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  36.  
  37.     glfwWindowHint(GLFW_RESIZABLE, false);
  38.  
  39.     win = glfwCreateWindow(640, 480, "Bug", nullptr, nullptr);
  40.  
  41.     if(!win) {
  42.         glfwTerminate();
  43.         return -1;
  44.     }
  45.  
  46.     glfwMakeContextCurrent(win);
  47.  
  48.     glfwSetKeyCallback(win, keyCallback);
  49.  
  50.     /*
  51.      * if console is under GLFW window
  52.         int xposWindow, yposWindow;
  53.         glfwGetWindowPos(win, &xposWindow, &yposWindow);
  54.         glfwSetWindowPos(win, xposWindow + 0, yposWindow);
  55.     */
  56.  
  57.     while(!glfwWindowShouldClose(win)) {
  58.         glClear(GL_COLOR_BUFFER_BIT);
  59.         glClearColor(0.25f, 0.1f, 0.0f, 0.0f);
  60.  
  61.         glfwSwapBuffers(win);
  62.         glfwPollEvents();
  63.     }
  64.  
  65.     glfwTerminate();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement