我有一个作业的要求,如题。
下面是我的 部分 代码,编译什么的都没有问题。
不过,结果是没有图像显示出来。
是不是我在比如initial matrix 时候还有什么没达到要求的呢。
==============================================================
void init(void)
{
  /* Setup cube vertex data. */
  v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1;
  v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1;
  v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1;
  v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1;
  v[0][2] = v[3][2] = v[4][2] = v[7][2] = 1;
  v[1][2] = v[2][2] = v[5][2] = v[6][2] = -1;  /* Enable a single OpenGL light. */   //==========================rewrite gllightfv,and lgmaterial ????  lecture 8
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHTING);  /* Use depth buffering for hidden surface elimination. */
  glEnable(GL_DEPTH_TEST);
}void viewSetup(void)
{
      /* Setup the view of the cube. */     glMatrixMode(GL_PROJECTION);
 gluPerspective(  40.0, 1.0,1.0, 10.0);
 glMatrixMode(GL_MODELVIEW);
      //我的想法是,单纯的用下面这个函数来代替GLLOADIDENTITY()就可以,不过感觉错误可能就在这。
      //用initmatrix()来给在global里定义过的matrix m 赋值。
 
 InitMatrix(m);  gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.);           /* Adjust cube position to be asthetic angle. */   
Translate(m,0,0,-1);   // glTranslatef(0.0, 0.0, -1.0);    RotateX(m,60);
    RotateY(m,0);
    RotateZ(m,0);    RotateX(m,0);
    RotateY(m,0);
    RotateZ(m,-20);
    //glRotatef(60, 1.0, 0.0, 0.0);
    //glRotatef(-20, 0.0, 0.0, 1.0);
//但是,transformation 和 object display应该是分开的吧?
//即使没有运用成功transformation,object display应该还是可以正常显示的吧?
//在没改动这部分transformation代码之前,object display是很正常的。
//希望高手们能指点指点,

void main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutCreateWindow("red 3D lighted cube");
  glutDisplayFunc(display);
  init();
  viewSetup();
  glutMainLoop();
 //  return 0;             /* ANSI C requires main to return int. */
}

解决方案 »

  1.   

    problem solved!!我发现我要把所有支持的函数放在       最后  调用函数    之前
      

  2.   


    呵呵,我也想呀。不过这个是学校作业呢。没的选择,而且问题不是在语言上,而是老师要我们写类似于API的代码,,
      

  3.   

    很简单啊,先定义一个单位矩阵m,再glMatrixMode(GL_MODELVIEW);glLoadMatrixf(m)
      

  4.   

    InitMatrix(m);
    glMatrixMode(GL_MODELVIEW);
    glMultMatrixf(m);
    这样就行了啊
      

  5.   

    我尝试了以上的推荐方法。不过,会有错误。然后我又尝试了好几张方法想cast 参数,但是好像不行。你们知道什么方法可以解决这个问题吗。?void InitMatrix(MATRIX4X4 matIdent) //初始化 matrix m//
    {
    GLint row,col;
    for(row=0;row<4;row++)
    for(col=0;col<4;col++)
    matIdent[row][col]=(row==col);

    InitMatrix(m);
    glMatrixMode(GL_MODELVIEW);
    glMultMatrixd( m );
    //glLoadMatrixf(m);
           C:\Program Files\Tencent\QQ\Users\292053446\FileRecv\cube.cpp(274) : error C2664: 'glLoadMatrixf' : cannot convert parameter 1 from 'double [4][4]' to 'const float *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.