- Activated debug and orientation management in Android manifest

- Coded double-click and orientation change for Android
- Clean up debug code badly introduced in opengl code in r3529
- updated Qt project to link against boost on linux
This commit is contained in:
Xawotihs
2011-04-25 10:04:44 +00:00
parent 7a1ed5278a
commit 137ccdf446
4 changed files with 87 additions and 39 deletions

View File

@@ -23,15 +23,16 @@
#define WAGIC_UPDATE_EVENT (SDL_USEREVENT + 1)
class SdlApp {
private:
public: /* For easy interfacing with JGE static functions */
bool Running;
SDL_Surface* Surf_Display;
SDL_Rect viewPort;
Uint32 lastMouseUpTime;
public:
SdlApp() {
Surf_Display = NULL;
lastMouseUpTime = 0;
Running = true;
};
@@ -60,6 +61,8 @@ class SdlApp {
bool OnInit();
void OnResize(int width, int height) {
DebugTrace("OnResize Width " << width << " height " << height);
if ((GLfloat)width / (GLfloat)height <= ACTUAL_RATIO)
{
viewPort.x = 0;
@@ -86,8 +89,6 @@ class SdlApp {
glMatrixMode (GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity (); // Reset The Projection Matrix
//gluOrtho2D(0.0f, (float) (viewPort.w)-1.0f, 0.0f, (float) (viewPort.h)-1.0f);
#if (defined GL_VERSION_ES_CM_1_1)
glOrthof(0.0f, (float) (viewPort.w)-1.0f, 0.0f, (float) (viewPort.h)-1.0f, -1.0f, 1.0f);
#else
@@ -101,13 +102,27 @@ class SdlApp {
#endif
};
void OnKeyPressed(const SDL_KeyboardEvent& event);
void OnMouseDoubleClicked(const SDL_MouseButtonEvent& event);
void OnMouseClicked(const SDL_MouseButtonEvent& event);
void OnMouseMoved(const SDL_MouseMotionEvent& event);
void OnEvent(SDL_Event* Event) {
if(Event->type < SDL_USEREVENT) DebugTrace("Received Event : " << Event->type);
switch(Event->type){
case SDL_QUIT:
{
Running = false;
break;
}
case SDL_WINDOWEVENT:
{ /* On Android, this is triggered when the device orientation changed */
#ifdef ANDROID
SDL_Window* window = SDL_GetWindowFromID(Event->window.windowID);
int h,w;
SDL_GetWindowSize(window, &w, &h);
OnResize(w, h);
#endif
break;
}
case SDL_VIDEORESIZE:
OnResize(Event->resize.w, Event->resize.h);
break;
@@ -119,9 +134,19 @@ class SdlApp {
OnMouseMoved(Event->motion);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
OnMouseClicked(Event->button);
break;
case SDL_MOUSEBUTTONUP:
{
Uint32 eventTime = SDL_GetTicks();
if(eventTime - lastMouseUpTime <= 500) {
OnMouseDoubleClicked(Event->button);
} else {
OnMouseClicked(Event->button);
}
lastMouseUpTime = eventTime;
break;
}
case WAGIC_UPDATE_EVENT:
OnUpdate();
break;
@@ -162,8 +187,8 @@ static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[]
{ SDLK_k, JGE_BTN_SEC },
{ SDLK_q, JGE_BTN_PREV },
{ SDLK_a, JGE_BTN_NEXT },
// fullscreen management seems somehow broken in JGE, it works fine with Qt directly
// { Qt::Key_F, JGE_BTN_FULLSCREEN },
{ SDLK_f, JGE_BTN_FULLSCREEN },
{ SDL_SCANCODE_AC_BACK, JGE_BTN_MENU },
};
void JGECreateDefaultBindings()
@@ -179,6 +204,7 @@ int JGEGetTime()
bool JGEToggleFullscreen()
{
SDL_WM_ToggleFullScreen(g_SdlApp->Surf_Display);
return true;
}
@@ -265,6 +291,16 @@ void SdlApp::OnMouseMoved(const SDL_MouseMotionEvent& event)
}
}
void SdlApp::OnMouseDoubleClicked(const SDL_MouseButtonEvent& event)
{
#if (defined ANDROID) || (defined IOS)
if(event.button == SDL_BUTTON_LEFT) /* Left button */
{
g_engine->HoldKey_NoRepeat(JGE_BTN_OK);
}
#endif
}
void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event)
{
if(event.type == SDL_MOUSEBUTTONDOWN)
@@ -283,7 +319,9 @@ void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event)
g_engine->LeftClicked(
((event.x-viewPort.x)*SCREEN_WIDTH)/actualWidth,
((event.y-viewPort.y)*SCREEN_HEIGHT)/actualHeight);
#if (!defined ANDROID) && (!defined IOS)
g_engine->HoldKey_NoRepeat(JGE_BTN_OK);
#endif
} else if(event.y < viewPort.y) {
g_engine->HoldKey_NoRepeat(JGE_BTN_MENU);
} else if(event.y > viewPort.y + viewPort.h) {
@@ -306,7 +344,9 @@ void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event)
event.y <= viewPort.y + viewPort.h &&
event.x >= viewPort.x &&
event.x <= viewPort.x + viewPort.w) {
#if (!defined ANDROID) && (!defined IOS)
g_engine->ReleaseKey(JGE_BTN_OK);
#endif
} else if(event.y < viewPort.y) {
g_engine->ReleaseKey(JGE_BTN_MENU);
} else if(event.y > viewPort.y + viewPort.h) {
@@ -325,10 +365,23 @@ void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event)
}
bool SdlApp::OnInit() {
int window_w, window_h;
if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
return false;
}
const SDL_VideoInfo *pVideoInfo = SDL_GetVideoInfo();
DebugTrace("Video Display : h " << pVideoInfo->current_h << ", w " << pVideoInfo->current_w);
#if (defined ANDROID) || (defined IOS)
window_w = pVideoInfo->current_w;
window_h = pVideoInfo->current_h;
#else
window_w = ACTUAL_SCREEN_WIDTH;
window_h = ACTUAL_SCREEN_HEIGHT;
#endif
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
@@ -343,10 +396,17 @@ bool SdlApp::OnInit() {
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
if((Surf_Display = SDL_SetVideoMode(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT, 32, /*SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER |*/ SDL_OPENGL | SDL_RESIZABLE)) == NULL) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
if((Surf_Display = SDL_SetVideoMode(window_w, window_h, 32,
#ifdef ANDROID
SDL_OPENGL | SDL_FULLSCREEN | SDL_WINDOW_BORDERLESS)) == NULL) {
#else
SDL_OPENGL | SDL_RESIZABLE | SDL_WINDOW_BORDERLESS)) == NULL) {
#endif
return false;
}
@@ -389,18 +449,17 @@ bool SdlApp::OnInit() {
glEnable(GL_SCISSOR_TEST); // Enable Clipping
OnResize(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT);
/* opengl needs to be fully initialized before starting the game */
if (!InitGame())
{
cerr << "Could not init the game\n";
return false;
}
OnResize(window_w, window_h);
JGECreateDefaultBindings();
SDL_SetTimer(5, OnTimer);
SDL_SetTimer(30, OnTimer);
return true;
};

View File

@@ -9,7 +9,7 @@
//-------------------------------------------------------------------------------------
#define GL_GLEXT_PROTOTYPES
#if (!defined IOS) && (!defined QT_CONFIG)
#if (!defined IOS)
#ifdef WIN32
#pragma warning(disable : 4786)
#pragma comment( lib, "giflib.lib" )
@@ -42,18 +42,12 @@ extern "C" {
#endif
#ifdef _DEBUG
void checkGlError()
{
GLenum glError = glGetError();
if(glError != 0)
printf("%s : %u : GLerror is %u\n", __FUNCTION__, __LINE__, glError);
}
/*#define checkGlError() \
#define checkGlError() \
{ \
GLenum glError = glGetError(); \
if(glError != 0) \
printf("%s : %u : GLerror is %u\n", __FUNCTION__, __LINE__, glError); \
}/*/
}
#else
#define checkGlError() (void(0))
#endif
@@ -826,7 +820,7 @@ void JRenderer::BeginScene()
esMatrixLoadIdentity(&theMvpMatrix);
esOrtho(&theMvpMatrix, 0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f,-1.0f, 1.0f);
#endif //(!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
#ifdef WIN32
#if (defined WIN32) || (defined ANDROID)
float scaleH = mActualHeight/SCREEN_HEIGHT_F;
float scaleW = mActualWidth/SCREEN_WIDTH_F;
if (scaleH != 1.0f || scaleW != 1.0f)
@@ -963,44 +957,37 @@ void JRenderer::RenderQuad(JQuad* quad, float xo, float yo, float angle, float x
// Use the program object
glUseProgram ( prog2 );
checkGlError();
// Load the vertex position
glVertexAttribPointer ( prog2_positionLoc, 3, GL_FLOAT,
GL_FALSE, 5 * sizeof(GLfloat), vVertices );
checkGlError();
// Load the texture coordinate
glVertexAttribPointer ( prog2_texCoordLoc, 2, GL_FLOAT,
GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] );
checkGlError();
// Load the colors
glVertexAttribPointer ( prog2_colorLoc, 4, GL_UNSIGNED_BYTE,
GL_TRUE, 4 * sizeof(GLubyte), colorCoords );
checkGlError();
glEnableVertexAttribArray ( prog2_positionLoc );
checkGlError();
glEnableVertexAttribArray ( prog2_texCoordLoc );
checkGlError();
glEnableVertexAttribArray ( prog2_colorLoc );
checkGlError();
// Load the MVP matrix
glUniformMatrix4fv( prog2_mvpLoc, 1, GL_FALSE, (GLfloat*) &mvpMatrix.m[0][0] );
checkGlError();
// Bind the texture
glActiveTexture ( GL_TEXTURE0 );
checkGlError();
glBindTexture ( GL_TEXTURE_2D, mCurrentTex );
checkGlError();
// Set the sampler texture unit to 0
glUniform1i ( prog2_samplerLoc, 0 );
checkGlError();
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
checkGlError();
#else
glPushMatrix();
@@ -1273,7 +1260,7 @@ void JRenderer::FillRect(float x, float y, float width, float height, PIXEL_TYPE
};
glVertexPointer(2,GL_FLOAT,0,vVertices);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors );
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors );
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
glDisableClientState(GL_COLOR_ARRAY);
@@ -1635,7 +1622,7 @@ static int getNextPower2(int width)
}
#if (!defined IOS) && (!defined QT_CONFIG)
#if (!defined IOS)
static void jpg_null(j_decompress_ptr cinfo __attribute__((unused)))
{
}

View File

@@ -3,8 +3,9 @@
package="org.libsdl.app"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/icon">
<application android:label="@string/app_name" android:icon="@drawable/icon" android:debuggable="true">
<activity android:name="SDLActivity"
android:configChanges="orientation"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -12,4 +13,5 @@
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>

View File

@@ -32,7 +32,7 @@ OBJECTS_DIR = objs
MOC_DIR = objs
DESTDIR = bin
unix:LIBS += -ljpeg -lgif -lpng12
unix:LIBS += -ljpeg -lgif -lpng12 -lboost_thread-mt
windows:LIBS += -L../../JGE/Dependencies/lib -llibjpeg-static-mt-debug -lgiflib -llibpng -lfmodvc
macx|unix:LIBS += -lz