Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Engine.h"
- Engine::Engine(){
- rocketContext = NULL;
- rockDoc = NULL;
- }
- void Engine::Start(const char* title, int width, int height, int bpp, bool fullscreen){
- int flags = 0;
- if (SDL_Init(SDL_INIT_EVERYTHING) == -1 ) { //turn on sdl
- printf("%s\n", SDL_GetError());
- return;
- }
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- screen = NULL;
- if (fullscreen) {//turn on fullscreen
- flags = SDL_FULLSCREEN;
- } else {
- flags = SDL_OPENGL;
- }
- screen = SDL_SetVideoMode(width, height, bpp, flags);//create a screen surface to draw on
- GLSetup();
- SDL_WM_SetCaption(title, title);//set window title
- if (screen == NULL) {
- SDL_GetError();
- return;
- }
- SDL_EnableUNICODE( SDL_TRUE );
- SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
- InitSDLtoRocketKeymap();
- fullScreen = fullscreen;
- //-
- Rocket::Core::SetSystemInterface( &rocketSys );
- Rocket::Core::SetRenderInterface( &rocketRender );
- Rocket::Core::Initialise();
- Rocket::Controls::Initialise();
- rocketContext = Rocket::Core::CreateContext( "main", Rocket::Core::Vector2i(width, height) );
- if (Rocket::Debugger::Initialise(rocketContext) && Rocket::Debugger::SetContext(rocketContext))
- Rocket::Debugger::SetVisible(true);
- bool success = Rocket::Core::FontDatabase::LoadFontFace("interface/Delicious-Roman.otf");
- if( !success ) std::cout << "Failed to load font!" << std::endl;
- rockDoc = rocketContext->LoadDocument( "interface/test.rml" );
- rockDoc->Show();
- //--
- running = true;//go live
- }
- void Engine::GLSetup(){
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glEnable(GL_BLEND);
- glEnable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, screen->w, screen->h, 0, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glClearColor( 0.2f, 0.2f, 0.2f, 1.0f );
- }
- void Engine::ChangeState(EngineState* state){
- if (!states.empty()){
- states.back()->Clean();
- states.pop_back();
- }
- states.push_back(state);
- states.back()->Start();
- }
- void Engine::PushState(EngineState* state){
- if (!states.empty()) {
- states.back()->Pause();
- }
- states.push_back(state);
- states.back()->Start();
- }
- void Engine::PopState(){
- if (!states.empty()) {
- states.back()->Clean();
- states.pop_back();
- }
- if (!states.empty())
- states.back()->Resume();
- }
- void Engine::HandleEvents(){
- states.back()->HandleEvents(this);
- }
- void Engine::Update(){
- states.back()->Update(this);
- rocketContext->Update();
- }
- void Engine::Draw(){
- states.back()->Draw(this);
- rocketContext->Render();
- }
- void Engine::Clean(){
- while (!states.empty()) {
- states.back()->Clean();
- states.pop_back();
- }
- rockDoc->RemoveReference();
- rocketContext->RemoveReference();
- Rocket::Core::Shutdown();
- }
- void Engine::Quit(){
- SDL_FreeSurface(screen);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement