Skip to content

Add Retina display resource for tests. And modify CCDrawingPrimitives.cpp for retina display support. And rename templates/CCApplicationWizard.vs templates/msvc. #175

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

Merged
2 commits merged into from
Mar 15, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-win32.bat
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ echo.*/
echo.

set SCRIPT_LOG=InstallWizardLog.txt
set SCRIPT_DIR=.\template\CCApplicationWizard.vs\
set SCRIPT_DIR=.\template\msvc\

if exist %SCRIPT_LOG% del /Q %SCRIPT_LOG%
cscript "%SCRIPT_DIR%InstallWizardForVC2008Express.js" /quiet
Expand Down
101 changes: 67 additions & 34 deletions cocos2dx/CCDrawingPrimitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ void ccDrawPoints(const CCPoint *points, unsigned int numberOfPoints)

void ccDrawLine(CCPoint origin, CCPoint destination)
{
CCPoint vertices[2];
ccVertex2F vertices[2] =
{
{origin.x * CC_CONTENT_SCALE_FACTOR(), origin.y * CC_CONTENT_SCALE_FACTOR()},
{destination.x * CC_CONTENT_SCALE_FACTOR(), destination.y * CC_CONTENT_SCALE_FACTOR()},
};

vertices[0] = origin;
vertices[1] = destination;

// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_VERTEX_ARRAY,
// Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
Expand All @@ -131,29 +132,61 @@ void ccDrawLine(CCPoint origin, CCPoint destination)
}


void ccDrawPoly(const CCPoint *poli, int points, bool closePolygon)
void ccDrawPoly(const CCPoint *poli, int numberOfPoints, bool closePolygon)
{
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_VERTEX_ARRAY,
// Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

glVertexPointer(2, GL_FLOAT, 0, poli);
if (closePolygon)
{
glDrawArrays(GL_LINE_LOOP, 0, points);
}
else
{
glDrawArrays(GL_LINE_STRIP, 0, points);
}

// restore default state
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
ccVertex2F* newPoint = new ccVertex2F[numberOfPoints];
if (! newPoint)
{
return;
}
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_VERTEX_ARRAY,
// Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);


// iPhone and 32-bit machines
if( sizeof(CCPoint) == sizeof(ccVertex2F) ) {

// convert to pixels ?
if( CC_CONTENT_SCALE_FACTOR() != 1 ) {
memcpy( newPoint, poli, numberOfPoints * sizeof(ccVertex2F) );
for( int i=0; i<numberOfPoints;i++)
{
newPoint[i].x = poli[i].x * CC_CONTENT_SCALE_FACTOR();
newPoint[i].y = poli[i].y * CC_CONTENT_SCALE_FACTOR();
}
glVertexPointer(2, GL_FLOAT, 0, newPoint);

} else
glVertexPointer(2, GL_FLOAT, 0, poli);


} else {
// 64-bit machines (Mac)

for( int i=0; i<numberOfPoints;i++)
{
newPoint[i].x = poli[i].x;
newPoint[i].y = poli[i].y;
}

glVertexPointer(2, GL_FLOAT, 0, newPoint );

}

if( closePolygon )
glDrawArrays(GL_LINE_LOOP, 0, numberOfPoints);
else
glDrawArrays(GL_LINE_STRIP, 0, numberOfPoints);

// restore default state
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
delete[] newPoint;
}

void ccDrawCircle(CCPoint center, float r, float a, int segs, bool drawLineToCenter)
Expand All @@ -180,11 +213,11 @@ void ccDrawCircle(CCPoint center, float r, float a, int segs, bool drawLineToCen
float j = r * cosf(rads + a) + center.x;
float k = r * sinf(rads + a) + center.y;

vertices[i*2] = j;
vertices[i*2+1] =k;
vertices[i*2] = j * CC_CONTENT_SCALE_FACTOR();
vertices[i*2+1] =k * CC_CONTENT_SCALE_FACTOR();
}
vertices[(segs+1)*2] = center.x;
vertices[(segs+1)*2+1] = center.y;
vertices[(segs+1)*2] = center.x * CC_CONTENT_SCALE_FACTOR();
vertices[(segs+1)*2+1] = center.y * CC_CONTENT_SCALE_FACTOR();

// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_VERTEX_ARRAY,
Expand Down Expand Up @@ -213,10 +246,10 @@ void ccDrawQuadBezier(CCPoint origin, CCPoint control, CCPoint destination, int
{
float x = powf(1 - t, 2) * origin.x + 2.0f * (1 - t) * t * control.x + t * t * destination.x;
float y = powf(1 - t, 2) * origin.y + 2.0f * (1 - t) * t * control.y + t * t * destination.y;
vertices[i] = CCPointMake(x, y);
vertices[i] = CCPointMake(x * CC_CONTENT_SCALE_FACTOR(), y * CC_CONTENT_SCALE_FACTOR());
t += 1.0f / segments;
}
vertices[segments] = destination;
vertices[segments] = CCPointMake(destination.x * CC_CONTENT_SCALE_FACTOR(), destination.y * CC_CONTENT_SCALE_FACTOR());

// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_VERTEX_ARRAY,
Expand Down Expand Up @@ -244,10 +277,10 @@ void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoi
{
float x = powf(1 - t, 3) * origin.x + 3.0f * powf(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x;
float y = powf(1 - t, 3) * origin.y + 3.0f * powf(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y;
vertices[i] = CCPointMake(x, y);
vertices[i] = CCPointMake(x * CC_CONTENT_SCALE_FACTOR(), y * CC_CONTENT_SCALE_FACTOR());
t += 1.0f / segments;
}
vertices[segments] = destination;
vertices[segments] = CCPointMake(destination.x * CC_CONTENT_SCALE_FACTOR(), destination.y * CC_CONTENT_SCALE_FACTOR());

// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_VERTEX_ARRAY,
Expand Down
2 changes: 2 additions & 0 deletions cocos2dx/include/CCDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class CC_DLL CCDirector : public CCObject
@since v0.99.5
*/
bool enableRetinaDisplay(bool enabled);
bool isRetinaDisplay() { return m_bRetinaDisplay; }

/** There are 4 types of Director.
- kCCDirectorTypeNSTimer (default)
Expand Down Expand Up @@ -548,6 +549,7 @@ class CC_DLL CCDirector : public CCObject
* mac platforms specific members
**************************************************/
bool m_bIsFullScreen;
bool m_bRetinaDisplay;
int m_nResizeMode;
CCPoint m_winOffset;
CCSize m_originalWinSize;
Expand Down
11 changes: 11 additions & 0 deletions cocos2dx/platform/CCDirector_mobile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ bool CCDirector::init(void)

m_pobOpenGLView = NULL;

m_bRetinaDisplay = false;
m_fContentScaleFactor = 1;
m_bIsContentScaleSupported = false;

Expand Down Expand Up @@ -804,6 +805,16 @@ bool CCDirector::enableRetinaDisplay(bool enabled)
m_pFPSLabel->retain();
}
#endif

if (m_fContentScaleFactor == 2)
{
m_bRetinaDisplay = true;
}
else
{
m_bRetinaDisplay = false;
}

return true;
}

Expand Down
Binary file added tests/Res/Images/b1-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/b2-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/background1-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/background2-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/background3-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/blocks-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/close-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/f1-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/f2-hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Res/Images/grossini-hd.png
Binary file added tests/Res/Images/grossini_dance_atlas-hd.png
Binary file added tests/Res/Images/grossinis_sister1-hd.png
Binary file added tests/Res/Images/grossinis_sister2-hd.png
Binary file added tests/Res/Images/particles-hd.png
Binary file added tests/Res/Images/r1-hd.png
Binary file added tests/Res/Images/r2-hd.png
Binary file added tests/Res/TileMaps/tiles-hd.png
Binary file added tests/Res/animations/dragon_animation-hd.png
Binary file added tests/Res/fonts/fps_images-hd.png
61 changes: 38 additions & 23 deletions tests/tests/HiResTest/HiResTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ CCLayer* createHiResLayer(int idx)
switch (idx)
{
case 0:
pLayer = new HiResTest1(); break;
CCDirector::sharedDirector()->enableRetinaDisplay(false);
pLayer = new HiResTest1();
break;
case 1:
pLayer = new HiResTest2(); break;
CCDirector::sharedDirector()->enableRetinaDisplay(true);
pLayer = new HiResTest2();
break;
}

return pLayer;
Expand Down Expand Up @@ -44,6 +48,25 @@ CCLayer* backHiResAction()
return pLayer;
}

//////////////////////////////////////////////////////////////////////////
// HiResTestBackToMainMenuLayer
//////////////////////////////////////////////////////////////////////////
class HiResTestBackToainMenuLayer : public BackToMainMenuLayer
{
public:
HiResTestBackToainMenuLayer() {}

// The CallBack for back to the main menu scene
virtual void MainMenuCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->enableRetinaDisplay(sm_bRitinaDisplay);
BackToMainMenuLayer::MainMenuCallback(pSender);
}

static bool sm_bRitinaDisplay;
};
bool HiResTestBackToainMenuLayer::sm_bRitinaDisplay = false;

////////////////////////////////////
//
// HiResDemo
Expand Down Expand Up @@ -143,16 +166,6 @@ void HiResDemo::backCallback(CCObject* pSender)
///////////////////////////////////
void HiResTest1::onEnter()
{
CCDirector::sharedDirector()->enableRetinaDisplay(false);
// Because BackToMainMenuLayer maybe addChild to scene again by HiResTest2,
// we add it again to make it in the right place.
// The right way is calling enableRetinaDisplay before all scene and layer.
CCScene * pScene = (CCScene*)getParent();
CCLayer* pLayer = (CCLayer*)pScene->getChildByTag(54321);
pScene->removeChild(pLayer, true);
pLayer = new BackToMainMenuLayer;
pScene->addChild(pLayer, 1000, 54321);
pLayer->release();

HiResDemo::onEnter();

Expand Down Expand Up @@ -180,17 +193,6 @@ std::string HiResTest1::subtitle()
///////////////////////////////////
void HiResTest2::onEnter()
{
CCDirector::sharedDirector()->enableRetinaDisplay(true);

// Because BackToMainMenuLayer has been addChild to scene,
// we must add it again.
// The right way is calling enableRetinaDisplay before all scene and layer.
CCScene * pScene = (CCScene*)getParent();
CCLayer* pLayer = (CCLayer*)pScene->getChildByTag(54321);
pScene->removeChild(pLayer, true);
pLayer = new BackToMainMenuLayer;
pScene->addChild(pLayer, 1000, 54321);
pLayer->release();

HiResDemo::onEnter();

Expand Down Expand Up @@ -218,9 +220,22 @@ std::string HiResTest2::subtitle()
///////////////////////////////////
void HiResTestScene::runThisTest()
{
HiResTestBackToainMenuLayer::sm_bRitinaDisplay = CCDirector::sharedDirector()->isRetinaDisplay();

CCLayer* pLayer = nextHiResAction();
addChild(pLayer);

pLayer->release();
CCDirector::sharedDirector()->replaceScene(this);
}

void HiResTestScene::onEnter()
{
TestScene::onEnter();

CCLayer* pLayer = (CCLayer*)getChildByTag(54321);
removeChild(pLayer, true);
pLayer = new HiResTestBackToainMenuLayer;
addChild(pLayer, 1000, 54321);
pLayer->release();
}
1 change: 1 addition & 0 deletions tests/tests/HiResTest/HiResTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HiResTestScene : public TestScene
{
public:
virtual void runThisTest();
virtual void onEnter();
};

#endif
2 changes: 0 additions & 2 deletions tests/tests/testBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ BackToMainMenuLayer::BackToMainMenuLayer()

void BackToMainMenuLayer::MainMenuCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->enableRetinaDisplay(false);

CCScene* pScene = CCScene::node();
CCLayer* pLayer = new TestController();
pLayer->autorelease();
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/testBasic.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BackToMainMenuLayer : public CCLayer
BackToMainMenuLayer();

// The CallBack for back to the main menu scene
void MainMenuCallback(CCObject* pSender);
virtual void MainMenuCallback(CCObject* pSender);
};

class TestScene : public CCScene
Expand Down