From 3e28700cebc6fa771c7fbc61bdd3f3266b6fab0e Mon Sep 17 00:00:00 2001 From: David Vereb Date: Thu, 21 May 2020 16:34:50 -0400 Subject: [PATCH] Initial Commit. --- .gitignore | 4 +++ Makefile | 2 ++ main.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1186b73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*~ +.o +a.out + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..76444a0 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +a.out: main.cpp + clang++ -std=c++14 -g -o a.out main.cpp -lGL -lGLU -lglut diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d82ad9e --- /dev/null +++ b/main.cpp @@ -0,0 +1,73 @@ +#include +#include + +#include + +GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; /* Red diffuse light. */ +GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */ + +void draw() +{ + glLineWidth(2.0f); + glColor3d(0,0,0); + + float line[21]; + + for(auto i = 0; i < 21; ++i) + line[i] = 0; + + for(auto y = 0; y < 100; ++y) + { + glBegin(GL_LINE_STRIP); + for(auto x = 0; x < 21; ++x) + { + line[x] += (rand() % 5 - 2) / 4.0f; + glVertex3f(x - 10, line[x], 25.0 - y); + } + glEnd(); + } +} + +void display() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + draw(); + glutSwapBuffers(); +} + +void init() +{ + // dvereb: + srand(time(NULL)); + + /* Enable a single OpenGL light. */ + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); + + /* Use depth buffering for hidden surface elimination. */ + glEnable(GL_DEPTH_TEST); + + /* Setup the view of the cube. */ + glMatrixMode(GL_PROJECTION); + gluPerspective( /* field of view in degree */ 40.0, + /* aspect ratio */ 1.0, + /* Z near */ 1.0, /* Z far */ 1000.0); + glMatrixMode(GL_MODELVIEW); + gluLookAt(0.0, 7.0, 25.0, /* eye is at (0,0,5) */ + 0.0, 0.0, 0.0, /* center is at (0,0,0) */ + 0.0, 1.0, 0.); /* up is in positive Y direction */ +} + +int main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow("test opengl program"); + glutDisplayFunc(display); + init(); + glutMainLoop(); + + return 0; +}