求教一个问题,如何在模拟生成10万个离散点并计算出性能消耗? 如何在opengl中绘制模拟生成的10万个离散点,并给出性能消耗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #include <GL/glut.h>#include <stdlib.h>#include <time.h>#include <stdio.h>#include <iostream>using namespace std; const int MAX=1000; const int count=1000000;class Point { public: GLfloat x; GLfloat y; Point(const GLfloat &x1=0.0,const GLfloat & y1=0.0){x=x1;y=y1;} };Point point[count];void init (void) { glClearColor (1.0, 1.0, 1.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, MAX, 0.0, MAX, -1.0, 1.0);}void display(void){ glClear (GL_COLOR_BUFFER_BIT); glColor3f (0.0, 0.0, 0.0); glPointSize(1); clock_t start, finish; double duration; int m_count=100;cout<<"Time to draw "<<count<<" nodes is: ";start = clock(); for (int m=0;m<m_count;m++) { glBegin(GL_POINTS); for (int j=0;j<count;j++) { glVertex2f(point[j].x,point[j].y); } glEnd(); } finish = clock();duration = (double)(finish - start) / CLOCKS_PER_SEC/m_count; cout<<duration<<" seconds"<<endl; glFlush ();}int main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (1000, 500); glutInitWindowPosition (100, 100); glutCreateWindow ("opengl"); init (); srand( (unsigned)time( NULL ) ); for (int i=0;i<count;i++) { point[i].x=(GLfloat)(rand()%MAX); point[i].y=(GLfloat)(rand()%MAX); } glutDisplayFunc(display); glutMainLoop(); return 0; } 使用CMDIFrameWndEx出现的GDI泄漏问题 请问如何按位比较 activex开发问题 急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 用vc6.0做了一个对话框程序,怎样才能按Enter键后窗口不关闭? 如何在VC2005中使用大内存! 如何在程序中安全的删除u盘。 ...............【换马甲拉】......... 高手指点了,关于Activex中如何用=赋属性值????送分了! 如何实现平滑字体 简单问题:如何获得系统有多少个盘? vc字符串连接 强制类型转换。指针取值疑惑????
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <iostream>
using namespace std;
const int MAX=1000;
const int count=1000000;
class Point
{
public:
GLfloat x;
GLfloat y;
Point(const GLfloat &x1=0.0,const GLfloat & y1=0.0){x=x1;y=y1;}
};
Point point[count];
void init (void)
{ glClearColor (1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, MAX, 0.0, MAX, -1.0, 1.0);
}
void display(void)
{ glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 0.0);
glPointSize(1); clock_t start, finish;
double duration;
int m_count=100;
cout<<"Time to draw "<<count<<" nodes is: ";
start = clock();
for (int m=0;m<m_count;m++)
{ glBegin(GL_POINTS);
for (int j=0;j<count;j++)
{
glVertex2f(point[j].x,point[j].y);
}
glEnd();
}
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC/m_count;
cout<<duration<<" seconds"<<endl;
glFlush ();
}int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (1000, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("opengl");
init (); srand( (unsigned)time( NULL ) );
for (int i=0;i<count;i++)
{
point[i].x=(GLfloat)(rand()%MAX);
point[i].y=(GLfloat)(rand()%MAX);
}
glutDisplayFunc(display);
glutMainLoop();
return 0;
}