C++ OpenGL 3.3中用于广告牌效果的地形不工作

C++ OpenGL 3.3中用于广告牌效果的地形不工作,c++,opengl,C++,Opengl,我试图运行OpenGL游戏编程书源代码第15章中沙漠广告牌中的仙人掌示例。我很难在屏幕上看到沙漠地形。我使用GLFW作为我的窗口,示例代码创建了它自己的窗口,这可能是问题所在吗 或者,问题可能与下面的DisplayScene函数有关。在这个函数中,我是否必须从camera类中设置以下矩阵 ViewMatrix = camera[currentCamera]->GetViewMatrix(); ProjectionMatrix = camera[currentCamera]->GetV

我试图运行OpenGL游戏编程书源代码第15章中沙漠广告牌中的仙人掌示例。我很难在屏幕上看到沙漠地形。我使用GLFW作为我的窗口,示例代码创建了它自己的窗口,这可能是问题所在吗

或者,问题可能与下面的DisplayScene函数有关。在这个函数中,我是否必须从camera类中设置以下矩阵

ViewMatrix = camera[currentCamera]->GetViewMatrix();
ProjectionMatrix = camera[currentCamera]->GetViewProjectionMatrix();
下面是Cacti演示中的DisplayScene函数:

BOOL DisplayScene()
{
  // used to track the orientation of the viewer
  static GLfloat s_eye[] = { MAP_X * MAP_SCALE * 0.5, 8.0, -MAP_Z * MAP_SCALE * 0.5};
  static GLfloat s_at[]  = { 0.0, 0.0, 0.0 };
  static GLfloat s_angle = -90.0;
  float speed = 0.3f;

  // check for rotation
  if (g_keys[VK_LEFT])
  {
    s_angle -= 2.0;
  }
  if (g_keys[VK_RIGHT])
  {
    s_angle += 2.0;
  }

  // run if the shift key is pressed
  if (KEY_DOWN(VK_SHIFT))
    speed = speed * 2;

  float rad =  float(PI*s_angle/180.0f);

  // check for forward and backward motion
  if (g_keys[VK_UP])
  {
    s_eye[2] += (float)sin(rad) * speed;
    s_eye[0] += (float)cos(rad) * speed;
  }
  if (g_keys[VK_DOWN])
  {
    s_eye[2] -= (float)sin(rad) * speed;
    s_eye[0] -= (float)cos(rad) * speed;
  }

  // do bound's checking to make sure they don't leave the map
  if (s_eye[0] < MAP_SCALE)
    s_eye[0] = MAP_SCALE;
  if (s_eye[0] > (MAP_X - 2) * MAP_SCALE)
    s_eye[0] = (MAP_X - 2) * MAP_SCALE;
  if (s_eye[2] < -(MAP_Z - 2) * MAP_SCALE)
    s_eye[2] = -(MAP_Z - 2) * MAP_SCALE;
  if (s_eye[2] > - MAP_SCALE)
    s_eye[2] = -MAP_SCALE;

  // set the eye position in relation to the ground
  s_eye[1] = GetHeight(s_eye[0], s_eye[2]) + 2.0f;

  //set the look at point to be at eye level in the direction the viewer is headed
  s_at[0] = float(s_eye[0] + 100*cos(rad));
  s_at[2] = float(s_eye[2] + 100*sin(rad));
  s_at[1] = s_eye[1];

  // set up the modelview matrix according to this viewer orientation
  glLoadIdentity();
  gluLookAt(s_eye[0], s_eye[1], s_eye[2],
    s_at[0], s_at[1], s_at[2],
    0.0, 1.0, 0.0
    );

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  DrawSand();
  DrawCacti();

  return TRUE;
} // end DisplayScene()
以下是用于绘制地形的DrawSand函数:

void DrawSand()
{
  // select the sand texture
  glBindTexture(GL_TEXTURE_2D, g_sand);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

  // loop through all the triangle strips
  for (int z = 0; z < MAP_Z-1; z++)
  {
    // draw the triangles in this strip
    glDrawElements(GL_TRIANGLE_STRIP, MAP_X * 2, GL_UNSIGNED_INT, &g_indexArray[z * MAP_X * 2]);
  }


} // end DrawSand()

可能不是问题所在,但使用GL_调制似乎很奇怪。这是不推荐使用的功能。是的,Cacti示例已有几年历史。您是否知道一个更现代的OpenGL公告牌示例,它使用2D图像模拟3D对象?