2010-07-21 59 views
0

A'm stucked一個很奇怪的問題.....真的不能得到如何走出與.. !!應用在模擬器中運行而不是在ipad ..!

我正在開發iPad應用中,我畫用OpenGL編程爲iPad一個3D立方體....一切都好....我用不同的顏色繪製的立方體,也有色這....這一切我在模擬器上測試過的東西,一切都很棒。但是當我試圖在iPad上測試時,我的立方體正在繪製,但着色部分不起作用... !!!

預先感謝幫助.. !!

+1

的OpenGL具有模擬器和設備之間的一些細微差異。發佈您的繪圖代碼。 – 2010-07-21 15:46:28

+0

這個drawProperties有什麼區別嗎? eaglLayer.drawableProperties = [NSDictionary的dictionaryWithObjectsAndKeys: [NSNumber的numberWithBool:FALSE],kEAGLDrawablePropertyRetainedBacking,kEAGLColorFormatRGBA8,kEAGLDrawablePropertyColorFormat,零]。 – rohanparekh 2010-07-22 04:11:51

+0

嘿,我發現我是用plist文件着色一個problem..actually。就像,當用戶選擇在那個時候我存儲的plist該顏色值,然後在我的渲染器類我是以顏色的值從plist中的任何顏色。所以當我在模擬器上工作時一切都很好,但是當我在設備上調試同樣的東西時,我無法從渲染器類的plist中獲得顏色的值。 plist是否有一些限制在實際設備中使用? – rohanparekh 2010-07-23 03:34:47

回答

0

UPDATE:我的示例代碼

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]; 
相關問題