仅供个人学习记录使用,如有错误,感谢指正!!!!!!!!!!
#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<math.h>
#include<Windows.h>
#include<stdio.h> //86
#include<GL/glut.h>
void Init() {
glClearColor(0.7f, 0.8f, 1.0f, 0.0f); //浅蓝//rgb透明度 背景色
}
void Reshape(int w,int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, (double)w,0,(double)h);
}
void myDisplay() { //金刚石 400 400 100//由团扇变化而来
int x0, y0, r;
scanf("%d %d %d", &x0, &y0, &r);
int i, n = 20;
float st;
glClear(GL_COLOR_BUFFER_BIT);
st = (360.0 / n) * (3.14 / 180);//角度转换为弧度
glColor3f(0.3f, 0.4f, 1.0f);
glBegin(GL_LINE_LOOP);
//for (int j = 0; j < r; j += r / n) {
for (int i = 0; i < n; i++) {
glVertex2f(x0 + r * cos(i * st), y0 + r * sin(i * st));
}
//}
glEnd();
glFlush();
glBegin(GL_LINES);
for (int j = n; j >=0; j-=1) {
for (int i = 0; i < n; i++) {
glVertex2f(x0 + r * cos(j * st), y0 + r * sin(j * st));
glVertex2f(x0 + r * cos(i * st), y0 + r * sin(i * st));
}
}
glEnd();
glFlush();
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(800, 700);
glutCreateWindow("the forth");
Init();
glutReshapeFunc(Reshape);
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}