用OpenGL画Sierpinski Gasket,要求完整代码,图片如下,非诚勿扰谢谢
答案:1 悬赏:0 手机版
解决时间 2021-04-08 01:37
- 提问者网友:城市野鹿
- 2021-04-07 06:37
用OpenGL画Sierpinski Gasket,要求完整代码,图片如下,非诚勿扰谢谢
最佳答案
- 五星知识达人网友:神的生死簿
- 2021-04-07 08:13
#include
#include
#include
#include
void display()
{
GLfloat vertices[3][3] = {{0.0,0.0,0.0}, {25.0, 50.0,0.0}, {50.0,0.0,0.0}};
// an arbitrary triangle in the plane z = 0;
GLfloat p[3] = {7.5, 5.0, 0.0};
// or set to any desired initial point inside the triangle;
intj,k;
intrand();
glBegin(GL_POINTS);
for (k = 0; k < 5000; k++)
{
j = rand()%3;
// compute new location;
p[0] = (p[0]+vertices[j][0])/2;
p[1] = (p[1]+vertices[j][1])/2;
// display new point
glVertex3fv(p);
}
glEnd();
glFlush();
}
void SetupRC(void)
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
glColor3f(1.0f,1.0f,1.0f);
}
void ChangeSize(GLsizei w,GLsizei h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,50.0,0,50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(0,0);
glutCreateWindow("Bounce");
glutDisplayFunc(display);
glutReshapeFunc(ChangeSize);
SetupRC();
glutMainLoop();
return 0;
}
追问:#include "stdafx.h"
#include
voidinit(){
glClearColor( 1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.01, 1.01, -1.01, 1.01);
glMatrixMode(GL_MODELVIEW);
}
#include
#include
#include
void display()
{
GLfloat vertices[3][3] = {{0.0,0.0,0.0}, {25.0, 50.0,0.0}, {50.0,0.0,0.0}};
// an arbitrary triangle in the plane z = 0;
GLfloat p[3] = {7.5, 5.0, 0.0};
// or set to any desired initial point inside the triangle;
intj,k;
intrand();
glBegin(GL_POINTS);
for (k = 0; k < 5000; k++)
{
j = rand()%3;
// compute new location;
p[0] = (p[0]+vertices[j][0])/2;
p[1] = (p[1]+vertices[j][1])/2;
// display new point
glVertex3fv(p);
}
glEnd();
glFlush();
}
void SetupRC(void)
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
glColor3f(1.0f,1.0f,1.0f);
}
void ChangeSize(GLsizei w,GLsizei h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,50.0,0,50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(0,0);
glutCreateWindow("Bounce");
glutDisplayFunc(display);
glutReshapeFunc(ChangeSize);
SetupRC();
glutMainLoop();
return 0;
}
追问:#include "stdafx.h"
#include
voidinit(){
glClearColor( 1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.01, 1.01, -1.01, 1.01);
glMatrixMode(GL_MODELVIEW);
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯