SHARE
TWEET

Untitled

a guest Feb 27th, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GLFW/glfw3.h>
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. double a[] = {0., 0., 0.},
  6.         b[] = {.5, 0, 0.},
  7.         c[] = {.5, .5, 0.},
  8.         d[] = {0, .7, 0};
  9.  
  10. static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
  11. {
  12.     if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  13.         glfwSetWindowShouldClose(window, GLFW_TRUE);
  14.     if (key == GLFW_KEY_LEFT )
  15.         glRotatef(5, 0, 1, 0);
  16.     if (key == GLFW_KEY_RIGHT)
  17.         glRotatef(-5, 0, 1, 0);
  18.     if (key == GLFW_KEY_UP && action == GLFW_PRESS)
  19.         a[1] += .1;
  20.     if (key == GLFW_KEY_DOWN && action == GLFW_PRESS)
  21.         a[1] -= .1;
  22.  
  23. }
  24.  
  25. void render(GLFWwindow *window) {
  26.     int width, height;
  27.     glfwGetFramebufferSize(window, &width, &height);
  28.     glViewport(0, 0, width, height);
  29.  
  30.     glClear(GL_COLOR_BUFFER_BIT);
  31.  
  32.     glBegin(GL_POINTS);
  33.     glPointSize(3);
  34.     glColor3b(255, 0, 0);
  35.     glVertex3d(-1, 0, 0);
  36.     glVertex3d(1, 0, 0);
  37. //    glVertex3d(0, -10, 0);
  38. //    glVertex3d(0, 10, 0);
  39. //    glVertex3d(0, 0, -10);
  40. //    glVertex3d(0, 0, 10);
  41.     glEnd();
  42.  
  43.     glBegin(GL_TRIANGLES);
  44.     int dots = 100;
  45.     double pi = 3.141591;
  46.     double r = 0.5;
  47.     double x_pr = 0, y_pr = 0;
  48.     int col = 1;
  49.     for (double alph = 2 * pi / dots; alph < 2 * pi; alph += 2 * pi / dots) {
  50.         double x = r * cos(alph);
  51.         double y = r * sin(alph);
  52.         glColor3b(col, 100, 0);
  53.         col = (col + 1) % 255;
  54.         glVertex3d(x, y, 10);
  55.         glVertex3d(x_pr, y_pr, 1);
  56.         glVertex3dv(a);
  57.         x_pr = x;
  58.         y_pr = y;
  59.     }
  60.     glEnd();
  61. }
  62.  
  63. int main()
  64. {
  65.     glfwInit();
  66.     auto *window = glfwCreateWindow(500, 500, "hui",  NULL, NULL);
  67.     glfwMakeContextCurrent(window);
  68.     glfwSetKeyCallback(window, key_callback);
  69.     // glfwSwapInterval(5);
  70.     while (!glfwWindowShouldClose(window))
  71.     {
  72.         render(window);
  73.  
  74.         glfwSwapBuffers(window);
  75. //        glfwPollEvents();
  76.         glfwWaitEvents();
  77.     }
  78.     glfwTerminate();
  79.     return 0;
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top