【问题标题】:app running on simulator but not in ipad..!应用程序在模拟器上运行,但不在 ipad 中..!
【发布时间】:2011-03-19 02:04:48
【问题描述】:

我遇到了一个非常奇怪的问题.....真的不知道如何解决这个问题..!!

我正在开发 iPad 应用程序,其中我正在为 ipad 使用 openGL 编程绘制一个 3d 立方体......一切都很好......我绘制了立方体并用不同的颜色给它着色......这一切我在模拟器上测试过,一切都很好。但是当我尝试在 iPad 上测试时,我的立方体正在绘制,但着色部分不起作用......!!!

提前感谢您的帮助..!!

【问题讨论】:

  • OpenGL 在模拟器和设备之间有一些细微的差别。发布您的绘图代码。
  • 这个drawProperties有什么不同吗? eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
  • 嘿,我发现了一个问题..实际上我使用的是 plist 文件进行着色。就像,当用户当时选择任何颜色时,我将该颜色值存储在 plist 中,然后在我的渲染器类中,我从 plist 中获取该颜色值。因此,当我在模拟器上工作时,一切都很好,但是当我在设备上调试相同的东西时,我无法从渲染器类中的 plist 中获取颜色值..!! plist 在实际设备中使用是否有一些限制?

标签: iphone opengl-es colors ipad ios-simulator


【解决方案1】:

更新:我的示例代码

MyViewController.h

    CubeView *cubeView;

MyViewController.m

    cubeView = [[CubeView alloc] initWithFrame:CGRectMake(250, 60, 450, 600)];
    cubeView.multipleTouchEnabled = YES;
    cubeView.backgroundColor = [UIColor clearColor];

    [self.view addSubview:cubeView];

CubeView.m

- (id)initWithCoder:(NSCoder*)coder
{    
    if ((self = [super initWithCoder:coder]))
    {

        // Get the layer
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

        eaglLayer.opaque = TRUE;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];

        [self setMultipleTouchEnabled:YES];
//      self.frame = CGRectMake(20, 30, 500, 500);
        renderer = nil;
        if (!renderer)
        {
            renderer = [[CubeRenderer alloc] init];

            if (!renderer)
            {
                [self release];
                return nil;
            }
        }

    }

    return self;
}

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Get the layer
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

        eaglLayer.opaque = TRUE;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
        [self setMultipleTouchEnabled:YES];
        renderer = nil;
        if (!renderer)
        {
            renderer = [[CubeRenderer alloc] init];

            if (!renderer)
            {
                [self release];
                return nil;
            }
        }

    }   
    return self;
}

CubeRenderer.m

- (id)init
{
    if ((self = [super init]))
    {
        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

        if (!context || ![EAGLContext setCurrentContext:context])
        {
            [self release];
            return nil;
        }

        currentCalculatedMatrix = CATransform3DIdentity;

        // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
        glGenFramebuffersOES(1, &defaultFramebuffer);
        glGenRenderbuffersOES(1, &colorRenderbuffer);
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
        glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
        glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);

    }

    return self;
}

    static const GLfloat cubeVertices[] = {

        -1.0, -1.0, 1.0,
        1.0, -1.0, 1.0,
        1.0, 1.0, 1.0,
        -1.0, 1.0, 1.0,

        -1.0, -1.0, -1.0,
        1.0, -1.0, -1.0,
        1.0, 1.0, -1.0,
        -1.0, 1.0, -1.0,
    };

    static const GLushort cubeIndicesFaceFront[] = {
        0, 1, 2, 3, 0
    };

    static const GLushort cubeIndicesFaceBack[] = {
        4, 5, 6, 7, 4
    };

    static const GLushort cubeIndicesFaceLeft[] = {
        0, 4, 7, 3, 0
    };

    static const GLushort cubeIndicesFaceRight[] = {
        1, 5, 6, 2, 1
    };

    static const GLushort cubeIndicesFaceTop[] = {
        3, 2, 6, 7, 3
    };

    static const GLushort cubeIndicesFaceBottom[] = {
        0, 1, 5, 4, 0
    };


    [EAGLContext setCurrentContext:context];


    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
        glOrthof(-2.0, 2.0, -2.0 * 480.0 / 320.0, 2.0 * 480.0 / 320.0, -3.0, 3.0);


        glMatrixMode(GL_MODELVIEW);

    glClear(GL_COLOR_BUFFER_BIT);

    glVertexPointer(3, GL_FLOAT, 0, cubeVertices);
    glEnableClientState(GL_VERTEX_ARRAY);


        glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeColorsBlueFace);
    glEnableClientState(GL_COLOR_ARRAY);
        glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceFront);
        //glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceFront);

        glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceBack);
    glEnableClientState(GL_COLOR_ARRAY);
        glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceBack);
        //glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceBack);

        glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceLeft);
    glEnableClientState(GL_COLOR_ARRAY);
        glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceLeft);
        //glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceLeft);

        glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceRight);
    glEnableClientState(GL_COLOR_ARRAY);
        glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceRight);
        //glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceRight);

        glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceTop);
    glEnableClientState(GL_COLOR_ARRAY);
        glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceTop);
        //glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceTop);

        glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceBottom);
    glEnableClientState(GL_COLOR_ARRAY);
        glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceBottom);
        //glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceBottom);

        glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
        [context presentRenderbuffer:GL_RENDERBUFFER_OES];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多