1 /* 2 * Martian: Motor para creaci�n de videojuegos con SDL y OpenGL 3 * Copyright (C) 2007 Javier P�rez Pacheco 4 * 5 * Este motor tiene licencia Creative Commons y se permite 6 * su modificacion y utilizacion libremente siempre y cuando se 7 * cite al autor original y se comparta con la misma licencia. 8 * No se permite su uso comercial. 9 * 10 * Para mas informacion visite la web: 11 * http://creativecommons.org/licenses/by-nc-sa/2.0/es/ 12 * 13 * PROGRAMADOR 14 * Javier P�rez Pacheco 15 * Cadiz (Spain) 16 * javielinux@gmail.com 17 * 18 */ 19 20 #include "world.h" 21 22 namespace Martian { 23 24 int World::width = 0; 25 int World::height = 0; 26 World(int w,int h,string titleWindow)27 World::World(int w, int h, string titleWindow) { 28 29 existDataDirectory = WorkingData::GetInstance()->existFile(string(DATA_DIR)+"/."); 30 31 srand(time(NULL)); 32 33 width = w; 34 height = h; 35 36 currentScene = -1; 37 38 // Init SDL 39 40 if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) 41 { 42 printf ("No se puede iniciar SDL: %s\n", SDL_GetError()); 43 } 44 45 fullscreen = false; 46 47 //modeScreen (); 48 49 //SDL_ShowCursor(0); 50 SDL_WM_SetCaption(titleWindow.c_str(), titleWindow.c_str()); 51 52 // load timer 53 54 Timer::GetInstance(); 55 56 } 57 58 InitGL()59 void World::InitGL() 60 { 61 //glViewport(0, 0, WIDTH_SCREEN, HEIGHT_SCREEN); 62 63 glEnable(GL_TEXTURE_2D); 64 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 65 66 glShadeModel(GL_SMOOTH); 67 68 glMatrixMode(GL_PROJECTION); 69 glLoadIdentity(); 70 glOrtho(0, width, height, 0, -1000, 1000); 71 glMatrixMode(GL_MODELVIEW); 72 73 } 74 75 modeScreen()76 void World::modeScreen () { 77 Uint32 flags; 78 int screen_bpp; 79 80 if (Options::GetInstance()->getValue("fullscreen") != "") { 81 if (Options::GetInstance()->getValue("fullscreen") == "true") { 82 fullscreen = true; 83 } else { 84 fullscreen = false; 85 } 86 } else { 87 fullscreen = false; 88 } 89 90 //flags = SDL_HWSURFACE | SDL_DOUBLEBUF; 91 92 if ( fullscreen ) { 93 flags = SDL_FULLSCREEN | SDL_OPENGL; 94 } else { 95 flags = SDL_OPENGL; 96 } 97 98 screen_bpp = 24; 99 100 //flags |= SDL_OPENGL; 101 102 103 screen = SDL_SetVideoMode (width, height, 0, flags); 104 105 InitGL(); 106 } 107 loadScene(string sc)108 int World::loadScene(string sc) { 109 if (sc=="quit") { 110 return -1; 111 } else { 112 return getScene(sc)->getId(); 113 } 114 } 115 unLoad()116 void World::unLoad() { 117 Sounds::GetInstance()->unLoadAll(); 118 Fonts::GetInstance()->unLoad(); 119 Cursor::GetInstance()->unLoad(); 120 } 121 122 123 } 124