#include <GL/glut.h>
#include<math.h>
#define pi 3.141592653584372
int n;
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); //清除颜色
glEnable(GL_BLEND);//开始调用颜色混合
glBlendFunc(GL_ONE, GL_ONE);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
n = 100;
float R = 0.5f;
for (int i = 0; i < n; i++)
{
glVertex2f(R*sin(2 * pi / n*i)-0.3, R*cos(2 * pi / n*i)-0.3);
}
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 0.0);
for (int i = 0; i < n; i++)
{
glVertex2f(R*sin(2 * pi / n*i) + 0.3, R*cos(2 * pi / n*i) -0.3);
}
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 1.0);
for (int i = 0; i < n; i++)
{
glVertex2f(R*sin(2 * pi / n*i) + 0.0, R*cos(2 * pi / n*i) + 0.3);
}
glEnd();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
gluOrtho2D(0.0, 1.0, 0.0, 1.0*(GLfloat)h / (GLfloat)w);
else
gluOrtho2D(0.0, 1.0*(GLfloat)w / (GLfloat)h, 0.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);//对GLUT进行初始化,这个函数必须在其它的GLUT使用之前调用一次
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); //设置显示方式
glutInitWindowPosition(400, 400);
glutInitWindowSize(400, 400);
// glutReshapeFunc(reshape);
glutCreateWindow("最后一个实验,加油"); //根据前面设置的信息创建窗口。参数将被作为窗口的标题。
// glutReshapeFunc(reshape);
glutDisplayFunc(&myDisplay); //当需要画图时,请调用myDisplay函数
glutMainLoop(); //进行一个消息循环
return 0;
#include<math.h>
#define pi 3.141592653584372
int n;
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); //清除颜色
glEnable(GL_BLEND);//开始调用颜色混合
glBlendFunc(GL_ONE, GL_ONE);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
n = 100;
float R = 0.5f;
for (int i = 0; i < n; i++)
{
glVertex2f(R*sin(2 * pi / n*i)-0.3, R*cos(2 * pi / n*i)-0.3);
}
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 0.0);
for (int i = 0; i < n; i++)
{
glVertex2f(R*sin(2 * pi / n*i) + 0.3, R*cos(2 * pi / n*i) -0.3);
}
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 1.0);
for (int i = 0; i < n; i++)
{
glVertex2f(R*sin(2 * pi / n*i) + 0.0, R*cos(2 * pi / n*i) + 0.3);
}
glEnd();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
gluOrtho2D(0.0, 1.0, 0.0, 1.0*(GLfloat)h / (GLfloat)w);
else
gluOrtho2D(0.0, 1.0*(GLfloat)w / (GLfloat)h, 0.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);//对GLUT进行初始化,这个函数必须在其它的GLUT使用之前调用一次
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); //设置显示方式
glutInitWindowPosition(400, 400);
glutInitWindowSize(400, 400);
// glutReshapeFunc(reshape);
glutCreateWindow("最后一个实验,加油"); //根据前面设置的信息创建窗口。参数将被作为窗口的标题。
// glutReshapeFunc(reshape);
glutDisplayFunc(&myDisplay); //当需要画图时,请调用myDisplay函数
glutMainLoop(); //进行一个消息循环
return 0;
}