#include<GL/glut.h>
#include<stdlib.h>
#include<time.h>
const int screenWidth=640;
const int screenHeight=480;
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(1.0,0.0,0.0);
glPointSize(3.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
void myDisplay()
{
srand(time(NULL));
GLint i=0;
GLint x1=0,y1=0,x2=0,y2=0;
GLfloat col=0;
glClear(GL_COLOR_BUFFER_BIT);
for(i=0;i<50;i++)
{
x1=rand()%screenWidth;
y1=rand()%screenHeight;
x2=rand()%screenWidth;
y2=rand()%screenHeight;
col=(rand()%10)/10.0;
glColor3f(col/2,col,col);
glRecti(x1,y1,x2,y2);
}
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutCreateWindow("drawing rectangles");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
#include<stdlib.h>
#include<time.h>
const int screenWidth=640;
const int screenHeight=480;
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(1.0,0.0,0.0);
glPointSize(3.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
void myDisplay()
{
srand(time(NULL));
GLint i=0;
GLint x1=0,y1=0,x2=0,y2=0;
GLfloat col=0;
glClear(GL_COLOR_BUFFER_BIT);
for(i=0;i<50;i++)
{
x1=rand()%screenWidth;
y1=rand()%screenHeight;
x2=rand()%screenWidth;
y2=rand()%screenHeight;
col=(rand()%10)/10.0;
glColor3f(col/2,col,col);
glRecti(x1,y1,x2,y2);
}
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutCreateWindow("drawing rectangles");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
No comments:
Post a Comment