- tab cleanup
- replace unix path management code by Qt one
This commit is contained in:
+85
-87
@@ -17,21 +17,20 @@ class JGEQtRenderer : public QGLWidget
|
|||||||
// Q_OBJECT // must include this if you use Qt signals/slots
|
// Q_OBJECT // must include this if you use Qt signals/slots
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JGEQtRenderer(QWidget *parent);
|
JGEQtRenderer(QWidget *parent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void initializeGL();
|
||||||
|
|
||||||
void initializeGL();
|
void resizeGL(int w, int h);
|
||||||
|
|
||||||
void resizeGL(int w, int h);
|
void paintGL();
|
||||||
|
|
||||||
void paintGL();
|
void timerEvent( QTimerEvent* );
|
||||||
|
|
||||||
void timerEvent( QTimerEvent* );
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyReleaseEvent(QKeyEvent *event);
|
||||||
|
|
||||||
void keyReleaseEvent(QKeyEvent *event);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t lastTickCount;
|
uint64_t lastTickCount;
|
||||||
@@ -41,22 +40,22 @@ JGameLauncher* g_launcher = NULL;
|
|||||||
JGEQtRenderer *g_glwidget = NULL;
|
JGEQtRenderer *g_glwidget = NULL;
|
||||||
|
|
||||||
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
||||||
{
|
{
|
||||||
{ Qt::Key_Enter, JGE_BTN_MENU },
|
{ Qt::Key_Enter, JGE_BTN_MENU },
|
||||||
{ Qt::Key_Backspace, JGE_BTN_CTRL },
|
{ Qt::Key_Backspace, JGE_BTN_CTRL },
|
||||||
{ Qt::Key_Up, JGE_BTN_UP },
|
{ Qt::Key_Up, JGE_BTN_UP },
|
||||||
{ Qt::Key_Down, JGE_BTN_DOWN },
|
{ Qt::Key_Down, JGE_BTN_DOWN },
|
||||||
{ Qt::Key_Left, JGE_BTN_LEFT },
|
{ Qt::Key_Left, JGE_BTN_LEFT },
|
||||||
{ Qt::Key_Right, JGE_BTN_RIGHT },
|
{ Qt::Key_Right, JGE_BTN_RIGHT },
|
||||||
{ Qt::Key_Space, JGE_BTN_OK },
|
{ Qt::Key_Space, JGE_BTN_OK },
|
||||||
{ Qt::Key_Tab, JGE_BTN_CANCEL },
|
{ Qt::Key_Tab, JGE_BTN_CANCEL },
|
||||||
{ Qt::Key_J, JGE_BTN_PRI },
|
{ Qt::Key_J, JGE_BTN_PRI },
|
||||||
{ Qt::Key_K, JGE_BTN_SEC },
|
{ Qt::Key_K, JGE_BTN_SEC },
|
||||||
{ Qt::Key_Q, JGE_BTN_PREV },
|
{ Qt::Key_Q, JGE_BTN_PREV },
|
||||||
{ Qt::Key_A, JGE_BTN_NEXT },
|
{ Qt::Key_A, JGE_BTN_NEXT },
|
||||||
// fullscreen management seems somehow broken in JGE, it works fine with Qt directly
|
// fullscreen management seems somehow broken in JGE, it works fine with Qt directly
|
||||||
// { Qt::Key_F, JGE_BTN_FULLSCREEN },
|
// { Qt::Key_F, JGE_BTN_FULLSCREEN },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void JGECreateDefaultBindings()
|
void JGECreateDefaultBindings()
|
||||||
@@ -102,11 +101,11 @@ void DestroyGame(void)
|
|||||||
{
|
{
|
||||||
g_engine->SetApp(NULL);
|
g_engine->SetApp(NULL);
|
||||||
if (g_app)
|
if (g_app)
|
||||||
{
|
{
|
||||||
g_app->Destroy();
|
g_app->Destroy();
|
||||||
delete g_app;
|
delete g_app;
|
||||||
g_app = NULL;
|
g_app = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
JGE::Destroy();
|
JGE::Destroy();
|
||||||
|
|
||||||
@@ -115,7 +114,7 @@ void DestroyGame(void)
|
|||||||
|
|
||||||
|
|
||||||
JGEQtRenderer::JGEQtRenderer(QWidget *parent)
|
JGEQtRenderer::JGEQtRenderer(QWidget *parent)
|
||||||
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
|
: QGLWidget(parent)
|
||||||
{
|
{
|
||||||
startTimer( 5 );
|
startTimer( 5 );
|
||||||
setWindowTitle(g_launcher->GetName());
|
setWindowTitle(g_launcher->GetName());
|
||||||
@@ -128,38 +127,38 @@ JGEQtRenderer::JGEQtRenderer(QWidget *parent)
|
|||||||
|
|
||||||
void JGEQtRenderer::initializeGL()
|
void JGEQtRenderer::initializeGL()
|
||||||
{
|
{
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers)
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers)
|
||||||
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
|
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
|
||||||
#if (defined GL_ES_VERSION_2_0)
|
#if (defined GL_ES_VERSION_2_0)
|
||||||
glClearDepthf(1.0f); // Depth Buffer Setup
|
glClearDepthf(1.0f); // Depth Buffer Setup
|
||||||
#else
|
#else
|
||||||
glClearDepth(1.0f); // Depth Buffer Setup
|
glClearDepth(1.0f); // Depth Buffer Setup
|
||||||
#endif// (defined GL_ES_VERSION_2_0)
|
#endif// (defined GL_ES_VERSION_2_0)
|
||||||
|
|
||||||
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
|
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
|
||||||
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
|
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
|
||||||
|
|
||||||
#else
|
#else
|
||||||
glClearDepth(1.0f); // Depth Buffer Setup
|
glClearDepth(1.0f); // Depth Buffer Setup
|
||||||
|
|
||||||
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
|
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
|
||||||
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
|
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
|
||||||
glShadeModel(GL_SMOOTH); // Select Smooth Shading
|
glShadeModel(GL_SMOOTH); // Select Smooth Shading
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
|
||||||
|
|
||||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // Set Line Antialiasing
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // Set Line Antialiasing
|
||||||
glEnable(GL_LINE_SMOOTH); // Enable it!
|
glEnable(GL_LINE_SMOOTH); // Enable it!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glEnable(GL_CULL_FACE); // do not calculate inside of poly's
|
glEnable(GL_CULL_FACE); // do not calculate inside of poly's
|
||||||
glFrontFace(GL_CCW); // counter clock-wise polygons are out
|
glFrontFace(GL_CCW); // counter clock-wise polygons are out
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glEnable(GL_SCISSOR_TEST); // Enable Clipping
|
glEnable(GL_SCISSOR_TEST); // Enable Clipping
|
||||||
}
|
}
|
||||||
|
|
||||||
int actualWidth;
|
int actualWidth;
|
||||||
@@ -171,38 +170,42 @@ GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize The GL Window
|
|||||||
actualHeight = height;
|
actualHeight = height;
|
||||||
|
|
||||||
if ((GLfloat)width / (GLfloat)height < ACTUAL_RATIO)
|
if ((GLfloat)width / (GLfloat)height < ACTUAL_RATIO)
|
||||||
|
{
|
||||||
glViewport(0, -((width/ACTUAL_RATIO)-height)/2, width, width / ACTUAL_RATIO); // Reset The Current Viewport
|
glViewport(0, -((width/ACTUAL_RATIO)-height)/2, width, width / ACTUAL_RATIO); // Reset The Current Viewport
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
glViewport(-(height*ACTUAL_RATIO-width)/2, 0, height * ACTUAL_RATIO, height);
|
glViewport(-(height*ACTUAL_RATIO-width)/2, 0, height * ACTUAL_RATIO, height);
|
||||||
|
}
|
||||||
glScissor(0, 0, width, height);
|
glScissor(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGEQtRenderer::resizeGL(int width, int height)
|
void JGEQtRenderer::resizeGL(int width, int height)
|
||||||
{
|
{
|
||||||
ReSizeGLScene(width, height);
|
ReSizeGLScene(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGEQtRenderer::paintGL()
|
void JGEQtRenderer::paintGL()
|
||||||
{
|
{
|
||||||
g_engine->Render();
|
g_engine->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGEQtRenderer::timerEvent( QTimerEvent* )
|
void JGEQtRenderer::timerEvent( QTimerEvent* )
|
||||||
{
|
{
|
||||||
QTime theTime = QTime::currentTime();
|
QTime theTime = QTime::currentTime();
|
||||||
static uint64_t tickCount;
|
static uint64_t tickCount;
|
||||||
quint32 dt;
|
quint32 dt;
|
||||||
tickCount = theTime.second() * 1000 + theTime.msec();
|
tickCount = theTime.second() * 1000 + theTime.msec();
|
||||||
dt = (tickCount - lastTickCount);
|
dt = (tickCount - lastTickCount);
|
||||||
lastTickCount = tickCount;
|
lastTickCount = tickCount;
|
||||||
|
|
||||||
if(g_engine->IsDone()) close();
|
if(g_engine->IsDone()) close();
|
||||||
|
|
||||||
//gPrevControllerState = gControllerState;
|
//gPrevControllerState = gControllerState;
|
||||||
g_engine->SetDelta((float)dt / 1000.0f);
|
g_engine->SetDelta((float)dt / 1000.0f);
|
||||||
g_engine->Update((float)dt / 1000.0f);
|
g_engine->Update((float)dt / 1000.0f);
|
||||||
|
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -229,42 +232,37 @@ void JGEQtRenderer::keyReleaseEvent(QKeyEvent *event)
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char* path = argv[0];
|
QApplication a( argc, argv );
|
||||||
while (*path) ++path;
|
QDir::setCurrent(QCoreApplication::applicationDirPath () );
|
||||||
while ((*path != '/') && (path > argv[0])) --path;
|
|
||||||
if ('/' == *path) *path = 0;
|
|
||||||
if (strlen(argv[0]) != 0) QDir::current().cd(argv[0]);
|
|
||||||
|
|
||||||
QApplication a( argc, argv );
|
g_launcher = new JGameLauncher();
|
||||||
|
|
||||||
g_launcher = new JGameLauncher();
|
u32 flags = g_launcher->GetInitFlags();
|
||||||
|
|
||||||
u32 flags = g_launcher->GetInitFlags();
|
if ((flags&JINIT_FLAG_ENABLE3D)!=0)
|
||||||
|
{
|
||||||
|
JRenderer::Set3DFlag(true);
|
||||||
|
}
|
||||||
|
|
||||||
if ((flags&JINIT_FLAG_ENABLE3D)!=0)
|
g_glwidget = new JGEQtRenderer(NULL);
|
||||||
JRenderer::Set3DFlag(true);
|
g_glwidget->resize(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT);
|
||||||
|
g_glwidget->show();
|
||||||
|
|
||||||
g_glwidget = new JGEQtRenderer(NULL);
|
if (!InitGame())
|
||||||
|
{
|
||||||
|
qDebug("Could not init the game\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
g_glwidget->resize(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT);
|
JGECreateDefaultBindings();
|
||||||
|
|
||||||
g_glwidget->show();
|
a.exec();
|
||||||
|
|
||||||
if (!InitGame())
|
if (g_launcher)
|
||||||
{
|
delete g_launcher;
|
||||||
printf("Could not init the game\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
JGECreateDefaultBindings();
|
if(g_glwidget)
|
||||||
|
delete g_glwidget;
|
||||||
a.exec();
|
|
||||||
|
|
||||||
if (g_launcher)
|
|
||||||
delete g_launcher;
|
|
||||||
|
|
||||||
if(g_glwidget)
|
|
||||||
delete g_glwidget;
|
|
||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
DestroyGame();
|
DestroyGame();
|
||||||
|
|||||||
Reference in New Issue
Block a user