Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include "shader.h"
- const char *vcode = "#version 330 core\n"
- "layout (location = 0) in vec3 aPos;\n"
- "void main()\n"
- "{\n"
- " gl_Position = vec4(aPos, 1.0);\n"
- "}";
- const char *fcode = "#version 330 core\n"
- "out vec4 FragColor;\n"
- "void main()\n"
- "{\n"
- "FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
- "}\n";
- int main()
- {
- GLFWwindow *win;
- GLuint vsh, fsh, program;
- GLuint vao, vbo;
- int i;
- float saw[3000] = {};
- if (glfwInit() != 1) {
- fprintf(stderr, "failed to init glfw\n");
- return -1;
- }
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- win = glfwCreateWindow(800, 600, "a title for a window!", NULL, NULL);
- if (win == NULL) {
- fprintf(stderr, "failed to open window\n");
- return -1;
- }
- glfwMakeContextCurrent(win);
- if (glewInit() != GLEW_OK) {
- fprintf(stderr, "Failed to init glew!");
- return -1;
- }
- /* generate :-D */
- float total = 1;
- int k = 0;
- for (i = 0; i < 3000; i += 3) {
- /*
- if (i == 0) {
- continue;
- }
- */
- saw[i + 0] = (total += -0.002);
- saw[i + 1] = sinf(10 * (2 * 3.14) * k);
- /* printf("%f\n", saw[i + 1]); */
- k++;
- printf("%f\n", saw[i]);
- }
- printf("%d\n", sizeof(sin));
- /* GL */
- vsh = vertex_compile(vcode);
- fsh = fragment_compile(fcode);
- program = shaders_link(vsh, fsh);
- glGenVertexArrays(1, &vao);
- glGenBuffers(1, &vbo);
- glBindVertexArray(vao);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, sizeof(saw), saw, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(0);
- while (glfwWindowShouldClose(win) != 1) {
- glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- glUseProgram(program);
- glBindVertexArray(vao);
- glDrawArrays(GL_LINE_STRIP, 0, 1000);
- glfwSwapBuffers(win);
- glfwPollEvents();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement