GlView导致OpenGL错误 [英] GlView causes OpenGL error

查看:224
本文介绍了GlView导致OpenGL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的cocos2d.I使用uiview与cocos2d(3.0测试版)平台的游戏。我在自定义viewcontroller设置一个GLView。下面是我的代码。

I am new in cocos2d.I am making a gaming with uiview with cocos2d(3.0 Beta) platform.I set a GLView in custom viewcontroller. Below is my code.

 - (void)setupCocos2D {

        CCGLView *glView = [CCGLView viewWithFrame:self.view.bounds pixelFormat:kEAGLColorFormatRGB565 depthFormat:0];**

       glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

        [self.view insertSubview:glView atIndex:0];

       [[CCDirector sharedDirector] setView:glView];**

    }

它工作正常。但当我们把对象,然后给我以下内存工作。

It's working fine.But when we put on object then give me Following Memory worning.

OpenGL error 0x0506 in -[CCSprite draw] 544
OpenGL error 0x0502 in -[CCGLView swapBuffers] 287**



我想当我们调用([[CCDirector sharedDirector] setView:glView]) setView方法找不到CCDirector方法但是UIView方法。我无法访问CCDirector方法。方法我也不能调用AppDelegate类。

I think when we call ([[CCDirector sharedDirector] setView:glView]) setView method it's not find CCDirector method but UIView method.I can't Access the CCDirector method.Same Method I also can't call in AppDelegate class.

- (void)applicationWillTerminate:(UIApplication *)application {

    CCDirector *director = [CCDirector sharedDirector];

  //openGLView is now (setView in Latest version).It's Can't Access here.**

  [[director openGLView] removeFromSuperview];
    [director end];
}


推荐答案

您在setupCocos2D

You use below Code in setupCocos2D

 - (void)setupCocos2D
 {
    [[CCDirector sharedDirector] end];

    UIWindow *window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    [window_ setBackgroundColor:[UIColor whiteColor]];


    CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                                   pixelFormat:kEAGLColorFormatRGB565
                                   depthFormat:0
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

    director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

    director_.wantsFullScreenLayout = YES;

    // Display FSP and SPF
    [director_ setDisplayStats:NO];

    // set FPS at 60
    [director_ setAnimationInterval:1.0/60];

    // attach the openglView to the director
    [director_ setView:glView];

    // 2D projection
    [director_ setProjection:kCCDirectorProjection2D];



    //  [director setProjection:kCCDirectorProjection3D];

    // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
    if( ! [director_ enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change this setting at any time.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

    CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
    [sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
    [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
    [sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
    [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];    // Default on iPad RetinaDisplay is "-ipadhd"

    // Assume that PVR images have premultiplied alpha
    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];


 }

这篇关于GlView导致OpenGL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆