本文整理汇总了C++中Director::getWinSizeInPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ Director::getWinSizeInPixels方法的具体用法?C++ Director::getWinSizeInPixels怎么用?C++ Director::getWinSizeInPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Director
的用法示例。
在下文中一共展示了Director::getWinSizeInPixels方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onBegin
void RenderTexture::onBegin()
{
//
Director *director = Director::getInstance();
Size size = director->getWinSizeInPixels();
kmGLGetMatrix(KM_GL_PROJECTION, &_oldProjMatrix);
kmGLMatrixMode(KM_GL_PROJECTION);
kmGLLoadMatrix(&_projectionMatrix);
kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix);
kmGLMatrixMode(KM_GL_MODELVIEW);
kmGLLoadMatrix(&_transformMatrix);
const Size& texSize = _texture->getContentSizeInPixels();
if(!_keepMatrix)
{
director->setProjection(director->getProjection());
// Calculate the adjustment ratios based on the old and new projections
float widthRatio = size.width / texSize.width;
float heightRatio = size.height / texSize.height;
kmMat4 orthoMatrix;
kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio,
(float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
kmGLMultMatrix(&orthoMatrix);
}
//calculate viewport
{
Rect viewport;
viewport.size.width = _fullviewPort.size.width;
viewport.size.height = _fullviewPort.size.height;
float viewPortRectWidthRatio = float(viewport.size.width)/_fullRect.size.width;
float viewPortRectHeightRatio = float(viewport.size.height)/_fullRect.size.height;
viewport.origin.x = (_fullRect.origin.x - _rtTextureRect.origin.x) * viewPortRectWidthRatio;
viewport.origin.y = (_fullRect.origin.y - _rtTextureRect.origin.y) * viewPortRectHeightRatio;
//glViewport(_fullviewPort.origin.x, _fullviewPort.origin.y, (GLsizei)_fullviewPort.size.width, (GLsizei)_fullviewPort.size.height);
glViewport(viewport.origin.x, viewport.origin.y, (GLsizei)texSize.width, (GLsizei)texSize.height);
}
// Adjust the orthographic projection and viewport
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
//TODO move this to configration, so we don't check it every time
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
*/
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
{
// -- bind a temporary texture so we can clear the render buffer without losing our texture
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0);
CHECK_GL_ERROR_DEBUG();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
}
}
示例2: beforeDraw
void GridBase::beforeDraw(void)
{
// save projection
Director *director = Director::getInstance();
_directorProjection = director->getProjection();
// 2d projection
// [director setProjection:Director::Projection::_2D];
set2DProjection();
Size size = director->getWinSizeInPixels();
glViewport(0, 0, (GLsizei)(size.width), (GLsizei)(size.height) );
_grabber->beforeRender(_texture);
}
示例3:
void GridBase::set2DProjection()
{
Director *director = Director::getInstance();
Size size = director->getWinSizeInPixels();
director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Mat4 orthoMatrix;
Mat4::createOrthographicOffCenter(0, size.width, 0, size.height, -1, 1, &orthoMatrix);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix);
director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
GL::setProjectionMatrixDirty();
}
示例4: glViewport
void GridBase::set2DProjection()
{
Director *director = Director::getInstance();
Size size = director->getWinSizeInPixels();
glViewport(0, 0, (GLsizei)(size.width), (GLsizei)(size.height) );
kmGLMatrixMode(KM_GL_PROJECTION);
kmGLLoadIdentity();
kmMat4 orthoMatrix;
kmMat4OrthographicProjection(&orthoMatrix, 0, size.width, 0, size.height, -1, 1);
kmGLMultMatrix( &orthoMatrix );
kmGLMatrixMode(KM_GL_MODELVIEW);
kmGLLoadIdentity();
GL::setProjectionMatrixDirty();
}
示例5: begin
void RenderTexture::begin()
{
kmGLMatrixMode(KM_GL_PROJECTION);
kmGLPushMatrix();
kmGLGetMatrix(KM_GL_PROJECTION, &_projectionMatrix);
kmGLMatrixMode(KM_GL_MODELVIEW);
kmGLPushMatrix();
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
if(!_keepMatrix)
{
Director *director = Director::getInstance();
director->setProjection(director->getProjection());
const Size& texSize = _texture->getContentSizeInPixels();
// Calculate the adjustment ratios based on the old and new projections
Size size = director->getWinSizeInPixels();
float widthRatio = size.width / texSize.width;
float heightRatio = size.height / texSize.height;
kmMat4 orthoMatrix;
kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio,
(float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
kmGLMultMatrix(&orthoMatrix);
}
_groupCommand.init(_globalZOrder);
Renderer *renderer = Director::getInstance()->getRenderer();
renderer->addCommand(&_groupCommand);
renderer->pushGroup(_groupCommand.getRenderQueueID());
_beginCommand.init(_globalZOrder);
_beginCommand.func = CC_CALLBACK_0(RenderTexture::onBegin, this);
Director::getInstance()->getRenderer()->addCommand(&_beginCommand);
}
示例6: begin
void RenderTexture::begin()
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
_projectionMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_transformMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
if(!_keepMatrix)
{
director->setProjection(director->getProjection());
const Size& texSize = _texture->getContentSizeInPixels();
// Calculate the adjustment ratios based on the old and new projections
Size size = director->getWinSizeInPixels();
float widthRatio = size.width / texSize.width;
float heightRatio = size.height / texSize.height;
Mat4 orthoMatrix;
Mat4::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix);
}
_groupCommand.init(_globalZOrder);
Renderer *renderer = Director::getInstance()->getRenderer();
renderer->addCommand(&_groupCommand);
renderer->pushGroup(_groupCommand.getRenderQueueID());
_beginCommand.init(_globalZOrder);
_beginCommand.func = CC_CALLBACK_0(RenderTexture::onBegin, this);
Director::getInstance()->getRenderer()->addCommand(&_beginCommand);
}
示例7: initWithSize
bool GridBase::initWithSize(const cocos2d::Size &gridSize, const cocos2d::Rect &rect)
{
Director *director = Director::getInstance();
Size s = director->getWinSizeInPixels();
auto POTWide = ccNextPOT((unsigned int)s.width);
auto POTHigh = ccNextPOT((unsigned int)s.height);
// we only use rgba8888
Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888;
auto dataLen = POTWide * POTHigh * 4;
void *data = calloc(dataLen, 1);
if (! data)
{
CCLOG("cocos2d: Grid: not enough memory.");
this->release();
return false;
}
Texture2D *texture = new (std::nothrow) Texture2D();
texture->initWithData(data, dataLen, format, POTWide, POTHigh, s);
free(data);
if (! texture)
{
CCLOG("cocos2d: Grid: error creating texture");
return false;
}
initWithSize(gridSize, texture, false, rect);
texture->release();
return true;
}
示例8: initWithSize
bool GridBase::initWithSize(const Size& gridSize)
{
Director *pDirector = Director::getInstance();
Size s = pDirector->getWinSizeInPixels();
unsigned long POTWide = ccNextPOT((unsigned int)s.width);
unsigned long POTHigh = ccNextPOT((unsigned int)s.height);
// we only use rgba8888
Texture2DPixelFormat format = kTexture2DPixelFormat_RGBA8888;
void *data = calloc((int)(POTWide * POTHigh * 4), 1);
if (! data)
{
CCLOG("cocos2d: Grid: not enough memory.");
this->release();
return false;
}
Texture2D *pTexture = new Texture2D();
pTexture->initWithData(data, format, POTWide, POTHigh, s);
free(data);
if (! pTexture)
{
CCLOG("cocos2d: Grid: error creating texture");
return false;
}
initWithSize(gridSize, pTexture, false);
pTexture->release();
return true;
}
示例9: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
Director* pDirector = gDirector;
GLView* pGLView = pDirector->getOpenGLView();
if( NULL == pGLView )
{
pGLView = GLView::create("game(v1.0.0.0)---test for inner");
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
pGLView->setFrameSize(1334, 750);
#endif
pDirector->setOpenGLView(pGLView);
}
// 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);
// resolution information
Size size;
size= pDirector->getWinSize();
log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height);
size = pDirector->getWinSizeInPixels();
log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height);
size = pDirector->getVisibleSize();
log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height);
Point point = pDirector->getVisibleOrigin();
log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y);
log("***IDONG: Director BS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor());
auto framsize = pGLView->getFrameSize();
auto dwinsize = pDirector->getWinSize();
auto designsize = Size(SCREEN_WIDTH, SCREEN_HEIGHT);
auto widthRate = framsize.width/designsize.width;
auto heightRate = framsize.height/designsize.height;
auto resolutionRate = 1.f;
if(widthRate > heightRate)
{
pGLView->setDesignResolutionSize(designsize.width,
designsize.height*heightRate/widthRate, ResolutionPolicy::NO_BORDER);
resolutionRate = heightRate/widthRate;
}
else
{
pGLView->setDesignResolutionSize(designsize.width*widthRate/heightRate, designsize.height,
ResolutionPolicy::NO_BORDER);
resolutionRate = widthRate/heightRate;
}
//pGLView->setDesignResolutionSize(SCREEN_WIDTH, SCREEN_HEIGHT, ResolutionPolicy::FIXED_HEIGHT);
log("***IDONG:/n");
log("***IDONG: Director AS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor());
size= pDirector->getWinSize();
log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height);
size = pDirector->getWinSizeInPixels();
log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height);
size = pDirector->getVisibleSize();
log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height);
point = pDirector->getVisibleOrigin();
log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y);
// ‘ˆº”À—À˜¬∑æ∂
gFileUtils->addSearchPath("assets");
// …Ë÷√◊ ‘¥ƒø¬�?
// ≥ı ºªØ◊ ‘¥ƒø¬�?dumpŒƒº˛…˙≥…ƒø¬�?
string logfile = "";
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
gGameManager->SetResourceRoot("/mnt/sdcard/com.zm.mszb/");
gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
gGameManager->CreateDirectory(gGameManager->GetLogPath());
logfile = gGameManager->GetLogPath()+"/log.txt";
gLog->Open(logfile.c_str());
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
gGameManager->SetResourceRoot("");
gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
gGameManager->CreateDirectory(gGameManager->GetLogPath());
logfile = gGameManager->GetLogPath()+"/log.txt";
gLog->Open(logfile.c_str());
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
gGameManager->SetResourceRoot(gFileUtils->getWritablePath());
gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
gGameManager->CreateDirectory(gGameManager->GetLogPath());
logfile = gGameManager->GetLogPath()+"/log.txt";
//.........这里部分代码省略.........