本文整理汇总了C++中CCDirector::getOpenGLView方法的典型用法代码示例。如果您正苦于以下问题:C++ CCDirector::getOpenGLView方法的具体用法?C++ CCDirector::getOpenGLView怎么用?C++ CCDirector::getOpenGLView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCDirector
的用法示例。
在下文中一共展示了CCDirector::getOpenGLView方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
int CCApplication::Run()
{
IW_CALLSTACK("CCApplication::Run");
s3eBool quitRequested = 0;
bool bNeedQuit = false;
if (!applicationDidFinishLaunching() )
{
return 0;
}
uint64 updateTime = 0 ;
while (true)
{
updateTime = s3eTimerGetMs();
s3eDeviceYield(0);
s3eKeyboardUpdate();
s3ePointerUpdate();
ccAccelerationUpdate();
quitRequested = s3eDeviceCheckQuitRequest();
if( quitRequested) {
CCDirector* pDirector = CCDirector::sharedDirector();
// if opengl view has been released, delete the director.
if (pDirector->getOpenGLView() == NULL)
{
CC_SAFE_DELETE(pDirector);
bNeedQuit = true;
}
else
{
pDirector->end();
}
}
if( bNeedQuit ) {
break;
}
CCDirector::sharedDirector()->mainLoop();
while ((s3eTimerGetMs() - updateTime) < m_nAnimationInterval) {
int32 yield = (int32) (m_nAnimationInterval - (s3eTimerGetMs() - updateTime));
if (yield<0)
break;
s3eDeviceYield(yield);
}
}
return -1;
}
示例2: visit
//make the visible region
void VEScrollView::visit()
{
CCDirector *director = CCDirector::sharedDirector();
CCPoint pos = getPosition();
CCPoint pos2 = ccp(pos.x - m_viewSize.width*0.5f , pos.y - m_viewSize.height*0.5f);
// apply world transform
CCPoint wp = getParent()->convertToWorldSpace(pos2);
glEnable(GL_SCISSOR_TEST);
director->getOpenGLView()->setScissorInPoints(wp.x, wp.y, m_viewSize.width, m_viewSize.height);
CCLayer::visit();
glDisable(GL_SCISSOR_TEST);
}
示例3: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
pDirector->getOpenGLView()->setDesignResolutionSize(720, 1080, kResolutionShowAll);
// create a scene. it's an autorelease object
CCScene *pScene = TGameTitle::scene();
// run
pDirector->runWithScene(pScene);
return true;
}
示例4: visit
void PageScrollView::visit()
{
CCDirector *director = CCDirector::sharedDirector();
float n_width = viewPort.size.width ;
float n_height = viewPort.size.height ;
CCPoint pos = getPosition();
CCPoint pos2 = ccp(pos.x + viewPort.origin.x , pos.y+viewPort.origin.y);
// apply world transform
CCPoint temp = getParent()->convertToWorldSpace(pos2);
float x = temp.x;
float y = temp.y;
glEnable(GL_SCISSOR_TEST);
director->getOpenGLView()->setScissorInPoints(x, y, n_width, n_height);
CCLayer::visit();
glDisable(GL_SCISSOR_TEST);
}
示例5: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching()
{
CCLog("enter applicationDidFinishLaunching...");
TDCCTalkingDataGA::onStart("2B002F9CD724EB09730AF32CB4D909C3", "");
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// turn on display FPS
//pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
pDirector->getOpenGLView()->setDesignResolutionSize(320, 480, kResolutionExactFit);
// create a scene. it's an autorelease object
CCScene *pScene = AccountLayer::scene();
// run
pDirector->runWithScene(pScene);
CCLog("exit applicationDidFinishLaunching...");
return true;
}
示例6: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching()
{
preInitAPI();
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// turn on display FPS
//pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
//check for first launch
if( getSystem()->isFirstLaunch() ){
//clear update folder
CCLOG("-- FIRST LAUNCH --");
string docpath;
getSystem()->getDocumentPath(docpath);
string udpath = docpath + "update/";
getSystem()->removeDirectory(udpath);
string dypath = docpath + "dynamic.json";
getSystem()->removeDirectory(dypath);
}
CCDictionary *pSetup = CCDictionary::createWithContentsOfFile("Setup.plist");
string display;
{//set display
CCSize winSize = pDirector->getWinSize();
float aspectRatio = winSize.height/winSize.width;
CCArray *pResolutions = (CCArray*)pSetup->objectForKey("Resolutions");
if( pResolutions != NULL )
{
float fitScore = 10;
float fitWidth = 0;
float fitHeight = 0;
bool isFitable = false;
CCObject *pObj = NULL;
CCARRAY_FOREACH(pResolutions, pObj)
{
CCDictionary *pRes = (CCDictionary*)pObj;
CCString *pPath = (CCString*)pRes->objectForKey("path");
CCString *pWidth = (CCString*)pRes->objectForKey("width");
CCString *pHeight = (CCString*)pRes->objectForKey("height");
float width, height, score;
sscanf(pWidth->getCString(), "%f", &width);
sscanf(pHeight->getCString(), "%f", &height);
if (winSize.height == height) {
isFitable = true;
}
if( winSize.width >= width && winSize.height >= height )
{
score = 0;
float aspect = height/width;
float dist = fabsf(aspect - aspectRatio);
if( dist < fitScore )
{
fitScore = dist;
fitWidth = width;
fitHeight = height;
display = pPath->getCString();
}
}
else
{
score = 8;
}
}
if(fitWidth == 0 || fitHeight == 0)
{
fitWidth = 640;
fitHeight = 960;
display = "960/";
}
//set best resolution
if (isFitable){
pDirector->getOpenGLView()->setDesignResolutionSize(fitWidth, fitHeight, kResolutionShowAll);
}
getSystem()->setViewSizeHeight((int)fitHeight);
getSystem()->setViewSizeWidth((int)fitWidth);
CCLog("Resolution Adapter: %dx%d (%s) = %f", (int)fitWidth, (int)fitHeight, display.c_str(), fitScore);
}
示例7: enableMutliResolutionSupport
bool Assets::enableMutliResolutionSupport()
{
/// Multi resolution support BEFORE cocos2d-x 2.0.4
/// The correct resolution is enableds using setResourceDirectory which set the resource directory for the current device's resolution
/// Shared/common images to all resolutions are stored in the root resources (Resources/GameResources/textures)
/// See http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Mechanism_of_loading_resources
/****************************************************************************************************************
*
* Since 2.0.4, cocos2d-x introduced a new multi-resolution support
* http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support
* http://www.cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation
*
* Set the design resolution: width, height and policy
*
* - kResolutionExactFit -
* The entire application is visible in the specified area without trying to preserve the original aspect ratio.
* Distortion can occur, and the application may appear stretched or compressed.
*
* - kResolutionNoBorder -
* The entire application fills the specified area, without distortion but possibly with some cropping,
* while maintaining the original aspect ratio of the application.
*
* - kResolutionShowAll -
* The entire application is visible in the specified area without distortion while maintaining the original
* aspect ratio of the application. Borders can appear on two sides of the application.
****************************************************************************************************************/
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = pDirector->getOpenGLView();
CCFileUtils &fileUtils = *CCFileUtils::sharedFileUtils();
pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionExactFit);
CCSize frameSize = pEGLView->getFrameSize();
/// We select resource according to the frame's height.
/// If the resource size is different from design resolution size, you need to set contentScaleFactor.
/// We use the ratio of resource's height to the height of design resolution,
/// this can make sure that the resource's height could fit for the height of design resolution.
std::vector<std::string> resOrder = fileUtils.getSearchResolutionsOrder();
/// GPU max texture size
GLint maxTextureSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
CCLOG("GPU max texture size: %d", maxTextureSize);
bool scaledGraphics = false;
/// set the contentScaleFactor based on the ratio of WIDTH
if (frameSize.width > mediumResource.size.width && maxTextureSize >= 2048) {
CCLOG("Select LARGE (ipadhd) resource...");
resOrder.insert(resOrder.begin(), largeResource.directory);
/// pDirector->setContentScaleFactor(largeResource.size.width/designResolutionSize.width);
pDirector->setContentScaleFactor(4.f);
}
// if the frame's height is larger than the height of small resource size, select medium resource.
else if (frameSize.width > smallResource.size.width && maxTextureSize >= 1024) {
CCLOG("Select MEDIUM (hd) resource...");
resOrder.insert(resOrder.begin(), mediumResource.directory);
/// pDirector->setContentScaleFactor(mediumResource.size.width/designResolutionSize.width);
pDirector->setContentScaleFactor(2.f);
scaledGraphics = frameSize.width > mediumResource.size.width; // have scale down because of max texture size too small?
}
// if the frame's height is smaller than the height of medium resource size, select small resource.
else {
CCLOG("Select SMALL (sd) resource...");
resOrder.insert(resOrder.begin(), smallResource.directory);
/// pDirector->setContentScaleFactor(smallResource.size.width/designResolutionSize.width);
pDirector->setContentScaleFactor(1.f);
scaledGraphics = frameSize.width > smallResource.size.width; // have scale down because of max texture size too small?
}
/// Show an error message if we scaled down the graphics or the max texture size is too small
if (scaledGraphics || maxTextureSize < 512) {
CCLOGERROR("Unsupported max texture size: %d",maxTextureSize);
CCMessageBox("We detected graphics limitation which might prevent the app to work properly or to use HD graphics (max texture too small)", "ERROR");
}
/// Bug fix: the resolution directory must have a trailing slash (e.g. hd/ or sd/) or
/// CCFileUtils::getFullPathForDirectoryAndFilename() will not work correclty on iOS if
/// both search paths and resolution order are defined (missing slash between directory and filename).
/// We now use setSearchResolutionsOrder instead of addSearchResolutionsOrder because
/// addSearchResolutionsOrder simply add the string to the list of the resolution order without adding the trailing slash.
/// setSearchResolutionOrder takes care of adding the trailing slash if missing.
/// See. http://discuss.cocos2d-x.org/t/search-paths-and-resolutions-order-issue-on-ios/14424
fileUtils.setSearchResolutionsOrder(resOrder);
/// Set the font sizes
for (int i = 0; i < 4; i++)
smFontsSize[i] *= designResolutionSize.width / smallResource.size.width;
////////////////// Trace settings... /////////////////
#if COCOS2D_DEBUG > 0
/// Redirect standard output and error stream to file
//freopen(fileUtils.getWritablePath().append("cocos2d.log").c_str(), "a+", stdout);
//freopen(fileUtils.getWritablePath().append("cocos2d.log").c_str(), "a+", stderr);
/// In debug mode we change the default search path to the following.
//.........这里部分代码省略.........
示例8: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
pDirector->setProjection(kCCDirectorProjection2D);
pDirector->getOpenGLView()->setDesignResolutionSize(640, 960, ResolutionPolicy::kResolutionFixedWidth);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
// register lua engine
CCLuaEngine *pEngine = CCLuaEngine::defaultEngine();
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
CCLuaStack *pStack = pEngine->getLuaStack();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// load framework
pStack->loadChunksFromZip("res/framework_precompiled.zip");
// set script path
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
#else
// load framework
if (m_projectConfig.isLoadPrecompiledFramework())
{
const string precompiledFrameworkPath = SimulatorConfig::sharedDefaults()->getPrecompiledFrameworkPath();
pStack->loadChunksFromZip(precompiledFrameworkPath.c_str());
}
// set script path
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(m_projectConfig.getScriptFileRealPath().c_str());
#endif
size_t pos;
while ((pos = path.find_first_of("\\")) != std::string::npos)
{
path.replace(pos, 1, "/");
}
size_t p = path.find_last_of("/\\");
if (p != path.npos)
{
const string dir = path.substr(0, p);
pStack->addSearchPath(dir.c_str());
p = dir.find_last_of("/\\");
if (p != dir.npos)
{
pStack->addSearchPath(dir.substr(0, p).c_str());
}
}
string env = "__LUA_STARTUP_FILE__=\"";
env.append(path);
env.append("\"");
pEngine->executeString(env.c_str());
CCLOG("------------------------------------------------");
CCLOG("LOAD LUA FILE: %s", path.c_str());
CCLOG("------------------------------------------------");
pEngine->executeScriptFile(path.c_str());
return true;
}