Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <GL/glut.

h> // (or others, depending on the system in use)


#include<stdlib.h>

void init (void)


{
glClearColor (0.0, 0.0, 0.0, 0.0); // Set display-window color to white.
glPointSize(3.0);
glMatrixMode (GL_PROJECTION); // Set projection parameters.
gluOrtho2D (0.0, 800.0, 0.0, 600.0);
}

int x1=0,y1=0;
void Draw()
{
glClear(GL_COLOR_BUFFER_BIT |GL_RGBA);
GLsizei r,g,b;
r=rand()%2;
b=rand()%2;
g=rand()%2;
glColor3f(r,g,b);

glBegin(GL_POINTS);
x1=rand()%800;
y1=rand()%600;
glVertex2i(x1,y1);

glEnd ( );

glFlush ( ); // Process all OpenGL routines as quickly as possible.


glutSwapBuffers();
}

void main (int argc, char** argv)


{
glutInit (&argc, argv); // Initialize GLUT.
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); // Set display mode.
glutInitWindowPosition(50, 100); // Set top-left display-window position.
glutInitWindowSize(800,600); // Set display-window width and height.
glutCreateWindow ("An Example OpenGL Program"); // Create display window.

init ( ); // Execute initialization procedure.


glutDisplayFunc(Draw); // Send graphics to display window.
glutIdleFunc(Draw);
glutMainLoop( ); // Display everything and wait.
}

You might also like