74 lines
1.6 KiB
C++
74 lines
1.6 KiB
C++
#include <iostream>
|
|
#include <cstdlib>
|
|
|
|
#include <GL/glut.h>
|
|
|
|
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;
|
|
}
|