Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GLFW/glfw3.h>
- #include <iostream>
- #include <cmath>
- double a[] = {0., 0., 0.},
- b[] = {.5, 0, 0.},
- c[] = {.5, .5, 0.},
- d[] = {0, .7, 0};
- static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
- {
- if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
- glfwSetWindowShouldClose(window, GLFW_TRUE);
- if (key == GLFW_KEY_LEFT )
- glRotatef(5, 0, 1, 0);
- if (key == GLFW_KEY_RIGHT)
- glRotatef(-5, 0, 1, 0);
- if (key == GLFW_KEY_UP && action == GLFW_PRESS)
- a[1] += .1;
- if (key == GLFW_KEY_DOWN && action == GLFW_PRESS)
- a[1] -= .1;
- }
- void render(GLFWwindow *window) {
- int width, height;
- glfwGetFramebufferSize(window, &width, &height);
- glViewport(0, 0, width, height);
- glClear(GL_COLOR_BUFFER_BIT);
- glBegin(GL_POINTS);
- glPointSize(3);
- glColor3b(255, 0, 0);
- glVertex3d(-1, 0, 0);
- glVertex3d(1, 0, 0);
- // glVertex3d(0, -10, 0);
- // glVertex3d(0, 10, 0);
- // glVertex3d(0, 0, -10);
- // glVertex3d(0, 0, 10);
- glEnd();
- glBegin(GL_TRIANGLES);
- int dots = 100;
- double pi = 3.141591;
- double r = 0.5;
- double x_pr = 0, y_pr = 0;
- int col = 1;
- for (double alph = 2 * pi / dots; alph < 2 * pi; alph += 2 * pi / dots) {
- double x = r * cos(alph);
- double y = r * sin(alph);
- glColor3b(col, 100, 0);
- col = (col + 1) % 255;
- glVertex3d(x, y, 10);
- glVertex3d(x_pr, y_pr, 1);
- glVertex3dv(a);
- x_pr = x;
- y_pr = y;
- }
- glEnd();
- }
- int main()
- {
- glfwInit();
- auto *window = glfwCreateWindow(500, 500, "hui", NULL, NULL);
- glfwMakeContextCurrent(window);
- glfwSetKeyCallback(window, key_callback);
- // glfwSwapInterval(5);
- while (!glfwWindowShouldClose(window))
- {
- render(window);
- glfwSwapBuffers(window);
- // glfwPollEvents();
- glfwWaitEvents();
- }
- glfwTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement