-
-
Save wheybags/802237fb51fa63af22c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "PythonInterface.h" | |
#include <Rocket/Core.h> | |
#include <Rocket/Controls.h> | |
#include <Rocket/Debugger.h> | |
#include <Input.h> | |
#include <Shell.h> | |
Rocket::Core::Context* context = NULL; | |
ShellRenderInterfaceExtensions *shell_renderer; | |
void GameLoop() | |
{ | |
context->Update(); | |
shell_renderer->PrepareRenderBuffer(); | |
context->Render(); | |
shell_renderer->PresentRenderBuffer(); | |
} | |
int main(int argc, char** argv) | |
{ | |
// @TODO Make these lookup at runtime rather than using hard coded paths | |
#define APP_PATH "../Samples/pyinvaders/" | |
#define ROCKET_PATH "" | |
int window_width = 1024; | |
int window_height = 768; | |
ShellRenderInterfaceOpenGL opengl_renderer; | |
shell_renderer = &opengl_renderer; | |
// @TODO switch to using variable for window sizes | |
// Generic OS initialisation, creates a window and attaches OpenGL. | |
if (!Shell::Initialise(APP_PATH) || | |
!Shell::OpenWindow("Rocket Invaders from Mars (Python Powered)", shell_renderer, window_width, window_height, false)) | |
{ | |
Shell::Shutdown(); | |
return -1; | |
} | |
// Rocket initialisation. | |
Rocket::Core::SetRenderInterface(&opengl_renderer); | |
opengl_renderer.SetViewport(window_width, window_height); | |
ShellSystemInterface system_interface; | |
Rocket::Core::SetSystemInterface(&system_interface); | |
Rocket::Core::Initialise(); | |
// Initialise the Rocket Controls library. | |
Rocket::Controls::Initialise(); | |
// Initialise the Python interface. | |
PythonInterface::Initialise((Shell::GetExecutablePath() + (APP_PATH "python") + PATH_SEPARATOR + Shell::GetExecutablePath() + ROCKET_PATH).CString()); | |
// Create the main Rocket context and set it on the shell's input layer. | |
context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window_width, window_height)); | |
if (context == NULL) | |
{ | |
Rocket::Core::Shutdown(); | |
Shell::Shutdown(); | |
return -1; | |
} | |
//Rocket::Debugger::Initialise(context); | |
Input::SetContext(context); | |
shell_renderer->SetContext(context); | |
Rocket::Core::ElementDocument* document = context->LoadDocument("data/tutorial.rml"); | |
if (document != NULL) | |
{ | |
document->Show(); | |
document->RemoveReference(); | |
} | |
Shell::EventLoop(GameLoop); | |
document->Close(); | |
// Shutdown the Rocket contexts. | |
context->RemoveReference(); | |
// Shutdown Python before we shut down Rocket. | |
PythonInterface::Shutdown(); | |
// Shutdown Rocket. | |
Rocket::Core::Shutdown(); | |
Shell::CloseWindow(); | |
Shell::Shutdown(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment