Advertisement
madras

Untitled

Feb 18th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <GLFW/glfw3.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. static void error_callback(int error, const char* description)
  6. {
  7.     fputs(description, stderr);
  8. }
  9. static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
  10. {
  11.     if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  12.         glfwSetWindowShouldClose(window, GL_TRUE);
  13. }
  14. int main(void)
  15. {
  16.     GLFWwindow* window;
  17.     glfwSetErrorCallback(error_callback);
  18.     if (!glfwInit())
  19.         exit(EXIT_FAILURE);
  20.     window = glfwCreateWindow(640, 480, "Okno test", NULL, NULL);
  21.     if (!window)
  22.     {
  23.         glfwTerminate();
  24.         exit(EXIT_FAILURE);
  25.     }
  26.     glfwMakeContextCurrent(window);
  27.     glfwSetKeyCallback(window, key_callback);
  28.     while (!glfwWindowShouldClose(window))
  29.     {
  30.         float ratio;
  31.         int width, height;
  32.         glfwGetFramebufferSize(window, &width, &height);
  33.         ratio = width / (float) height;
  34.         glViewport(0, 0, width, height);
  35.         glClear(GL_COLOR_BUFFER_BIT);
  36.         glMatrixMode(GL_PROJECTION);
  37.         glLoadIdentity();
  38.         glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
  39.         glMatrixMode(GL_MODELVIEW);
  40.         glLoadIdentity();
  41. //      glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
  42.  
  43.         glBegin(GL_POLYGON);
  44.  
  45.         glColor3f(1.f, 0.f, 0.f);
  46.         glVertex3f(-1.2f, -0.4f, 0.f);
  47.         glColor3f(0.f, 1.f, 0.f);
  48.         glVertex3f(0.6f, -0.4f, 0.f);
  49.         glColor3f(0.f, 0.f, 1.f);
  50.         glVertex3f(0.f, 0.6f, 0.f);
  51.  
  52.         glColor3f(1.f, 1.f, 1.f);
  53.         glVertex3f(0.0f, 0.0f, 0.0f);
  54.  
  55.         glEnd();
  56.         glfwSwapBuffers(window);
  57.         glfwPollEvents();
  58.     }
  59.     glfwDestroyWindow(window);
  60.     glfwTerminate();
  61.     exit(EXIT_SUCCESS);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement