|
|

楼主 |
发表于 2006-10-7 02:12:00
|
显示全部楼层
Re:求助:这个产生赛平斯基垫片的几行代码错在哪儿?
谢谢楼上!偶已经改过了,修改后的代码如下:
-----------------------------------------
#include <windows.h>
#include <gl/Gl.h>
#include <gl/glut.h>
class GLintPoint{
public:
GLint x, y;
};
int random(int m)
{
return rand() % m;
}
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void drawDot(GLint x, GLint y)
{ // 在整数点(x, y)绘制一个点
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd;
}
void Sierpinski(void)
{
GLintPoint T[3] = {{10, 10}, {300, 30}, {200, 300}};
int index = random(3); // 0、1或2都很相似
GLintPoint point = T[index]; // 初始点
drawDot(point.x, point.y); // 绘制初始点
for (int i = 0; i < 1000; i++) // 绘制1000个点
{
index = random(3);
point.x = (point.x + T[index].x) / 2;
point.y = (point.y + T[index].y) / 2;
drawDot(point.x, point.y);
}
glFlush();
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
Sierpinski();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow("Sierpinski");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
-----------------------------------------
可为什么绘制出的图片会这么难看呢?

图片的刷新也有问题……
------------------------------------------------------------------------------------------------
改为绘制20000个点,好看了一些,但是刷新还是有问题 [em7]为什么背景不能持续显示为白色呢?
 |
|