Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <GL/glew.h>
  5. #include <GLFW/glfw3.h>
  6.  
  7. #include "shader.h"
  8.  
  9. const char *vcode = "#version 330 core\n"
  10.                     "layout (location = 0) in vec3 aPos;\n"
  11.                     "void main()\n"
  12.                     "{\n"
  13.                     "   gl_Position = vec4(aPos, 1.0);\n"
  14.                     "}";
  15. const char *fcode = "#version 330 core\n"
  16.                     "out vec4 FragColor;\n"
  17.                     "void main()\n"
  18.                     "{\n"
  19.                     "FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
  20.                     "}\n";
  21.  
  22. int main()
  23. {
  24.     GLFWwindow *win;
  25.     GLuint vsh, fsh, program;
  26.     GLuint vao, vbo;
  27.     int i;
  28.     float saw[3000] = {};
  29.  
  30.     if (glfwInit() != 1) {
  31.         fprintf(stderr, "failed to init glfw\n");
  32.         return -1;
  33.     }
  34.  
  35.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  36.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  37.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  38.  
  39.     win = glfwCreateWindow(800, 600, "a title for a window!", NULL, NULL);
  40.     if (win == NULL) {
  41.         fprintf(stderr, "failed to open window\n");
  42.         return -1;
  43.     }
  44.  
  45.     glfwMakeContextCurrent(win);
  46.     if (glewInit() != GLEW_OK) {
  47.         fprintf(stderr, "Failed to init glew!");
  48.         return -1;
  49.     }
  50.  
  51.     /* generate  :-D */
  52.     float total = 1;
  53.     int k = 0;
  54.     for (i = 0; i < 3000; i += 3) {
  55.     /*
  56.         if (i == 0) {
  57.             continue;
  58.         }
  59.         */
  60.         saw[i + 0] = (total += -0.002);
  61.         saw[i + 1] = sinf(10 * (2 * 3.14) * k);
  62.     /*  printf("%f\n", saw[i + 1]); */
  63.         k++;
  64.         printf("%f\n", saw[i]);
  65.     }
  66.  
  67.     printf("%d\n", sizeof(sin));
  68.     /* GL */
  69.     vsh = vertex_compile(vcode);
  70.     fsh = fragment_compile(fcode);
  71.     program = shaders_link(vsh, fsh);
  72.  
  73.     glGenVertexArrays(1, &vao);
  74.     glGenBuffers(1, &vbo);
  75.  
  76.     glBindVertexArray(vao);
  77.     glBindBuffer(GL_ARRAY_BUFFER, vbo);
  78.     glBufferData(GL_ARRAY_BUFFER, sizeof(saw), saw, GL_STATIC_DRAW);
  79.     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
  80.     glEnableVertexAttribArray(0);  
  81.  
  82.     while (glfwWindowShouldClose(win) != 1) {
  83.         glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
  84.         glClear(GL_COLOR_BUFFER_BIT);
  85.  
  86.         glUseProgram(program);
  87.         glBindVertexArray(vao);
  88.         glDrawArrays(GL_LINE_STRIP, 0, 1000);
  89.  
  90.         glfwSwapBuffers(win);  
  91.         glfwPollEvents();
  92.     }
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement