版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34195441/article/details/79122145
#include <GL/glut.h>
void myDisplay(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0f, 1.0f, 1.0f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);//矩形
glBegin (GL_QUADS);//菱形
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.0f, 0.0f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (-0.25f, 0.5f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.0f, 1.0f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.25f, 0.5f);
glEnd ();
glBegin (GL_QUADS);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.0f, 0.0f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.25f, 0.5f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.75f, 0.75f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.5f, 0.25f);
glEnd ();
glBegin (GL_QUADS);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.0f, 0.0f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.5f, 0.25f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (1.0f, 0.0f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.5f, -0.25f);
glEnd ();
glBegin (GL_QUADS);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.0f, 0.0f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.5f, -0.25f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.75f, -0.75f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.25f, -0.5f);
glEnd ();
glBegin (GL_QUADS);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.0f, 0.0f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (-0.25f, -0.5f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.0f, -1.0f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.25f, -0.5f);
glEnd ();
glBegin (GL_QUADS);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.0f, 0.0f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (-0.25f, -0.5f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (-0.75f, -0.75f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (-0.5f, -0.25f);
glEnd ();
glBegin (GL_QUADS);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (0.0f, 0.0f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (-0.5f, 0.25f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (-1.0f, 0.0f);
glColor3f (1.0f, 0.0f, 1.0f); glVertex2f (-0.5f, -0.25f);
glEnd ();
glBegin (GL_QUADS);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.0f, 0.0f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (-0.5f, 0.25f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (-0.75f, 0.75f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (-0.25f, 0.5f);
glEnd ();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("Hello world!");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}