📄 rcrv.c
字号:
#include<windows.h>
#include<glut.h>
#include<gl.h>
GLfloat v[3][2]={{5.0,5.0},{12.0,5.0},{8.5,15.0}};
int n;
void triangle(GLfloat *a,GLfloat *b,GLfloat *c)
{
glVertex2fv(a);
glVertex2fv(b);
glVertex2fv(c);
}
void divide_tri(GLfloat *a, GLfloat *b,GLfloat *c, int m)
{
GLfloat v0[2],v1[2],v2[2];
int j;
if(m>0)
{
for(j=0;j<2;j++)
{
v0[j]=(a[j]+b[j])/2;
}
for(j=0;j<2;j++)
{
v1[j]=(a[j]+c[j])/2;
}
for(j=0;j<2;j++)
{
v2[j]=(b[j]+c[j])/2;
}
divide_tri(a,v0,v1,m-1);
divide_tri(c,v1,v2,m-1);
divide_tri(b,v2,v0,m-1);
}
else triangle(a,b,c);
}
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
gluOrtho2D(0.0,15.0,0.0,15.0);
}
void myDisplay(void)
{
//int n=5;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
divide_tri(v[0],v[1],v[2],n);
glEnd();
glFlush();
}
void main(int argc,char **argv)
{
n=5;
glutInitWindowSize(640,480);
glutCreateWindow("aaa");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -