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