bool GLView::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
{
    setViewName(viewName);
    setFrameSize(rect.size.width, rect.size.height);
    setFrameZoomFactor(frameZoomFactor);
    
    glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
    
    _mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor,
                                   _screenSize.height * _frameZoomFactor,
                                   _viewName.c_str(),
                                   _primaryMonitor,
                                   NULL);
    glfwMakeContextCurrent(_mainWindow);
    
    int w, h;
    glfwGetWindowSize(_mainWindow, &w, &h);
    int frameBufferW, frameBufferH;
    glfwGetFramebufferSize(_mainWindow, &frameBufferW, &frameBufferH);
    
    if (frameBufferW == 2 * w && frameBufferH == 2 * h)
    {
        _isRetina = true;
        setFrameZoomFactor(frameZoomFactor * 2);
        glfwSetWindowSize(_mainWindow, rect.size.width/2 * _frameZoomFactor, rect.size.height/2 * _frameZoomFactor);
    }
    
    glfwSetMouseButtonCallback(_mainWindow, GLViewEventHandler::onGLFWMouseCallBack);
    glfwSetCursorPosCallback(_mainWindow, GLViewEventHandler::onGLFWMouseMoveCallBack);
    glfwSetScrollCallback(_mainWindow, GLViewEventHandler::onGLFWMouseScrollCallback);
    glfwSetCharCallback(_mainWindow, GLViewEventHandler::onGLFWCharCallback);
    glfwSetKeyCallback(_mainWindow, GLViewEventHandler::onGLFWKeyCallback);
    glfwSetWindowPosCallback(_mainWindow, GLViewEventHandler::onGLFWWindowPosCallback);
    glfwSetFramebufferSizeCallback(_mainWindow, GLViewEventHandler::onGLFWframebuffersize);
	glfwSetWindowSizeCallback(_mainWindow, GLViewEventHandler::OnGLFWWindowSizeFunCallback);
    // check OpenGL version at first
    const GLubyte* glVersion = glGetString(GL_VERSION);
    
    if ( atof((const char*)glVersion) < 1.5 )
    {
        char strComplain[256] = {0};
        sprintf(strComplain,
                "OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.",
                glVersion);
        MessageBox(strComplain, "OpenGL version too old");
        return false;
    }
    
    initGlew();

    // Enable point size by default.
    glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
    
    return true;
}
Exemple #2
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("DontCrash", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("DontCrash");
#endif
        director->setOpenGLView(glview);
       
    }
    
    glview->setDesignResolutionSize(designResolutionSize.width  ,designResolutionSize.height ,ResolutionPolicy::SHOW_ALL);
    
    glview->setFrameZoomFactor(0.5);

    // 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);
    

    register_all_packages();

    // create a scene. it's an autorelease object
//    auto scene = Controller::getInstance()->createScene();
    auto scene = EnterScene::create();
    // run
    director->runWithScene(scene);

    return true;
}
bool AppDelegate::applicationDidFinishLaunching() {

    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
	if (!glview) {
		glview = GLViewImpl::create("Monkey Adventure");
		director->setOpenGLView(glview);
		// For Android 
		glview->setFrameSize(480,800);
		
		// For IOS
		//glview->setFrameSize(320, 480);
		//glview->setFrameSize(640,960);
		//glview->setFrameSize(640, 1136);
		//glview->setFrameSize(750, 1334);
	//	glview->setFrameSize(1242, 2208);
		//glview->setFrameSize(480, 800);

		glview->setFrameZoomFactor(.8f);
	}
	director->setDisplayStats(false);
	director->getOpenGLView()->setDesignResolutionSize(480, 800, ResolutionPolicy::FIXED_HEIGHT);
    register_all_packages();

    auto scene = FlashScene::createScene();
	director->runWithScene(scene);
    return true;
}
Exemple #4
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        //glview = GLView::create("My Game");
		glview = GLView::createWithRect("PlaneGame",Rect(0,0,480,800));
		glview->setFrameZoomFactor(0.8f); 
		director->setOpenGLView(glview);
		glview->setDesignResolutionSize(480,800,ResolutionPolicy::NO_BORDER);
    }

    // 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);

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

    // run
    director->runWithScene(scene);

    return true;
}
Exemple #5
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("bonimei", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
        //glview->setFrameSize(860, 640);
#else
        glview = GLViewImpl::create("bonimei");
#endif
        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);

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::FIXED_HEIGHT);
    glview->setFrameZoomFactor(0.6);
//    Size frameSize = glview->getFrameSize();
//    // if the frame's height is larger than the height of medium size.
//    if (frameSize.height > mediumResolutionSize.height)
//    {        
//        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
//    }
//    // if the frame's height is larger than the height of small size.
//    else if (frameSize.height > smallResolutionSize.height)
//    {        
//        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
//    }
//    // if the frame's height is smaller than the height of medium size.
//    else
//    {        
//        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
//    }
    auto fileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths;
    searchPaths.push_back("res/");
    searchPaths.push_back(GResource::getInstance()->getWritePath());
    searchPaths.push_back(GResource::getInstance()->getWriteResPath());
    searchPaths.push_back(GResource::getInstance()->getTempPath());
    searchPaths.push_back(GResource::getInstance()->getCachePath());
    fileUtils->setSearchPaths(searchPaths);

    register_all_packages();

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

    // run
    director->runWithScene(scene);

    return true;
}
Exemple #6
0
bool AppDelegate::applicationDidFinishLaunching() {
	auto designSize = Size(640, 960);

	// initialize director
	auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	if(!glview) {
		glview = GLView::createWithRect("My Game", Rect(0, 0, 640, 960));
		director->setOpenGLView(glview);
		glview->setFrameSize(640, 960);
		glview->setFrameZoomFactor(0.8);
	}

	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);

	glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_WIDTH);


	auto wisize = director->getWinSize();

	director->setContentScaleFactor(1136/designSize.height);

	// create a scene. it's an autorelease object
	//auto scene = View::Hall::createScene();
	//auto scene = View::GameLayer::creatScene();
	// run

	auto scene = View::LoginBar::createScene();
	
	//View::_table.init();
	//auto scene = View::Table::creatScene();

	//std::vector<View::PlayerInfo> pInfo;
	//View::PlayerInfo pi;
	//pi.chairid = 0;
	//pi.allchips = 1000;
	//pi.nickname = "xiaocelao";
	//for (int i = 0; i < 3; ++i)
	//{
	//	pInfo.push_back(pi);
	//}
	//View::_table.onPlayerEnter(pInfo);

	//auto scene = View::GameLayer::creatScene();

	Director::getInstance()->runWithScene(scene); 

	return true;
}
Exemple #7
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();

    if(!glview) {
        glview = GLViewImpl::create("Goku Fight");
        director->setOpenGLView(glview);
		//glview->setFrameSize(320, 480);
		//glview->setFrameSize(640,960);
		//glview->setFrameSize(640, 1136);
		//glview->setFrameSize(750, 1334);
		glview->setFrameSize(1242, 2208);
		//glview->setFrameSize(480, 800);

		glview->setFrameZoomFactor(.2f);
    }

	CCLOG("FrameSize : %f  %f", Director::getInstance()->getOpenGLView()->getFrameSize().width, Director::getInstance()->getOpenGLView()->getFrameSize().height);

    // turn on display FPS
    director->setDisplayStats(false);
	director->getOpenGLView()->setDesignResolutionSize(R::Constants::WIDTH_SCREEN, R::Constants::HEIGHT_SCREEN, ResolutionPolicy::FIXED_HEIGHT);
	
	R::Constants::WIDTH_SCREEN = Director::getInstance()->getWinSize().width;

	/*Size winSize = Size(R::Constants::WIDTH_SCREEN, 800);
	Size frameSize = glview->getFrameSize();
	float widthRate = frameSize.width / winSize.width;
	float heightRate = frameSize.height / winSize.height;
	if (widthRate > heightRate)
	{
		glview->setDesignResolutionSize(winSize.width,
			winSize.height*heightRate / widthRate, ResolutionPolicy::FIXED_HEIGHT);
	}
	else
	{
		glview->setDesignResolutionSize(winSize.width*widthRate / heightRate, winSize.height,
			ResolutionPolicy::FIXED_HEIGHT);
	}*/



    director->setAnimationInterval(1.0 / 60);

    register_all_packages();

    //auto scene = HelloWorld::createScene();
	auto scene = StartScreen::createScene();
    director->runWithScene(scene);

    return true;
}
Exemple #8
0
void GLViewEventHandler::onGLFWframebuffersize(GLFWwindow* window, int w, int h)
{
    auto view = Director::getInstance()->getOpenGLView();

    float frameSizeW = view->getFrameSize().width;
    float frameSizeH = view->getFrameSize().height;
    float factorX = frameSizeW / w * view->getFrameZoomFactor();
    float factorY = frameSizeH / h * view->getFrameZoomFactor();;
    
    if (fabs(factorX - 0.5f) < FLT_EPSILON && fabs(factorY - 0.5f) < FLT_EPSILON )
    {
        view->_isRetina = true;
        view->setFrameZoomFactor(2.0f * view->getFrameZoomFactor());
        glfwSetWindowSize(window, static_cast<int>(frameSizeW * 0.5f * view->getFrameZoomFactor()) , static_cast<int>(frameSizeH * 0.5f * view->getFrameZoomFactor()));
    }
    else if(fabs(factorX - 2.0f) < FLT_EPSILON && fabs(factorY - 2.0f) < FLT_EPSILON)
    {
        view->_isRetina = false;
        view->setFrameZoomFactor(0.5f * view->getFrameZoomFactor());
        glfwSetWindowSize(window, static_cast<int>(frameSizeW * view->getFrameZoomFactor()), static_cast<int>(frameSizeH * view->getFrameZoomFactor()));
    }
}
Exemple #9
0
void SimulatorWin::setupUI()
{
    auto menuBar = player::PlayerProtocol::getInstance()->getMenuService();

    // FILE
    menuBar->addItem("FILE_MENU", tr("File"));
    menuBar->addItem("EXIT_MENU", tr("Exit"), "FILE_MENU");

    // VIEW
    menuBar->addItem("VIEW_MENU", tr("View"));
    SimulatorConfig *config = SimulatorConfig::getInstance();
    int current = config->checkScreenSize(_project.getFrameSize());
    for (int i = 0; i < config->getScreenSizeCount(); i++)
    {
        SimulatorScreenSize size = config->getScreenSize(i);
        std::stringstream menuId;
        menuId << "VIEWSIZE_ITEM_MENU_" << i;
        auto menuItem = menuBar->addItem(menuId.str(), size.title.c_str(), "VIEW_MENU");

        if (i == current)
        {
            menuItem->setChecked(true);
        }
    }

    menuBar->addItem("DIRECTION_MENU_SEP", "-", "VIEW_MENU");
    menuBar->addItem("DIRECTION_PORTRAIT_MENU", tr("Portrait"), "VIEW_MENU")
        ->setChecked(_project.isPortraitFrame());
    menuBar->addItem("DIRECTION_LANDSCAPE_MENU", tr("Landscape"), "VIEW_MENU")
        ->setChecked(_project.isLandscapeFrame());

    menuBar->addItem("VIEW_SCALE_MENU_SEP", "-", "VIEW_MENU");
    std::vector<player::PlayerMenuItem*> scaleMenuVector;
    auto scale100Menu = menuBar->addItem("VIEW_SCALE_MENU_100", tr("Zoom Out").append(" (100%)"), "VIEW_MENU");
    auto scale75Menu = menuBar->addItem("VIEW_SCALE_MENU_75", tr("Zoom Out").append(" (75%)"), "VIEW_MENU");
    auto scale50Menu = menuBar->addItem("VIEW_SCALE_MENU_50", tr("Zoom Out").append(" (50%)"), "VIEW_MENU");
    auto scale25Menu = menuBar->addItem("VIEW_SCALE_MENU_25", tr("Zoom Out").append(" (25%)"), "VIEW_MENU");
    int frameScale = int(_project.getFrameScale() * 100);
    if (frameScale == 100)
    {
        scale100Menu->setChecked(true);
    }
    else if (frameScale == 75)
    {
        scale75Menu->setChecked(true);
    }
    else if (frameScale == 50)
    {
        scale50Menu->setChecked(true);
    }
    else if (frameScale == 25)
    {
        scale25Menu->setChecked(true);
    }
    else
    {
        scale100Menu->setChecked(true);
    }

    scaleMenuVector.push_back(scale100Menu);
    scaleMenuVector.push_back(scale75Menu);
    scaleMenuVector.push_back(scale50Menu);
    scaleMenuVector.push_back(scale25Menu);

    menuBar->addItem("REFRESH_MENU_SEP", "-", "VIEW_MENU");
    menuBar->addItem("REFRESH_MENU", tr("Refresh"), "VIEW_MENU");

    HWND &hwnd = _hwnd;
    ProjectConfig &project = _project;
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    dispatcher->addEventListenerWithFixedPriority(EventListenerCustom::create("APP.EVENT", [&project, &hwnd, scaleMenuVector](EventCustom* event){
        auto menuEvent = dynamic_cast<AppEvent*>(event);
        if (menuEvent)
        {
            rapidjson::Document dArgParse;
            dArgParse.Parse<0>(menuEvent->getDataString().c_str());
            if (dArgParse.HasMember("name"))
            {
                string strcmd = dArgParse["name"].GetString();

                if (strcmd == "menuClicked")
                {
                    player::PlayerMenuItem *menuItem = static_cast<player::PlayerMenuItem*>(menuEvent->getUserData());
                    if (menuItem)
                    {
                        if (menuItem->isChecked())
                        {
                            return;
                        }

                        string data = dArgParse["data"].GetString();
                        auto player = player::PlayerProtocol::getInstance();

                        if ((data == "CLOSE_MENU") || (data == "EXIT_MENU"))
                        {
                            player->quit();
                        }
                        else if (data == "REFRESH_MENU")
                        {
                            player->relaunch();
                        }
                        else if (data.find("VIEW_SCALE_MENU_") == 0) // begin with VIEW_SCALE_MENU_
                        {
                            string tmp = data.erase(0, strlen("VIEW_SCALE_MENU_"));
                            float scale = atof(tmp.c_str()) / 100.0f;
                            project.setFrameScale(scale);

                            auto glview = static_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView());
                            glview->setFrameZoomFactor(scale);

                            // update scale menu state
                            for (auto &it : scaleMenuVector)
                            {
                                it->setChecked(false);
                            }
                            menuItem->setChecked(true);

                            // update window size
                            RECT rect;
                            GetWindowRect(hwnd, &rect);
                            MoveWindow(hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE);
                        
                            // fix: can not update window on some windows system 
                            ::SendMessage(hwnd, WM_MOVE, NULL, NULL);
                        }
                        else if (data.find("VIEWSIZE_ITEM_MENU_") == 0) // begin with VIEWSIZE_ITEM_MENU_
                        {
                            string tmp = data.erase(0, strlen("VIEWSIZE_ITEM_MENU_"));
                            int index = atoi(tmp.c_str());
                            SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(index);

                            if (project.isLandscapeFrame())
                            {
                                std::swap(size.width, size.height);
                            }

                            project.setFrameSize(cocos2d::Size(size.width, size.height));
                            project.setWindowOffset(cocos2d::Vec2(player->getPositionX(), player->getPositionY()));
                            player->openProjectWithProjectConfig(project);
                        }
                        else if (data == "DIRECTION_PORTRAIT_MENU")
                        {
                            project.changeFrameOrientationToPortait();
                            player->openProjectWithProjectConfig(project);
                        }
                        else if (data == "DIRECTION_LANDSCAPE_MENU")
                        {
                            project.changeFrameOrientationToLandscape();
                            player->openProjectWithProjectConfig(project);
                        }
                    }
                }
            }
        }
    }), 1);

    AppDelegate *app = _app;
    auto listener = EventListenerCustom::create(kAppEventDropName, [&project, app](EventCustom* event)
    {
        AppEvent *dropEvent = dynamic_cast<AppEvent*>(event);
        if (dropEvent)
        {
            string dirPath = dropEvent->getDataString() + "/";
            string configFilePath = dirPath + CONFIG_FILE;

            if (FileUtils::getInstance()->isDirectoryExist(dirPath) &&
                FileUtils::getInstance()->isFileExist(configFilePath))
            {
                // parse config.json
                ConfigParser::getInstance()->readConfig(configFilePath);

                project.setProjectDir(dirPath);
                project.setScriptFile(ConfigParser::getInstance()->getEntryFile());
                project.setWritablePath(dirPath);

                app->setProjectConfig(project);
                app->reopenProject();
            }
        }
    });
    dispatcher->addEventListenerWithFixedPriority(listener, 1);
}
Exemple #10
0
bool EGLView::init(const char* viewName, float width, float height, float frameZoomFactor)
{
    if(nullptr != _mainWindow) return true;

    setViewName(viewName);
    setFrameSize(width, height);
    setFrameZoomFactor(frameZoomFactor);

    glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
   _mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr);
    glfwMakeContextCurrent(_mainWindow);
    
    glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
    
    glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
    glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
    glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
    glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
    glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::OnGLFWWindowPosCallback);

    // check OpenGL version at first
    const GLubyte* glVersion = glGetString(GL_VERSION);
    CCLOG("OpenGL version = %s", glVersion);
    
    if ( atof((const char*)glVersion) < 1.5 )
    {
        char strComplain[256] = {0};
        sprintf(strComplain,
                "OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.",
                glVersion);
        MessageBox(strComplain, "OpenGL version too old");
        return false;
    }
    
    GLenum GlewInitResult = glewInit();
    if (GLEW_OK != GlewInitResult)
    {
        MessageBox((char *)glewGetErrorString(GlewInitResult), "OpenGL error");
        return false;
    }
    
    if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
    {
        log("Ready for GLSL");
    }
    else
    {
        log("Not totally ready :(");
    }
    
    if (glewIsSupported("GL_VERSION_2_0"))
    {
       log("Ready for OpenGL 2.0");
    }
    else
    {
        log("OpenGL 2.0 not supported");
    }
    
//    if(glew_dynamic_binding() == false)
//    {
//        MessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error");
//        return false;
//    }
//    
    // Enable point size by default on windows.
    glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
    
    return true;
}