开发者

When using glOrthof, all I see is a cross

I have an iOS app which runs in landscape (always), and uses OpenGL for drawing. I have this code in my draw method:

  GLfloat width = self.frame.size.width;   // 480
  GLfloat height = self.frame.size.height; // 320
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrthof(-width / 2, width / 2, -height / 2, height / 2, -1.0f, 1.0f);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(160.0f, 240.0f, 0开发者_开发技巧.0f);
  glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);
  glScalef(1.0f, -1.0f, 1.0f);

  glMatrixMode(GL_PROJECTION);
  glTranslatef(self.player.x, self.player.y, 0.0f);

Where self.player.x and self.player.y are GLfloat variables ranging from -3.0f to 3.0f.

However, all I see is a blue cross:

When using glOrthof, all I see is a cross

I use glOrthof to make OpenGL use the correct aspect ratio. When I comment the glOrthof call out, I get this result (the light blue lines should form squares, not rectangles):

When using glOrthof, all I see is a cross


I tried everything, from swapping the width and the height, changing the parameters of the glOrthof call, but nothing helped. Could someone help me out, or explain what I've done wrong? Thanks in advance. :)


Try this:

GLfloat aspect=width/height;
glOrthof(-aspect, aspect, -1.0, 1.0, -1.0f, 1.0f);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜