小编Ivo*_*ius的帖子

OpenGL深度测试问题

我在Mac上遇到了OpenGL的问题,我认为问题是深度测试.

所以,我的问题:从很远的我的场景:,而不是解释,我做了两个截图http://c0848462.cdn.cloudfiles.rackspacecloud.com/dd2267e27ad7d0206526b208cf2ea6910bcd00b4fa.jpg 而从近:HTTP://c0848462.cdn.cloudfiles .rackspacecloud.com/dd2267e27a561b5f02344dca57508dddce21d2315f.jpg

如果我不画绿色地板,一切看起来都很好.但是,像这样,它看起来只是令人敬畏.

以下是我用来设置Opengl的三个代码块:

+ (NSOpenGLPixelFormat*) defaultPixelFormat
{
    NSOpenGLPixelFormatAttribute attributes [] = {
        NSOpenGLPFAWindow,
        NSOpenGLPFADoubleBuffer, 
        NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, 
        (NSOpenGLPixelFormatAttribute)nil
    };
    return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
}


- (void) prepareOpenGL
{
    NSLog(@"Preparing OpenGL");
    glClearColor( 0.0f, 0.0f, 1.0f, 1.0f );             

    glEnable(GL_TEXTURE_2D);                           

    glClearDepth(1);                                  
    glEnable(GL_DEPTH_TEST);                          

    glEnable (GL_BLEND);                              
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

- (void)reshape
{
    NSLog(@"Reshaping view");
    glViewport( 0, 0, (GLsizei)[self bounds].size.width, (GLsizei)[self bounds].size.height);
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45.0, [self bounds].size.width / [self bounds].size.height, 0.1f /*Nearest render distance*/, 5000.0 /*Render …
Run Code Online (Sandbox Code Playgroud)

opengl objective-c depth nsopenglview

2
推荐指数
1
解决办法
641
查看次数

标签 统计

depth ×1

nsopenglview ×1

objective-c ×1

opengl ×1