横向模式OpenGL ES 1.1

时间:2012-08-20 05:26:10

标签: iphone opengl-es

我在iPhone上使用opengl es 1.1。

我最初为肖像写了一切看起来很棒但是当我切换到横向模式时,图形看起来很拉伸......

有关如何取消拉伸的任何线索?

我基本上遵循这个教程,但添加了方块并添加了shouldAutorotateToInterfaceOrientation但图形仍然被拉伸: http://www.71squared.com/2011/03/tutorial-14-moving-to-3d/

代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
}

- (void)drawFrame
{
    [(EAGLView *)self.view setFramebuffer];

    // Replace the implementation of this method to do your own custom drawing.
    static const GLfloat squareVertices[] = {
        -0.33f, -0.33f, 0.0f,
        0.33f, -0.33f, 0.0f,
        -0.33f,  0.33f, 0.0f,
        0.33f,  0.33f, 0.0f
    };

    static const GLubyte squareColors[] = {
        255, 255,   0, 255,
        0,   255, 255, 255,
        0,     0,   0,   0,
        255,   0, 255, 255,
    };

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Position the camera back from the origin and slightly raised i.e. {0, 3, -6}
    static GLfloat z = 0;

    gluLookAt(0, 5, -10, 0, 0, 0, 0, 1, 0);
    z += 0.075f;

   // GL DRAW ARRAYS STUFF GOES HERE

   [(EAGLView *)self.view presentFramebuffer];
}

- (void)initOpenGLES1
{
    // Set the clear color
    glClearColor(0, 0, 0, 1.0f);

    // Projection Matrix config
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    CGSize layerSize = self.view.layer.frame.size;
    gluPerspective(45.0f, (GLfloat)layerSize.width / (GLfloat)layerSize.height, 0.1f, 750.0f);

    // Modelview Matrix config
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // This next line is not really needed as it is the default for OpenGL ES
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_BLEND);

    // Enable depth testing
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
}

1 个答案:

答案 0 :(得分:0)

这是一个有点稀缺的信息。你是如何设置视口的?我最好的猜测是你错过了告诉你应用程序改变了方向的事件。您必须处理willRotateToInterfaceOrientation:duration:didRotateFromInterfaceOrientation:并在那里设置新的视口。 glRotate根本不是必需的。