Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLView -> GLViewImpl refactor in 3.3 #8546

Closed
slackmoehrle opened this issue Oct 1, 2014 · 2 comments
Closed

GLView -> GLViewImpl refactor in 3.3 #8546

slackmoehrle opened this issue Oct 1, 2014 · 2 comments

Comments

@slackmoehrle
Copy link
Contributor

In 3.2

We used to do this in AppController.mm, RootViewController.mm, AppDelegate.cpp:

// AppController.mm, RootViewController.mm
#import "platform/ios/CCEAGLView.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [snip] 
cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView);

}

bool AppDelegate::applicationDidFinishLaunching() 
{
auto director = Director::getInstance();
auto glview = director->getOpenGLView();

if(!glview) {
        glview = GLView::create("My Game");
        director->setOpenGLView(glview);
 }

in 3.3 GLView has been refactored in some manner and now what needs to be done:

// AppController.mm, RootViewController.mm
#import "platform/ios/CCEAGLView-ios.h" // <- addition of -ios

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [snip] 
cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); // <- addition of Impl

}

bool AppDelegate::applicationDidFinishLaunching() 
{
auto director = Director::getInstance();
auto glview = director->getOpenGLView();

if(!glview) {
        glview = GLViewImpl::create("My Game");  // <- addition of Impl
        director->setOpenGLView(glview);
 }

Also, using cocos command like tool:

cocos new MyGame2 -p com.MyCompany.MyGame2 -l cpp -d .

and trying to compile a project on IOS it does not compile by default, without making the changes above.

Forum thread: http://discuss.cocos2d-x.org/t/glview-glviewimpl-change-in-3-3/17408

@minggo
Copy link
Contributor

minggo commented Oct 8, 2014

We refactored like this to let developers can create their own GLView. For example, cocos studio needs their own GLView.

Default GLView named GLViewImpl, if you want to your own GLView, you should need another name, such as CSGLView, then you can create and set it to Director.

That's why we can not just have a class named GLView, because we have to separate some functions into subclass to let it configurable.

@minggo minggo closed this as completed Oct 13, 2014
@Avanteobaidi
Copy link

I have Added Impl but still got problem with my GLVie, this is my appDelegate to have a look :
#include "AppDelegate.h"
#include "SplashScene.h"

// is the game landscape or portrait (true for landscape and false for portrait)
#define IS_LANDSCAPE false

USING_NS_CC;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::create("My Game");
director->setOpenGLView(glview);
}

// turn on display FPS
director->setDisplayStats(true);

// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);

auto fileUtils = FileUtils::getInstance( );
auto screenSize = glview->getFrameSize( );
std::vector<std::string> resDirOrders;

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// check which assets the devices requires
if ( 2048 == screenSize.width || 2048 == screenSize.height ) // retina iPad
{
resDirOrders.push_back( "ipadhd" );
resDirOrders.push_back( "ipad" );
resDirOrders.push_back( "iphonehd5" );
resDirOrders.push_back( "iphonehd" );
resDirOrders.push_back( "iphone" );

    if ( true == IS_LANDSCAPE )
    {
        glview->setDesignResolutionSize( 2048, 1536, ResolutionPolicy::NO_BORDER );
    }
    else
    {
        glview->setDesignResolutionSize( 1536, 2048, ResolutionPolicy::NO_BORDER );
    }
}
else if ( 1024 == screenSize.width || 1024 == screenSize.height ) // non retina iPad
{
    resDirOrders.push_back( "ipad" );
    resDirOrders.push_back( "iphonehd5" );
    resDirOrders.push_back( "iphonehd" );
    resDirOrders.push_back( "iphone" );

    if ( true == IS_LANDSCAPE )
    {
        glview->setDesignResolutionSize( 1024, 768, ResolutionPolicy::NO_BORDER );
    }
    else
    {
        glview->setDesignResolutionSize( 768, 1024, ResolutionPolicy::NO_BORDER );
    }
}
else if ( 1136 == screenSize.width || 1136 == screenSize.height ) // retina iPhone (5 and 5S)
{
    resDirOrders.push_back("iphonehd5");
    resDirOrders.push_back("iphonehd");
    resDirOrders.push_back("iphone");

    if ( true == IS_LANDSCAPE )
    {
        glview->setDesignResolutionSize( 1136, 640, ResolutionPolicy::NO_BORDER );
    }
    else
    {
        glview->setDesignResolutionSize( 640, 1136, ResolutionPolicy::NO_BORDER );
    }
}
else if ( 960 == screenSize.width || 960 == screenSize.height ) // retina iPhone (4 and 4S)
{
    resDirOrders.push_back( "iphonehd" );
    resDirOrders.push_back( "iphone" );

    if ( true == IS_LANDSCAPE )
    {
        glview->setDesignResolutionSize( 960, 640, ResolutionPolicy::NO_BORDER );
    }
    else
    {
        glview->setDesignResolutionSize( 640, 960, ResolutionPolicy::NO_BORDER );
    }
}
else // non retina iPhone and Android devices
{
    if ( 1080 < screenSize.width && 1080 < screenSize.height ) // android devices that have a high resolution
    {
        resDirOrders.push_back( "iphonehd" );
        resDirOrders.push_back( "iphone" );

        if ( true == IS_LANDSCAPE )
        {
            glview->setDesignResolutionSize( 960, 640, ResolutionPolicy::NO_BORDER );
        }
        else
        {
            glview->setDesignResolutionSize( 640, 960, ResolutionPolicy::NO_BORDER );
        }
    }
    else // non retina iPhone and Android devices with lower resolutions
    {
        resDirOrders.push_back( "iphone" );

        if ( true == IS_LANDSCAPE )
        {
            glview->setDesignResolutionSize( 480, 320, ResolutionPolicy::NO_BORDER );
        }
        else
        {
            glview->setDesignResolutionSize( 320, 480, ResolutionPolicy::NO_BORDER );
        }
    }
}

#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
resDirOrders.push_back( "ipad" );
resDirOrders.push_back( "iphonehd5" );
resDirOrders.push_back( "iphonehd" );
resDirOrders.push_back( "iphone" );

if ( true == IS_LANDSCAPE )
{
    glview->setFrameSize( 1024, 768 );
    glview->setDesignResolutionSize( 1024, 768, ResolutionPolicy::NO_BORDER );
}
else
{
    glview->setFrameSize( 768, 1024 );
    glview->setDesignResolutionSize( 768, 1024, ResolutionPolicy::NO_BORDER );
}

#endif

fileUtils->setSearchPaths(resDirOrders);

// create a scene. it's an autorelease object
auto scene = SplashScene::createScene();

// run
director->runWithScene(scene);

return true;

}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
Director::getInstance()->stopAnimation();

// if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic();

}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
Director::getInstance()->startAnimation();

// if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants