#include <stdlib.h>
+#include <simgear/compiler.h>
+#include <simgear/structure/exception.hxx>
+#include <simgear/debug/logstream.hxx>
+
#include <SDL/SDL.h>
#include <plib/pu.h>
int cbits = (bpp <= 16) ? 5 : 8;
int zbits = (bpp <= 16) ? 16 : 24;
- SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE); // FIXME: handle errors
+ if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) == -1)
+ throw sg_throwable(string("Failed to initialize SDL: ")
+ + SDL_GetError());
+ atexit(SDL_Quit);
+
+ SDL_WM_SetCaption("FlightGear", "FlightGear");
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, cbits);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, cbits);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, cbits);
if(alpha)
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- if(stencil)
+ if(bpp > 16 && stencil)
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, zbits);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if(fullscreen) {
vidmask |= SDL_FULLSCREEN;
}
- SDL_SetVideoMode(w, h, 16, vidmask); // FIXME: handle errors
-
- SDL_WM_SetCaption("FlightGear", "FlightGear");
+ if (SDL_SetVideoMode(w, h, 16, vidmask) == 0)
+ throw sg_throwable(string("Failed to set SDL video mode: ")
+ + SDL_GetError());
// This enables keycode translation (e.g. capital letters when
// shift is pressed, as well as i18n input methods). Eventually,
(*KeyHandler)(key, keymod, CurrentMouseX, CurrentMouseY);
}
-// FIXME: need to export this and get the rest of FlightGear to use
-// it, the SDL hook is required to do things like reset the video
-// mode and key repeat. Integrate with existing fgExit() in util.cxx.
+// FIXME: Integrate with existing fgExit() in util.cxx.
void fgOSExit(int code)
{
- SDL_Quit();
exit(code);
}
return;
}
SDL_ShowCursor(SDL_ENABLE);
- for(int i=0; i<NCURSORS; i++) {
+ for(unsigned int i=0; i<NCURSORS; i++) {
if(cursor == cursors[i].name) {
CurrentMouseCursor = cursor;
SDL_SetCursor(cursors[i].sdlCursor);
static void initCursors()
{
unsigned char mask[128], img[128];
- int i=0;
- for(int i=0; i<NCURSORS; i++) {
+ for(unsigned int i=0; i<NCURSORS; i++) {
if(cursors[i].name == MOUSE_CURSOR_NONE) break;
for(int j=0; j<128; j++) mask[j] = img[j] = 0;
for(int y=0; y<cursors[i].h; y++) {