mirror of https://github.com/axmolengine/axmol.git
Merge branch 'gles20' of https://github.com/dumganhar/cocos2d-x into gles20
This commit is contained in:
commit
a5639281ec
|
@ -77,6 +77,7 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
CCEGLView::CCEGLView()
|
CCEGLView::CCEGLView()
|
||||||
: bIsInit(false)
|
: bIsInit(false)
|
||||||
|
, m_fFrameZoomFactor(1.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +110,7 @@ void charEventHandle(int iCharID,int iCharState) {
|
||||||
|
|
||||||
void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
||||||
if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) {
|
if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
|
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||||
//get current mouse pos
|
//get current mouse pos
|
||||||
int x,y;
|
int x,y;
|
||||||
glfwGetMousePos(&x, &y);
|
glfwGetMousePos(&x, &y);
|
||||||
|
@ -120,12 +122,14 @@ void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
oPoint.x /= pEGLView->m_fFrameZoomFactor;
|
||||||
|
oPoint.y /= pEGLView->m_fFrameZoomFactor;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
if (iMouseState == GLFW_PRESS) {
|
if (iMouseState == GLFW_PRESS) {
|
||||||
CCEGLView::sharedOpenGLView()->handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y);
|
pEGLView->handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y);
|
||||||
|
|
||||||
} else if (iMouseState == GLFW_RELEASE) {
|
} else if (iMouseState == GLFW_RELEASE) {
|
||||||
CCEGLView::sharedOpenGLView()->handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y);
|
pEGLView->handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,10 +139,13 @@ void mousePosEventHandle(int iPosX,int iPosY) {
|
||||||
|
|
||||||
//to test move
|
//to test move
|
||||||
if (iButtonState == GLFW_PRESS) {
|
if (iButtonState == GLFW_PRESS) {
|
||||||
int id = 0;
|
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||||
float x = (float)iPosX;
|
int id = 0;
|
||||||
float y = (float)iPosY;
|
float x = (float)iPosX;
|
||||||
CCEGLView::sharedOpenGLView()->handleTouchesMove(1, &id, &x, &y);
|
float y = (float)iPosY;
|
||||||
|
x /= pEGLView->m_fFrameZoomFactor;
|
||||||
|
y /= pEGLView->m_fFrameZoomFactor;
|
||||||
|
pEGLView->handleTouchesMove(1, &id, &x, &y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,6 +241,21 @@ void CCEGLView::setFrameSize(float width, float height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setFrameZoom(float fZoomFactor)
|
||||||
|
{
|
||||||
|
m_fFrameZoomFactor = fZoomFactor;
|
||||||
|
glfwSetWindowSize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
|
||||||
|
CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
|
{
|
||||||
|
glViewport((GLint)(x * m_fScaleX * m_fFrameZoomFactor+ m_obViewPortRect.origin.x * m_fFrameZoomFactor),
|
||||||
|
(GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor),
|
||||||
|
(GLsizei)(w * m_fScaleX * m_fFrameZoomFactor),
|
||||||
|
(GLsizei)(h * m_fScaleY * m_fFrameZoomFactor));
|
||||||
|
}
|
||||||
|
|
||||||
bool CCEGLView::isOpenGLReady()
|
bool CCEGLView::isOpenGLReady()
|
||||||
{
|
{
|
||||||
return bIsInit;
|
return bIsInit;
|
||||||
|
|
|
@ -32,6 +32,11 @@ public:
|
||||||
* iDepth is not the buffer depth of opengl, it indicate how may bits for a pixel
|
* iDepth is not the buffer depth of opengl, it indicate how may bits for a pixel
|
||||||
*/
|
*/
|
||||||
virtual void setFrameSize(float width, float height);
|
virtual void setFrameSize(float width, float height);
|
||||||
|
virtual void setViewPortInPoints(float x , float y , float w , float h);
|
||||||
|
/*
|
||||||
|
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
void setFrameZoom(float fZoomFactor);
|
||||||
virtual bool isOpenGLReady();
|
virtual bool isOpenGLReady();
|
||||||
virtual void end();
|
virtual void end();
|
||||||
virtual void swapBuffers();
|
virtual void swapBuffers();
|
||||||
|
@ -42,13 +47,13 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCEGLView* sharedOpenGLView();
|
static CCEGLView* sharedOpenGLView();
|
||||||
private:
|
private:
|
||||||
bool initGL();
|
bool initGL();
|
||||||
void destroyGL();
|
void destroyGL();
|
||||||
private:
|
private:
|
||||||
bool m_bCaptured;
|
|
||||||
//store current mouse point for moving, valid if and only if the mouse pressed
|
//store current mouse point for moving, valid if and only if the mouse pressed
|
||||||
CCPoint m_mousePoint;
|
CCPoint m_mousePoint;
|
||||||
bool bIsInit;
|
bool bIsInit;
|
||||||
|
float m_fFrameZoomFactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -29,6 +29,9 @@ int main(int argc, char **argv)
|
||||||
AppDelegate app;
|
AppDelegate app;
|
||||||
CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
|
CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
|
||||||
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
||||||
eglView->setFrameSize(960, 640);
|
eglView->setFrameSize(2048, 1536);
|
||||||
|
// The resolution of ipad3 is very large. In general, PC's resolution is smaller than it.
|
||||||
|
// So we need to invoke 'setFrameZoom'(only valid on desktop(win32, mac, linux)) to make the window smaller.
|
||||||
|
eglView->setFrameZoom(0.4f);
|
||||||
return CCApplication::sharedApplication()->run();
|
return CCApplication::sharedApplication()->run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue