Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <GLFW/glfw3.h>
- #include <gl/GL.h>
- void render_loop()
- {
- glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- float x1 = 10.0f, y1 = 15.0f;
- float x2 = 80.0f, y2 = 95.f;
- int i, j;
- for (i = 1; i <= 8; i++) {
- for (j = 1; j <= 8; j++) {
- if ((j+i) % 2 == 0)
- glColor3f(0.0, 0.0, 0.0);
- else
- glColor3f(1.0, 1.0, 1.0);
- glBegin(GL_POLYGON);
- glVertex2f(x1, y1);
- glVertex2f(x2, y1);
- glVertex2f(x2, y2);
- glVertex2f(x1, y2);
- glEnd();
- x1 += 70.0f;
- x2 += 70.0f;
- }
- x1 = 10.0f;
- x2 = 80.0f;
- y1 += 80.0f;
- y2 += 80.0f;
- }
- }
- /* program entry */
- int main(int argc, char *argv[])
- {
- GLFWwindow* window;
- if (!glfwInit())
- {
- fprintf(stderr, "Failed to initialize GLFW\n");
- exit(EXIT_FAILURE);
- }
- glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
- window = glfwCreateWindow(660, 610, "LearnOpenGL", NULL, NULL);
- if (!window)
- {
- fprintf(stderr, "Failed to open GLFW window\n");
- glfwTerminate();
- exit(EXIT_FAILURE);
- }
- glfwMakeContextCurrent(window);
- glfwSwapInterval(1);
- // set up view
- glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- glViewport(0, 0, 800, 600);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- // see https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml
- glOrtho(0.0, 700.0, 0.0, 650.0, 0.0, 1.0); // this creates a canvas you can do 2D drawing on
- // Main loop
- while (!glfwWindowShouldClose(window))
- {
- // Draw gears
- render_loop();
- // Swap buffers
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- // Terminate GLFW
- glfwTerminate();
- // Exit program
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement