如何让点一个个的现实,现在一次全出来了。

haiyanhuman 2009-03-20 05:38:12
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <gl/glut.h>


void pixel(int x, int y, int size, GLubyte Red, GLubyte Green, GLubyte Blue)
{
glPointSize(size);

glBegin(GL_POINTS);
glColor3ub(Red, Green, Blue);
glVertex2f(x, y);
glEnd();

glFlush();

}

void drawing()
{
int x,y,red,green,blue;
srand((unsigned)time(NULL));
for(int i=0;i <2000;i++)
{
red=rand()%255+1;
green=rand()%255+1;
blue=rand()%255+1;
x=rand()%800+1;
y=rand()%600+1;
pixel(x, y, i%3, red, green, blue);
/*-------------------------------这里加入Sleep(10);就会出问题!!!!!!!!!!!!!!!!不出窗口了。*/
}

}

void init_display()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void display()
{
init_display();

drawing();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
}

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_SINGLE);
glutInitWindowSize(800, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow("Point");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
display();
glutMainLoop();
return 0;
}
...全文
74 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你在每处需要间隔的地方sleep.
daniel_yao 2009-03-20
  • 打赏
  • 举报
回复
for(int i=0;i <2000;i++)

这句话可以把2000 改成个全局变量

每次增加1或n个就可以了

opengl显示是要你全部场景画完才能显示 所以你在画的时候显示当然显示不了

你应该先画1个点 显示 再画2个点(包括前1个点) 显示。。。。。。直到2000个点才能给人感觉是依次显示的 看看opengl红宝书 前几章有说明的
lingyin55 2009-03-20
  • 打赏
  • 举报
回复
先#include <time.h>

//在需要开始计时的地方
long start = clock();

//在结束的地方
long end = clock();

//判读是不是到时间了
if ( ( start - end )>= 你设定的时间 )
{
//do something here
}
npuhuxl 2009-03-20
  • 打赏
  • 举报
回复
可以记下程序开始执行时的时间,在循环for(int i=0;i <2000;i++)
将2000改为与当前时间与开始时间间隔相关的函数,即可

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧