您的位置:程序门 -> vc/mfc -> 图形处理/算法



请问一个基本的opengl的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请问一个基本的opengl的问题[已结贴,结贴人:ssh29]
发表于: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;
}
发表于:2007-12-31 06:18:201楼 得分:20
?你的程序在我机器上没有问题啊。是一个螺旋向上的弹簧~~
这个程序支持键盘操作。如果不调整弹簧的角度的话,默认会从底部看向头部,效果就是你说的那种情况。按   上下左右   看看?


快速检索

最新资讯
热门点击