| 发表于:2007-12-30 21:04:32 楼主 |
我最近刚刚开始看opengl,以下的程序是《opengl超级宝典》上第3章的一个例子,输出的结果应该是一个螺旋曲线。但是在我的电脑上输出的结果却只是一个大的、中间为空心的的圆饼。我想请问一下各位是什么原因(是不是硬件原因)? 我的电脑主板名称 asus p5pe-vm 显示卡(主板集成) intel 82865g graphics controller [a-2] 程序如下: // pointsz.c // opengl superbible, chapter 4 // demonstrates opengl primative gl_points with point size // program by richard s. wright jr. #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> #include <gl/glut.h> #include <math.h> // define a constant for the value of pi #define gl_pi 3.1415f // rotation amounts static glfloat xrot = 0.0f; static glfloat yrot = 0.0f; // called to draw scene void renderscene(void) { glfloat x,y,z,angle; // storeage for coordinates and angles glfloat sizes[2]; // store supported point size range glfloat step; // store supported point size increments glfloat cursize; // store current size // clear the window with current clearing color glclear(gl_color_buffer_bit); // save matrix state and do the rotation glpushmatrix(); glrotatef(xrot, 1.0f, 0.0f, 0.0f); glrotatef(yrot, 0.0f, 1.0f, 0.0f); // get supported point size range and step size glgetfloatv(gl_point_size_range,sizes); glgetfloatv(gl_point_size_granularity,&step); // set the initial point size cursize = sizes[0]; // set beginning z coordinate z = -50.0f; // loop around in a circle three times for(angle = 0.0f; angle <= (2.0f*3.1415f)*3.0f; angle += 0.1f) { // calculate x and y values on the circle // specify the point size before the primative is specified glpointsize(cursize); x = 50.0f*sin(angle); y = 50.0f*cos(angle); // draw the point glbegin(gl_points); glvertex3f(x, y, z); glend(); z += 0.5f; cursize += step; // bump up the z value and the point size } // restore matrix state glpopmatrix(); // flush drawing commands glutswapbuffers(); } // this function does any needed initialization on the rendering // context. void setuprc() { // black background glclearcolor(0.0f, 0.0f, 0.0f, 1.0f ); // set drawing color to green glcolor3f(0.0f, 1.0f, 0.0f); } void specialkeys(int key, int x, int y) { if(key == glut_key_up) xrot-= 5.0f; if(key == glut_key_down) xrot += 5.0f; if(key == glut_key_left) yrot -= 5.0f; if(key == glut_key_right) yrot += 5.0f; if(key > 356.0f) xrot = 0.0f; if(key < -1.0f) xrot = 355.0f; if(key > 356.0f) yrot = 0.0f; if(key < -1.0f) yrot = 355.0f; // refresh the window glutpostredisplay(); } void changesize(int w, int h) { glfloat nrange = 100.0f; // prevent a divide by zero if(h == 0) h = 1; // set viewport to window dimensions glviewport(0, 0, w, h); // reset projection matrix stack glmatrixmode(gl_projection); glloadidentity(); // establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glortho (-nrange, nrange, -nrange*h/w, nrange*h/w, -nrange, nrange); else glortho (-nrange*w/h, nrange*w/h, -nrange, nrange, -nrange, nrange); // reset model view matrix stack glmatrixmode(gl_modelview); glloadidentity(); } int main(int argc, char* argv[]) { glutinit(&argc, argv); glutinitdisplaymode(glut_double ¦ glut_rgb ¦ glut_depth); glutcreatewindow("points size example"); glutreshapefunc(changesize); glutspecialfunc(specialkeys); glutdisplayfunc(renderscene); setuprc(); glutmainloop(); return 0; } |
|
|
|
|