void OPGraphicsManager::unloadGFXMode() { uint8_t hiddenCursorData = 0; hiddenCursor = SDL_CreateCursor(&hiddenCursorData, &hiddenCursorData, 8, 1, 0, 0); // Free the hidden SDL cursor created in loadGFXMode SDL_FreeCursor(hiddenCursor); SurfaceSdlGraphicsManager::unloadGFXMode(); }
void init() { assert(!m_inited); m_inited = true; // store system cursor m_system_cursor = SDL_GetCursor(); // Init active cursor. int i, row, col; Uint8 data[4 * 32]; Uint8 mask[4 * 32]; int hot_x, hot_y; i = -1; for (row=0; row<32; ++row) { for (col=0; col<32; ++col) { if (col % 8) { data[i] <<= 1; mask[i] <<= 1; } else { ++i; data[i] = mask[i] = 0; } switch (s_hand_image[4 + row][col]) { default: break; case 'X': // black data[i] |= 0x01; mask[i] |= 0x01; break; case '.': // white mask[i] |= 0x01; break; case ' ': // transparent break; } } } sscanf(s_hand_image[4 + row], "%d,%d", &hot_x, &hot_y); m_active_cursor = SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y); }
static SDL_Cursor * Create(const CursorData * cursorInfo) { SDL_Cursor * cursor = SDL_CreateCursor( cursorInfo->Data, cursorInfo->Mask, CURSOR_WIDTH, CURSOR_HEIGHT, cursorInfo->HotSpot.X, cursorInfo->HotSpot.Y); return cursor; }
/** * Starts up SDL with all the subsystems and SDL_mixer for audio processing, * creates the display screen and sets up the cursor. * @param title Title of the game window. */ Game::Game(const std::string &title) : _screen(0), _cursor(0), _lang(0), _res(0), _save(0), _rules(0), _quit(false), _init(false), _mouseActive(true), _timeUntilNextFrame(0) { Options::reload = false; Options::mute = false; // Initialize SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) { throw Exception(SDL_GetError()); } Log(LOG_INFO) << "SDL initialized successfully."; // Initialize SDL_mixer if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { Log(LOG_ERROR) << SDL_GetError(); Log(LOG_WARNING) << "No sound device detected, audio disabled."; Options::mute = true; } else { initAudio(); } // trap the mouse inside the window SDL_WM_GrabInput(Options::captureMouse); // Set the window icon CrossPlatform::setWindowIcon(103, "openxcom.png"); // Set the window caption SDL_WM_SetCaption(title.c_str(), 0); SDL_EnableUNICODE(1); // Create display _screen = new Screen(); // Create cursor _cursor = new Cursor(9, 13); // Create invisible hardware cursor to workaround bug with absolute positioning pointing devices SDL_ShowCursor(SDL_ENABLE); Uint8 cursor = 0; SDL_SetCursor(SDL_CreateCursor(&cursor, &cursor, 1,1,0,0)); // Create fps counter _fpsCounter = new FpsCounter(15, 5, 0, 0); // Create blank language _lang = new Language(); _timeOfLastFrame = 0; }
void initmouse(void) { mouse = 1; setmousesens(M_MEDIUM); #ifdef PANDORA Uint8 noData = 0; fakeCursor = SDL_CreateCursor(&noData, &noData, 8, 1, 0, 0); SDL_ShowCursor(SDL_ENABLE); SDL_SetCursor(fakeCursor); #else //SDL_ShowCursor(SDL_DISABLE); #endif }
static void CreateCursors(void) { static Uint8 empty_cursor_data = 0; // Save the default cursor so it can be recalled later cursors[1] = SDL_GetCursor(); // Create an empty cursor cursors[0] = SDL_CreateCursor(&empty_cursor_data, &empty_cursor_data, 1, 1, 0, 0); }
static SDL_Cursor* create_cursor(surface surf) { const surface nsurf(make_neutral_surface(surf)); if(nsurf == NULL) { return NULL; } // The width must be a multiple of 8 (SDL requirement) #ifdef __APPLE__ size_t cursor_width = 16; #else size_t cursor_width = nsurf->w; if((cursor_width%8) != 0) { cursor_width += 8 - (cursor_width%8); } #endif std::vector<Uint8> data((cursor_width*nsurf->h)/8,0); std::vector<Uint8> mask(data.size(),0); // See http://sdldoc.csn.ul.ie/sdlcreatecursor.php for documentation // on the format that data has to be in to pass to SDL_CreateCursor surface_lock lock(nsurf); const Uint32* const pixels = reinterpret_cast<Uint32*>(lock.pixels()); for(int y = 0; y != nsurf->h; ++y) { for(int x = 0; x != nsurf->w; ++x) { Uint8 r,g,b,a; Uint8 trans = 0; Uint8 black = 0; const size_t index = y*cursor_width + x; if (static_cast<size_t>(x) < cursor_width) { SDL_GetRGBA(pixels[y*nsurf->w + x],nsurf->format,&r,&g,&b,&a); const size_t shift = 7 - (index % 8); trans = (a < 128 ? 0 : 1) << shift; black = (trans == 0 || (r+g + b) / 3 > 128 ? 0 : 1) << shift; data[index/8] |= black; mask[index/8] |= trans; } } } return SDL_CreateCursor(&data[0],&mask[0],cursor_width,nsurf->h,0,0); }
/* Create a cursor. */ int AG_SDL_CreateCursor(void *obj, AG_Cursor *ac) { SDL_Cursor *sc; sc = SDL_CreateCursor(ac->data, ac->mask, ac->w, ac->h, ac->xHot, ac->yHot); if (sc == NULL) { AG_SetError("SDL_CreateCursor failed"); return (-1); } ac->p = (void *)sc; return (0); }
SDL_Cursor * cursorFromXPM(const char * xpm[]) { int i, row, col; int width, height; Uint8 * data; Uint8 * mask; int hot_x, hot_y; SDL_Cursor * cursor = NULL; sscanf(xpm[0], "%d %d", &width, &height); data = (Uint8*)calloc(width/8*height,sizeof(Uint8)); mask = (Uint8*)calloc(width/8*height,sizeof(Uint8)); i = -1; for ( row=0; row<height; ++row ) { for ( col=0; col<width; ++col ) { if ( col % 8 ) { data[i] <<= 1; mask[i] <<= 1; } else { ++i; data[i] = mask[i] = 0; } switch (xpm[4+row][col]) { case 'X': data[i] |= 0x01; mask[i] |= 0x01; break; case '.': mask[i] |= 0x01; break; case ' ': break; } } } sscanf(xpm[4+row], "%d,%d", &hot_x, &hot_y); cursor = SDL_CreateCursor(data, mask, width, height, hot_x, hot_y); free(data); free(mask); return cursor; }
SDL_Cursor* init_system_cursor32(CURSOR cur) { int i, row, col; uint8_t data[4 * 32]; uint8_t mask[4 * 32]; int hot_x, hot_y; const char** image; ASSERT(cur < CURSOR_MAX, "Attempting to load non-existent cursor: %u", (unsigned int)cur); ASSERT(cursors[cur].cursor_num == cur, "Bad cursor mapping"); image = cursors[cur].image; i = -1; for (row = 0; row < 32; ++row) { for (col = 0; col < 32; ++col) { if (col % 8) { data[i] <<= 1; mask[i] <<= 1; } else { ++i; data[i] = mask[i] = 0; } switch (image[4 + row][col]) { case 'X': data[i] |= 0x01; mask[i] |= 0x01; break; case '.': mask[i] |= 0x01; break; case ' ': break; } } } sscanf(image[4 + row], "%d,%d", &hot_x, &hot_y); return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y); }
static VALUE sdl_setCursor_imp(VALUE mod,VALUE data,VALUE mask,VALUE w, VALUE h,VALUE hot_x,VALUE hot_y) { SDL_Cursor *newCursor; newCursor=SDL_CreateCursor(GETCSTR(data),GETCSTR(mask),NUM2INT(w), NUM2INT(h),NUM2INT(hot_x),NUM2INT(hot_y)); if( newCursor==NULL ) rb_raise(eSDLError,"cursor creation failed :%s",SDL_GetError()); SDL_SetCursor(newCursor); /* free old cursor */ if( cursor!=NULL ) SDL_FreeCursor(cursor); cursor=newCursor; return Qnil; }
int fs_ml_main_loop() { while (g_fs_ml_running) { fs_ml_event_loop(); process_video_events(); #if defined(WINDOWS) || defined (MACOSX) fs_ml_prevent_power_saving(); #endif fs_ml_render_iteration(); } if (g_fs_emu_video_fullscreen) { if (SDL_getenv("FSGS_RETURN_CURSOR_TO") && SDL_getenv("FSGS_RETURN_CURSOR_TO")[0]) { // we want to improve the transitioning from FS-UAE back to // e.g. FS-UAE Game Center - avoid blinking cursor - so we try // to move it (to the bottom right of the screen). This probably // requires that the cursor is not grabbed (SDL often keeps the // cursor in the center of the screen, then). int x = -1; int y = -1; sscanf(SDL_getenv("FSGS_RETURN_CURSOR_TO"), "%d,%d", &x, &y); if (x != -1 && y != -1) { fs_log("trying to move mouse cursor to x=%d y=%d\n", x, y); Uint8 data[] = "\0"; #ifdef USE_SDL2 SDL_SetWindowGrab(g_fs_ml_window, SDL_FALSE); #else SDL_WM_GrabInput(SDL_GRAB_OFF); #endif // setting invisible cursor so we won't see it when we // enable the cursor in order to move it SDL_Cursor *cursor = SDL_CreateCursor(data, data, 8, 1, 0, 0); SDL_SetCursor(cursor); SDL_ShowCursor(SDL_ENABLE); #ifdef USE_SDL2 SDL_WarpMouseInWindow(g_fs_ml_window, x, y); #else SDL_WarpMouse(x, y); #endif } } } return 0; }
static SDL_Cursor *make_sdl_cursor(unsigned char *combi) { unsigned char data[256]; unsigned char mask[256]; int y; /* separate the data & mask from the combined image */ for (y = 0; y < 16; y++) { data[y * 2 + 0] = combi[y * 4 + 0]; data[y * 2 + 1] = combi[y * 4 + 1]; mask[y * 2 + 0] = combi[y * 4 + 2]; mask[y * 2 + 1] = combi[y * 4 + 3]; } return SDL_CreateCursor(data, mask, 16, 16, 8, 8); }
int SDL_CursorInit(Uint32 multithreaded) { /* We don't have mouse focus, and the cursor isn't drawn yet */ SDL_cursorstate = CURSOR_VISIBLE; /* Create the default cursor */ if ( SDL_defcursor == NULL ) { SDL_defcursor = SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); SDL_SetCursor(SDL_defcursor); } /* Create a lock if necessary */ if ( multithreaded ) { SDL_cursorlock = SDL_CreateMutex(); } /* That's it! */ return(0); }
void es_createCursor(sdl_data *sd, int len, char *bp) { int sendlen; char *start; Uint8* data; Uint8* mask; int w,h, hotx, hoty, ds; SDL_Cursor* cursor; w = * (unsigned short *) bp; bp += sizeof(unsigned short); h = * (unsigned short *) bp; bp += sizeof(unsigned short); hotx = * (unsigned short *) bp; bp += sizeof(unsigned short); hoty = * (unsigned short *) bp; bp += sizeof(unsigned short); ds = * (unsigned short *) bp; bp += sizeof(unsigned short); data = (Uint8*) bp; mask = data + ds; cursor = SDL_CreateCursor(data, mask, w, h, hotx, hoty); bp = start = sdl_get_temp_buff(sd, 8); PUSHGLPTR(cursor, bp); sendlen = bp - start; sdl_send(sd, sendlen); }
MouseCursor::MouseCursor() { system_cursor = true; cursortex = 0; hidden = false; timeout = 3.0f; idle = timeout; scrollwheel = 0; left_click = false; right_click = false; middle_click = false; sdl_default_cursor = SDL_GetCursor(); Uint8 data[4*32]; Uint8 mask[4*32]; memset(data, 0, sizeof(data)); memset(mask, 0, sizeof(mask)); sdl_hidden_cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0); }
static SDL_Cursor *cursor_init(const char *image[]) { int i, row, col; Uint8 data[4*32]; Uint8 mask[4*32]; int hot_x, hot_y; i = -1; for (row=0; row<32; ++row) { for ( col=0; col<32; ++col ) { if ( col % 8 ) { data[i] <<= 1; mask[i] <<= 1; } else { ++i; data[i] = mask[i] = 0; } switch (image[row][col]) { case 'X': data[i] |= 0x01; mask[i] |= 0x01; break; case '.': mask[i] |= 0x01; break; case ' ': break; } } } sscanf(image[row], "%d,%d", &hot_x, &hot_y); return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y); }
static void I_InitInputs(void) { static Uint8 empty_cursor_data = 0; int nomouse_parm = M_CheckParm("-nomouse"); // check if the user wants to use the mouse mouse_enabled = usemouse && !nomouse_parm; SDL_PumpEvents(); // Save the default cursor so it can be recalled later cursors[0] = SDL_GetCursor(); // Create an empty cursor cursors[1] = SDL_CreateCursor(&empty_cursor_data, &empty_cursor_data, 8, 1, 0, 0); if (mouse_enabled) { CenterMouse(); MouseAccelChanging(); } I_InitJoystick(); }
Cursor::Cursor(char* xpmCursor[]) { const int width = 16, height = 24; int i, row, col; Uint8 data[4 * height]; Uint8 mask[4 * height]; int hot_x, hot_y; i = -1; for (row = 0; row < height; ++row) { for (col = 0; col < width; ++col) { if (col % 8) { data[i] <<= 1; mask[i] <<= 1; } else { ++i; data[i] = mask[i] = 0; } switch (xpmCursor[4+row][col]) { case 'X': data[i] |= 0x01; mask[i] |= 0x01; break; case '.': mask[i] |= 0x01; break; case ' ': break; } } } sscanf(xpmCursor[4+row], "%d,%d", &hot_x, &hot_y); #if !PLATFORM(AMIGAOS4) m_impl = SDL_CreateCursor(data, mask, width, height, hot_x, hot_y); #endif }
/** * Resets the screen surfaces based on the current display options, * as they don't automatically take effect. * @param resetVideo Reset display surface. */ void Screen::resetDisplay(bool resetVideo) { int width = Options::displayWidth; int height = Options::displayHeight; #ifdef __linux__ Uint32 oldFlags = _flags; #endif makeVideoFlags(); if (!_surface || (_surface && (_surface->getSurface()->format->BitsPerPixel != _bpp || _surface->getSurface()->w != _baseWidth || _surface->getSurface()->h != _baseHeight))) // don't reallocate _surface if not necessary, it's a waste of CPU cycles { if (_surface) delete _surface; _surface = new Surface(_baseWidth, _baseHeight, 0, 0, Screen::is32bitEnabled() ? 32 : 8); // only HQX needs 32bpp for this surface; the OpenGL class has its own 32bpp buffer if (_surface->getSurface()->format->BitsPerPixel == 8) _surface->setPalette(deferredPalette); } SDL_SetColorKey(_surface->getSurface(), 0, 0); // turn off color key! if (resetVideo || _screen->format->BitsPerPixel != _bpp) { #ifdef __linux__ // Workaround for segfault when switching to opengl if (!(oldFlags & SDL_OPENGL) && (_flags & SDL_OPENGL)) { Uint8 cursor = 0; char *_oldtitle = 0; SDL_WM_GetCaption(&_oldtitle, NULL); std::string title(_oldtitle); SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_ShowCursor(SDL_ENABLE); SDL_EnableUNICODE(1); SDL_WM_SetCaption(title.c_str(), 0); SDL_SetCursor(SDL_CreateCursor(&cursor, &cursor, 1,1,0,0)); } #endif Log(LOG_INFO) << "Attempting to set display to " << width << "x" << height << "x" << _bpp << "..."; _screen = SDL_SetVideoMode(width, height, _bpp, _flags); if (_screen == 0) { Log(LOG_ERROR) << SDL_GetError(); Log(LOG_INFO) << "Attempting to set display to default resolution..."; _screen = SDL_SetVideoMode(640, 400, _bpp, _flags); if (_screen == 0) { throw Exception(SDL_GetError()); } } Log(LOG_INFO) << "Display set to " << getWidth() << "x" << getHeight() << "x" << (int)_screen->format->BitsPerPixel << "."; } else { clear(); } Options::displayWidth = getWidth(); Options::displayHeight = getHeight(); _scaleX = getWidth() / (double)_baseWidth; _scaleY = getHeight() / (double)_baseHeight; _clear.x = 0; _clear.y = 0; _clear.w = getWidth(); _clear.h = getHeight(); double pixelRatioY = 1.0; if (Options::nonSquarePixelRatio && !Options::allowResize) { pixelRatioY = 1.2; } bool cursorInBlackBands; if (!Options::keepAspectRatio) { cursorInBlackBands = false; } else if (Options::fullscreen) { cursorInBlackBands = Options::cursorInBlackBandsInFullscreen; } else if (!Options::borderless) { cursorInBlackBands = Options::cursorInBlackBandsInWindow; } else { cursorInBlackBands = Options::cursorInBlackBandsInBorderlessWindow; } if (_scaleX > _scaleY && Options::keepAspectRatio) { int targetWidth = (int)floor(_scaleY * (double)_baseWidth); _topBlackBand = _bottomBlackBand = 0; _leftBlackBand = (getWidth() - targetWidth) / 2; if (_leftBlackBand < 0) { _leftBlackBand = 0; } _rightBlackBand = getWidth() - targetWidth - _leftBlackBand; _cursorTopBlackBand = 0; if (cursorInBlackBands) { _scaleX = _scaleY; _cursorLeftBlackBand = _leftBlackBand; } else { _cursorLeftBlackBand = 0; } } else if (_scaleY > _scaleX && Options::keepAspectRatio) { int targetHeight = (int)floor(_scaleX * (double)_baseHeight * pixelRatioY); _topBlackBand = (getHeight() - targetHeight) / 2; if (_topBlackBand < 0) { _topBlackBand = 0; } _bottomBlackBand = getHeight() - targetHeight - _topBlackBand; if (_bottomBlackBand < 0) { _bottomBlackBand = 0; } _leftBlackBand = _rightBlackBand = 0; _cursorLeftBlackBand = 0; if (cursorInBlackBands) { _scaleY = _scaleX; _cursorTopBlackBand = _topBlackBand; } else { _cursorTopBlackBand = 0; } } else { _topBlackBand = _bottomBlackBand = _leftBlackBand = _rightBlackBand = _cursorTopBlackBand = _cursorLeftBlackBand = 0; } if (isOpenGLEnabled()) { #ifndef __NO_OPENGL glOutput.init(_baseWidth, _baseHeight); glOutput.linear = Options::useOpenGLSmoothing; // setting from shader file will override this, though glOutput.set_shader(FileMap::getFilePath(Options::useOpenGLShader).c_str()); glOutput.setVSync(Options::vSyncForOpenGL); OpenGL::checkErrors = Options::checkOpenGLErrors; #endif } if (_screen->format->BitsPerPixel == 8) { setPalette(getPalette()); } }
static SDL_Cursor * RPI_CreateDefaultCursor(void) { return SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); }
void assign_cursor(int cursor_id) { int hot_x,hot_y,x,y,i,cur_color,cur_byte,cur_bit; Uint8 cur_mask=0; Uint8 cursor_data[16*16/8]; Uint8 cursor_mask[16*16/8]; Uint8 *cur_cursor_mem; //clear the data and mask for(i=0;i<16*16/8;i++)cursor_data[i]=0; for(i=0;i<16*16/8;i++)cursor_mask[i]=0; cur_cursor_mem=(Uint8 *)calloc(16*16*2, sizeof(char)); i=0; for(y=0;y<cursors_y_length;y++) for(x=cursor_id*16;x<cursor_id*16+16;x++) { cur_color=*(cursors_mem+(y*cursors_x_length+x)*2); *(cur_cursor_mem+i)=cur_color;//data cur_color=*(cursors_mem+(y*cursors_x_length+x)*2+1); *(cur_cursor_mem+i+256)=cur_color;//mask i++; } //ok, now put the data into the bit data and bit mask for(i=0;i<16*16;i++) { cur_color=*(cur_cursor_mem+i); cur_byte=i/8; cur_bit=i%8; if(cur_color)//if it is 0, let it alone, no point in setting it { switch(cur_bit) { case 0: cur_mask=128;break; case 1: cur_mask=64;break; case 2: cur_mask=32;break; case 3: cur_mask=16;break; case 4: cur_mask=8;break; case 5: cur_mask=4;break; case 6: cur_mask=2;break; case 7: cur_mask=1;break; } cursor_data[cur_byte]|=cur_mask; } } for(i=0;i<16*16;i++) { cur_color=*(cur_cursor_mem+i+256); cur_byte=i/8; cur_bit=i%8; if(cur_color)//if it is 0, let it alone, no point in setting it { if(cur_bit==0)cur_mask=128; else if(cur_bit==1)cur_mask=64; else if(cur_bit==2)cur_mask=32; else if(cur_bit==3)cur_mask=16; else if(cur_bit==4)cur_mask=8; else if(cur_bit==5)cur_mask=4; else if(cur_bit==6)cur_mask=2; else if(cur_bit==7)cur_mask=1; cursor_mask[cur_byte]|=cur_mask; } } hot_x=cursors_array[cursor_id].hot_x; hot_y=cursors_array[cursor_id].hot_y; cursors_array[cursor_id].cursor_pointer=(Uint8 *)SDL_CreateCursor(cursor_data,cursor_mask,16,16,hot_x,hot_y); free(cur_cursor_mem); }
static void set_video_mode() { #ifdef USE_SDL2 int flags = SDL_WINDOW_OPENGL; if (g_fs_emu_video_fullscreen_mode != FULLSCREEN_WINDOW && g_window_resizable) { flags |= SDL_WINDOW_RESIZABLE; } int x = g_window_x, y = g_window_y; int w = -1, h = -1; // if (g_initial_input_grab) { // flags |= SDL_WINDOW_INPUT_GRABBED; // g_has_input_grab = 1; // } if (g_fs_emu_video_fullscreen == 1) { w = g_fullscreen_width; h = g_fullscreen_height; //w = g_window_width; //h = g_window_height; if (g_fs_emu_video_fullscreen_mode == FULLSCREEN_WINDOW) { fs_log("using fullscreen window mode\n"); x = 0; y = 0; //w = g_fullscreen_width; //h = g_fullscreen_height; flags |= SDL_WINDOW_BORDERLESS; } else if (g_fs_emu_video_fullscreen_mode == FULLSCREEN_DESKTOP) { fs_log("using fullscreen desktop mode\n"); // the width and height will not be used for the fullscreen // desktop mode, only for the window when toggling fullscreen // state w = g_window_width; h = g_window_height; // x = 0; // y = 0; // w = g_fullscreen_width; // h = g_fullscreen_height; flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; } else { fs_log("using SDL_FULLSCREEN mode\n"); flags |= SDL_WINDOW_FULLSCREEN; } fs_log("setting (fullscreen) video mode %d %d\n", w, h); } else { w = g_window_width; h = g_window_height; fs_log("using windowed mode\n"); //SDL_putenv("SDL_VIDEO_WINDOW_POS="); fs_log("setting (windowed) video mode %d %d\n", w, h); } #if 0 Uint8 data[] = "\0"; SDL_Cursor *cursor = SDL_CreateCursor(data, data, 8, 1, 0, 0); SDL_SetCursor(cursor); #endif g_fs_ml_video_width = w; g_fs_ml_video_height = h; fs_log("SDL_CreateWindow(x=%d, y=%d, w=%d, h=%d, flags=%d)\n", x, y, w, h, flags); g_fs_ml_window = SDL_CreateWindow(g_window_title, x, y, w, h, flags); g_fs_ml_context = SDL_GL_CreateContext(g_fs_ml_window); #else int flags = SDL_DOUBLEBUF | SDL_OPENGL; if (g_fs_emu_video_fullscreen == 1) { g_fs_ml_video_width = g_fullscreen_width; g_fs_ml_video_height = g_fullscreen_height; if (g_fs_emu_video_fullscreen_mode == FULLSCREEN_WINDOW) { fs_log("using fullscreen window mode\n"); SDL_putenv("SDL_VIDEO_WINDOW_POS=0,0"); flags |= SDL_NOFRAME; //fs_ml_set_fullscreen_extra(); } else { fs_log("using SDL_FULLSCREEN mode\n"); flags |= SDL_FULLSCREEN; } fs_log("setting (fullscreen) video mode %d %d\n", g_fs_ml_video_width, g_fs_ml_video_height); g_sdl_screen = SDL_SetVideoMode(g_fs_ml_video_width, g_fs_ml_video_height, 0, flags); //update_viewport(); } else { fs_log("using windowed mode\n"); //SDL_putenv("SDL_VIDEO_WINDOW_POS="); g_fs_ml_video_width = g_window_width; g_fs_ml_video_height = g_window_height; if (g_window_resizable) { flags |= SDL_RESIZABLE; } fs_log("setting (windowed) video mode %d %d\n", g_fs_ml_video_width, g_fs_ml_video_height); g_sdl_screen = SDL_SetVideoMode(g_fs_ml_video_width, g_fs_ml_video_height, 0, flags); //update_viewport(); } #endif fs_ml_configure_window(); // FIXME: this can be removed g_fs_ml_opengl_context_stamp++; log_opengl_information(); }
static void sdlwindow_update_cursor_state(running_machine &machine, sdl_window_info *window) { #if (USE_XINPUT) // Hack for wii-lightguns: // they stop working with a grabbed mouse; // even a ShowCursor(SDL_DISABLE) already does this. // To make the cursor disappear, we'll just set an empty cursor image. unsigned char data[]={0,0,0,0,0,0,0,0}; SDL_Cursor *c; c=SDL_CreateCursor(data, data, 8, 8, 0, 0); SDL_SetCursor(c); #else #if (SDLMAME_SDL2) // do not do mouse capture if the debugger's enabled to avoid // the possibility of losing control if (!(machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)) { //FIXME: SDL1.3: really broken: the whole SDL code // will only work correct with relative mouse movements ... //SDL_SetRelativeMouseMode if (!window->fullscreen && !sdlinput_should_hide_mouse(machine)) { SDL_ShowCursor(SDL_ENABLE); if (SDL_GetWindowGrab(window->sdl_window )) SDL_SetWindowGrab(window->sdl_window, SDL_FALSE); } else { SDL_ShowCursor(SDL_DISABLE); if (!SDL_GetWindowGrab(window->sdl_window)) SDL_SetWindowGrab(window->sdl_window, SDL_TRUE); } SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility } #else // do not do mouse capture if the debugger's enabled to avoid // the possibility of losing control if (!(machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)) { if ( window->fullscreen || sdlinput_should_hide_mouse(machine) ) { SDL_ShowCursor(SDL_DISABLE); if (!SDL_WM_GrabInput(SDL_GRAB_QUERY)) { SDL_WM_GrabInput(SDL_GRAB_ON); } } else { SDL_ShowCursor(SDL_ENABLE); if (SDL_WM_GrabInput(SDL_GRAB_QUERY)) { SDL_WM_GrabInput(SDL_GRAB_OFF); } } } #endif #endif }
void Controller::update_mouse_cursor() { // FIXME: This could need some cleanup/feature enhancements if (client_draw_param->generic_brush.radius < 5.0f) return ; GrayscaleBuffer* brush = client_draw_param->brush_buffer; int w = brush->get_width(); int pitch = brush->get_width()/8 + 1; int h = brush->get_height(); int len = pitch * h; Uint8* data = new Uint8[len]; Uint8* mask = new Uint8[len]; memset(data, 0, len); memset(mask, 0, len); for(int y = 1; y < brush->get_height()-1; ++y) for(int x = 1; x < brush->get_width()-1; ++x) { int threshold = 64; Uint8 check = 0; if (((x / 1) % 2) ^ (y / 1) % 2) check = 1; if ((brush->at(x-1, y) < threshold && brush->at(x+1, y) > threshold) || (brush->at(x-1, y) > threshold && brush->at(x+1, y) < threshold) || (brush->at(x, y-1) < threshold && brush->at(x, y+1) > threshold) || (brush->at(x, y-1) > threshold && brush->at(x, y+1) < threshold) ) { // black data[y * pitch + x/8] |= (check << (7 - (x%8))); mask[y * pitch + x/8] |= (0x01 << (7 - (x%8))); } } if (w > 7 && h > 7) { int y = h / 2; int x = 0; for(x = w/2 - 3; x <= w/2 + 3; ++x) { data[y * pitch + x/8] |= (0x01 << (7 - (x%8))); mask[y * pitch + x/8] |= (0x01 << (7 - (x%8))); } x = w / 2; for(int y = h/2 - 3; y <= h/2 + 3; ++y) { data[y * pitch + x/8] |= (0x01 << (7 - (x%8))); mask[y * pitch + x/8] |= (0x01 << (7 - (x%8))); } y = h / 2; for(x = w/2 - 1; x <= w/2 + 1; ++x) { data[y * pitch + x/8] ^= (0x01 << (7 - (x%8))); mask[y * pitch + x/8] |= (0x01 << (7 - (x%8))); } x = w / 2; for(int y = h/2 - 1; y <= h/2 + 1; ++y) { data[y * pitch + x/8] ^= (0x01 << (7 - (x%8))); mask[y * pitch + x/8] |= (0x01 << (7 - (x%8))); } } SDL_Cursor* cursor = SDL_CreateCursor(data, mask, pitch*8, h, w/2, h/2); SDL_SetCursor(cursor); delete[] mask; delete[] data; }
/* * This thread will read the buttons in an interrupt like fashion, and * also initializes SDL_INIT_VIDEO and the surfaces * * it must be done in the same thread (at least on windows) because events only * work in the thread which called SDL_Init(SubSystem) with SDL_INIT_VIDEO * * This is an SDL thread and relies on preemptive behavoir of the host **/ static int sdl_event_thread(void * param) { SDL_InitSubSystem(SDL_INIT_VIDEO); #if (CONFIG_PLATFORM & PLATFORM_MAEMO) SDL_sem *wait_for_maemo_startup; #endif SDL_Surface *picture_surface = NULL; int width, height; int depth; Uint32 flags; /* Try and load the background image. If it fails go without */ if (background) { picture_surface = SDL_LoadBMP("UI256.bmp"); if (picture_surface == NULL) { background = false; DEBUGF("warn: %s\n", SDL_GetError()); } } /* Set things up */ if (background) { width = UI_WIDTH; height = UI_HEIGHT; } else { #ifdef HAVE_REMOTE_LCD if (showremote) { width = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH; height = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT; } else #endif { width = SIM_LCD_WIDTH; height = SIM_LCD_HEIGHT; } } depth = LCD_DEPTH; if (depth < 8) depth = 16; flags = SDL_HWSURFACE|SDL_DOUBLEBUF; #if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) /* Fullscreen mode for maemo app */ flags |= SDL_FULLSCREEN; #endif SDL_WM_SetCaption(UI_TITLE, NULL); if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, depth, flags)) == NULL) { panicf("%s", SDL_GetError()); } #if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) /* SDL touch screen fix: Work around a SDL assumption that returns relative mouse coordinates when you get to the screen edges using the touchscreen and a disabled mouse cursor. */ uint8_t hiddenCursorData = 0; SDL_Cursor *hiddenCursor = SDL_CreateCursor(&hiddenCursorData, &hiddenCursorData, 8, 1, 0, 0); SDL_ShowCursor(SDL_ENABLE); SDL_SetCursor(hiddenCursor); #endif if (background && picture_surface != NULL) SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); /* let system_init proceed */ SDL_SemPost((SDL_sem *)param); #if (CONFIG_PLATFORM & PLATFORM_MAEMO) /* Start maemo thread: Listen to display on/off events and battery monitoring */ wait_for_maemo_startup = SDL_CreateSemaphore(0); /* 0-count so it blocks */ SDL_Thread *maemo_thread = SDL_CreateThread(maemo_thread_func, wait_for_maemo_startup); #endif /* * finally enter the button loop */ gui_message_loop(); #if (CONFIG_PLATFORM & PLATFORM_MAEMO) /* Ensure maemo thread is up and running */ SDL_SemWait(wait_for_maemo_startup); SDL_DestroySemaphore(wait_for_maemo_startup); #if (CONFIG_PLATFORM & PLATFORM_MAEMO5) pcm_shutdown_gstreamer(); #endif g_main_loop_quit (maemo_main_loop); g_main_loop_unref(maemo_main_loop); SDL_WaitThread(maemo_thread, NULL); #endif #if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) SDL_FreeCursor(hiddenCursor); #endif if(picture_surface) SDL_FreeSurface(picture_surface); /* Order here is relevent to prevent deadlocks and use of destroyed sync primitives by kernel threads */ #ifdef HAVE_SDL_THREADS sim_thread_shutdown(); /* not needed for native threads */ #endif return 0; }
void CGeneral::InitCursor() { char cursor_data[22 + 1][18 + 1] = { "***** ***********", "**** )) **********", "**** )) **********", "**** )) **********", "**** )) **********", "**** )) ********", "**** )) )) *****", "**** )) )) )) ***", "**** )) )) )) ) **", " ) )) )) )) )) *", " )) )))))))) )) *", " ))) ))))))))))) *", "* )) ))))))))))) *", "** ) ))))))))))) *", "** ))))))))))))) *", "*** )))))))))))) *", "*** ))))))))))) **", "**** )))))))))) **", "**** )))))))))) **", "***** )))))))) ***", "***** )))))))) ***", "***** ***" }; unsigned char data[24 * 3], mask[24 * 3]; int i, j, index = -1; for (i = 0; i < 24 * 3; i++) { data[i] = mask[i] = 0; } for (i = 0; i < 22; i++) { for (j = 0; j < 24; j++) { if (j % 8 != 0) { data[index] <<= 1; mask[index] <<= 1; } else { index++; } if (j >= 18) { continue; } switch (cursor_data[i][j]) { case ')': mask[index] |= 1; break; case ' ': data[index] |= 1; mask[index] |= 1; break; } } } m_HandCursor = SDL_CreateCursor(data, mask, 24, 24, 0, 0); SDL_SetCursor(m_HandCursor); }
int main(int argc, char *argv[]) { SDL_Surface *screen; SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE; SDL_Cursor *cursor[3]; int current; /* Load the SDL library */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); return(1); } screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT); if (screen==NULL) { fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError()); return(1); } SDL_FillRect(screen, NULL, 0x664422); cursor[0] = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask, 16, 16, 8, 8); if (cursor[0]==NULL) { fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError()); SDL_Quit(); return(1); } cursor[1] = create_arrow_cursor(); if (cursor[1]==NULL) { fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",SDL_GetError()); SDL_FreeCursor(cursor[0]); SDL_Quit(); return(1); } cursor[2] = SDL_CreateCursor(small_cursor_data, small_cursor_mask, 8, 11, 3, 5); if (cursor[2]==NULL) { fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError()); SDL_Quit(); return(1); } current = 0; SDL_SetCursor(cursor[current]); while (!quit) { SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: current = (current + 1)%3; SDL_SetCursor(cursor[current]); break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) { quit = SDL_TRUE; } break; case SDL_QUIT: quit = SDL_TRUE; break; } } SDL_Flip(screen); SDL_Delay(1); } SDL_FreeCursor(cursor[0]); SDL_FreeCursor(cursor[1]); SDL_FreeCursor(cursor[2]); SDL_Quit(); return(0); }
int main(int argc, char **argv) { const SDL_Color whitecol = {255,255,255,255}; srand(time(NULL)); // a quick 'n dirty way of initializing random seed // load scores #ifdef WINDOWS FILE *scorefil = fopen("score.dat","rb"); #else char filen[256]; snprintf(filen,256,"%s/.nasuscore",getenv("HOME")); FILE *scorefil = fopen(filen,"rb"); chdir("/usr/share/games/nasu"); #endif if ( scorefil == NULL ) score = 0; else { fread((void *)&score,sizeof(unsigned long int),1,scorefil); fclose(scorefil); } // parameter parsing // -fullscreen specifies that the game is fullscreen // -res WxH specifies resolution // -noscale does not scale virtual screen float ScreenMult = 2; int resx = 640, resy = 480; bool bIsFullscreen = false; bool bNoScale = false; bool bNoSound = false; for ( int i=1; i<argc; i++ ) { if ( strcasecmp(argv[i],"-fullscreen") == 0 ) bIsFullscreen = true; else if ( strcasecmp(argv[i],"-res") == 0 ) { // expect next parameter to be a resolution in format WxH if ( argc <= i ) { fprintf(stderr,"Expected video resolution for parameter -res in format WxH\n"); return 1; } else { sscanf(argv[i+1],"%dx%d",&resx,&resy); if ( resx < 320 ) resx = 320; if ( resy < 240 ) resy = 240; } } else if ( strcasecmp(argv[i],"-noscale") == 0 ) bNoScale = true; else if ( strcasecmp(argv[i],"-nosound") == 0 ) bNoSound = true; } // calculate screen mult based on specified resolution int sm[2]; sm[0] = floor(resx/320); sm[1] = floor(resy/240); ScreenMult = (sm[0]>sm[1])?sm[1]:sm[0]; if ( bNoScale ) ScreenMult = 1; atexit(savescore); if ( SDL_Init(SDL_INIT_EVERYTHING) == -1 ) { fprintf(stderr,"couldn't initialize SDL (%s)\n", SDL_GetError()); return 1; } Uint8 blankcursor = 0; Uint8 blankcursormask = 0; SDL_Cursor *blankcur = SDL_CreateCursor(&blankcursor,&blankcursormask,1,1,0,0); SDL_SetCursor(blankcur); // load program icon SDL_Surface *icone = IMG_Load("nasuicon.png"); if ( icone != NULL ) SDL_WM_SetIcon(icone,NULL); SDL_WM_SetCaption("NASU","NASU"); // I don't really know why the two parameters but oh well~ SDL_Surface *mainscreen = NULL; // Create window. If SDL can't set a fullscreen mode it'll fall back to windowed if ( bIsFullscreen && (SDL_VideoModeOK(resx,resy,32,SDL_SWSURFACE|SDL_FULLSCREEN) != 0) ) mainscreen = SDL_SetVideoMode(resx,resy,32,SDL_SWSURFACE|SDL_FULLSCREEN); else { bIsFullscreen = false; mainscreen = SDL_SetVideoMode(resx,resy,32,SDL_SWSURFACE); } if ( mainscreen == NULL ) { fprintf(stderr,"couldn't create window (%s)\n", SDL_GetError()); fflush(stderr); return 1; } SDL_Rect scrrect; SDL_GetClipRect(mainscreen,&scrrect); // real screen that will be resized to fit SDL_Surface *_realscreen = SDL_CreateRGBSurface(SDL_SWSURFACE,320,240,mainscreen->format->BitsPerPixel,mainscreen->format->Rmask,mainscreen->format->Gmask,mainscreen->format->Bmask,mainscreen->format->Amask); SDL_Surface *realscreen = SDL_DisplayFormatAlpha(_realscreen); SDL_FreeSurface(_realscreen); SDL_Rect rscrrect; SDL_GetClipRect(realscreen,&rscrrect); // load up player SDL_Surface *_playersprites = IMG_Load("player.png"); SDL_Surface *playersprites = SDL_DisplayFormatAlpha(_playersprites); SDL_FreeSurface(_playersprites); NASU_Player player; player.graph = playersprites; player.res.w = 24; player.res.h = 24; player.pivot.x = 12.f; player.pivot.y = 12.f; player.pos.x = 160.f; player.pos.y = 149.f; player.vel.x = 0.f; player.vel.y = 0.f; player.tbox.x1 = -12.f; player.tbox.y1 = -4.f; player.tbox.x2 = 12.f; player.tbox.y2 = 12.f; player.dim.w = 24.f; player.dim.h = 24.f; player.scale = 1; player.bIsJumping = false; player.animframe = 0; player.bLeft = false; // load up main frame SDL_Surface *_mainframeimg = IMG_Load("mainscreen.png"); SDL_Surface *mainframeimg = SDL_DisplayFormatAlpha(_mainframeimg); SDL_FreeSurface(_mainframeimg); NASU_Actor mainframe; mainframe.graph = mainframeimg; mainframe.res.w = 320; mainframe.res.h = 240; mainframe.pivot.x = 0.f; mainframe.pivot.y = 0.f; mainframe.pos.x = 0.f; mainframe.pos.y = 0.f; mainframe.vel.x = 0.f; mainframe.vel.y = 0.f; mainframe.tbox.x1 = 0.f; mainframe.tbox.y1 = 0.f; mainframe.tbox.x2 = 320.f; mainframe.tbox.y2 = 240.f; mainframe.dim.w = 320.f; mainframe.dim.h = 240.f; mainframe.scale = 1; mainframe.animframe = 0; // load up game screen SDL_Surface *_gamescreenimg = IMG_Load("gamescreen.png"); SDL_Surface *gamescreenimg = SDL_DisplayFormatAlpha(_gamescreenimg); SDL_FreeSurface(_gamescreenimg); NASU_Actor gamescreen; gamescreen.graph = gamescreenimg; gamescreen.res.w = 184; gamescreen.res.h = 130; gamescreen.pivot.x = 0.f; gamescreen.pivot.y = 0.f; gamescreen.pos.x = 68.f; gamescreen.pos.y = 47.f; gamescreen.vel.x = 0.f; gamescreen.vel.y = 0.f; gamescreen.tbox.x1 = 0.f; gamescreen.tbox.y1 = 0.f; gamescreen.tbox.x2 = 320.f; gamescreen.tbox.y2 = 240.f; gamescreen.dim.w = 184.f; gamescreen.dim.h = 130.f; gamescreen.scale = 1; gamescreen.animframe = 0; // load up eggplants SDL_Surface *_nasuimg = IMG_Load("nasu.png"); SDL_Surface *nasuimg = SDL_DisplayFormatAlpha(_nasuimg); SDL_FreeSurface(_nasuimg); NASU_Actor nasu; nasu.graph = nasuimg; nasu.res.w = 8; nasu.res.h = 8; nasu.pivot.x = 4.f; nasu.pivot.y = 4.f; nasu.pos.x = 4.f; nasu.pos.y = 4.f; nasu.vel.x = 0.f; nasu.vel.y = 0.f; nasu.tbox.x1 = -3.f; nasu.tbox.y1 = -3.f; nasu.tbox.x2 = 3.f; nasu.tbox.y2 = 3.f; nasu.dim.w = 8.f; nasu.dim.h = 8.f; nasu.scale = 1; nasu.animframe = 0; NASU_Actor nasu_b; nasu_b.graph = nasuimg; nasu_b.res.w = 8; nasu_b.res.h = 8; nasu_b.pivot.x = 4.f; nasu_b.pivot.y = 4.f; nasu_b.pos.x = 12.f; nasu_b.pos.y = 4.f; nasu_b.vel.x = 0.f; nasu_b.vel.y = 0.f; nasu_b.tbox.x1 = -3.f; nasu_b.tbox.y1 = -3.f; nasu_b.tbox.x2 = 3.f; nasu_b.tbox.y2 = 3.f; nasu_b.dim.w = 8.f; nasu_b.dim.h = 8.f; nasu_b.scale = 1; nasu_b.animframe = 1; TTF_Init(); // load up score text TTF_Font *basefont = TTF_OpenFont("04B.TTF",8); NASU_ScrnText scoretxt; scoretxt.font = basefont; memset(&scoretxt.text,0,256); scoretxt.pos.x = 192.f; scoretxt.pos.y = 164.f; scoretxt.colr = whitecol; NASU_ScrnText scorenumtxt; scorenumtxt.font = basefont; memset(&scorenumtxt.text,0,256); scorenumtxt.pos.x = 240.f; scorenumtxt.pos.y = 164.f; scorenumtxt.colr = whitecol; NASU_ScrnText fpsnum; fpsnum.font = basefont; memset(&fpsnum.text,0,256); fpsnum.pos.x = 4.f; fpsnum.pos.y = 4.f; fpsnum.colr = whitecol; // load up the start/game over/paused text SDL_Surface *_textyimg = IMG_Load("texty.png"); SDL_Surface *textyimg = SDL_DisplayFormatAlpha(_textyimg); SDL_FreeSurface(_textyimg); NASU_Actor texty; texty.graph = textyimg; texty.res.w = 72; texty.res.h = 8; texty.pivot.x = 36.f; texty.pivot.y = 4.f; texty.pos.x = 160.f; texty.pos.y = 120.f; texty.vel.x = 0.f; texty.vel.y = 0.f; texty.tbox.x1 = 0.f; texty.tbox.y1 = 0.f; texty.tbox.x2 = 0.f; texty.tbox.y2 = 0.f; texty.dim.w = 72.f; texty.dim.h = 8.f; texty.scale = 1; texty.animframe = 2; // load up score sprites SDL_Surface *_pointsimg = IMG_Load("scores.png"); SDL_Surface *pointsimg = SDL_DisplayFormatAlpha(_pointsimg); SDL_FreeSurface(_pointsimg); NASU_Actor points1; points1.graph = pointsimg; points1.res.w = 40; points1.res.h = 12; points1.pivot.x = 20.f; points1.pivot.y = 6.f; points1.pos.x = 16.f; points1.pos.y = 16.f; points1.vel.x = 0.f; points1.vel.y = 0.f; points1.tbox.x1 = 0.f; points1.tbox.y1 = 0.f; points1.tbox.x2 = 0.f; points1.tbox.y2 = 0.f; points1.dim.w = 40.f; points1.dim.h = 12.f; points1.scale = 1; points1.animframe = 0; NASU_Actor points2; points2.graph = pointsimg; points2.res.w = 40; points2.res.h = 12; points2.pivot.x = 20.f; points2.pivot.y = 6.f; points2.pos.x = 16.f; points2.pos.y = 32.f; points2.vel.x = 0.f; points2.vel.y = 0.f; points2.tbox.x1 = 0.f; points2.tbox.y1 = 0.f; points2.tbox.x2 = 0.f; points2.tbox.y2 = 0.f; points2.dim.w = 40.f; points2.dim.h = 12.f; points2.scale = 1; points2.animframe = 1; NASU_Actor points3; points3.graph = pointsimg; points3.res.w = 40; points3.res.h = 12; points3.pivot.x = 20.f; points3.pivot.y = 6.f; points3.pos.x = 16.f; points3.pos.y = 48.f; points3.vel.x = 0.f; points3.vel.y = 0.f; points3.tbox.x1 = 0.f; points3.tbox.y1 = 0.f; points3.tbox.x2 = 0.f; points3.tbox.y2 = 0.f; points3.dim.w = 40.f; points3.dim.h = 12.f; points3.scale = 1; points3.animframe = 2; // load up sounds // TODO Pitch modification // step sounds: 1.1, 0.9, 1.5 // nasu get sounds: 1.0, 1.1, 1.5 Mix_Chunk *stepsnd[3]; Mix_Chunk *getsnd[3]; Mix_Chunk *losesnd; Mix_Music *titlemus; Mix_Music *gamemus; Mix_Music *losemus; if ( !bNoSound ) { Mix_Init(MIX_INIT_OGG); Mix_OpenAudio(44100,AUDIO_S16SYS,2,1024); Mix_AllocateChannels(8); stepsnd[0] = Mix_LoadWAV("nasustep1.ogg"); Mix_VolumeChunk(stepsnd[0], MIX_MAX_VOLUME*0.75f); stepsnd[1] = Mix_LoadWAV("nasustep2.ogg"); Mix_VolumeChunk(stepsnd[1], MIX_MAX_VOLUME*0.75f); stepsnd[2] = Mix_LoadWAV("nasustep3.ogg"); Mix_VolumeChunk(stepsnd[2], MIX_MAX_VOLUME*0.75f); getsnd[0] = Mix_LoadWAV("nasuget1.ogg"); Mix_VolumeChunk(getsnd[0], MIX_MAX_VOLUME); getsnd[1] = Mix_LoadWAV("nasuget2.ogg"); Mix_VolumeChunk(getsnd[1], MIX_MAX_VOLUME); getsnd[2] = Mix_LoadWAV("nasuget3.ogg"); Mix_VolumeChunk(getsnd[2], MIX_MAX_VOLUME); losesnd = Mix_LoadWAV("nasulose.ogg"); Mix_VolumeChunk(losesnd, MIX_MAX_VOLUME); titlemus = Mix_LoadMUS("nasutitle.ogg"); gamemus = Mix_LoadMUS("nasugame.ogg"); losemus = Mix_LoadMUS("nasuover.ogg"); Mix_VolumeMusic(MIX_MAX_VOLUME*0.35f); } // game variables float pts1time = 0.f, pts2time = 0.f, pts3time = 0.f; unsigned long int cscore = 0; unsigned short int GameState = 0; float TimeUntilNextNasu = 2.0f, TimeUntilNextNasuB = 25.f; bool bLostGame = false; float blink = 0.f; unsigned short int blinkcounter = 0; bool bDerp = false; NASU_Vect Nasupos, Nasubpos; float deltatime = 0.f, calfps = 0.f; bool bShowFPS = false; float difficulty = 0.f; uint32_t lastframe = 0; char scrname[256]; // start main loop! if ( !bNoSound ) Mix_PlayMusic(titlemus,-1); bool bQueriedQuit = false; lastframe = SDL_GetTicks(); while (!bQueriedQuit) { // input event polling SDL_Event Event; while ( SDL_PollEvent(&Event) ) { switch (Event.type) { case SDL_QUIT: bQueriedQuit = true; break; case SDL_KEYDOWN: switch (Event.key.keysym.sym) { case SDLK_ESCAPE: bQueriedQuit = true; break; case SDLK_F12: #ifdef WINDOWS SDL_SaveBMP(realscreen,"screenshot.bmp"); #else snprintf(scrname,256,"%s/nasu_screenshot.bmp",getenv("HOME")); SDL_SaveBMP(realscreen,scrname); #endif break; case SDLK_F10: bIsFullscreen = !bIsFullscreen; SDL_FreeSurface(mainscreen); mainscreen = NULL; if ( bIsFullscreen && (SDL_VideoModeOK(resx,resy,32,SDL_SWSURFACE|SDL_FULLSCREEN) != 0) ) mainscreen = SDL_SetVideoMode(resx,resy,32,SDL_SWSURFACE|SDL_FULLSCREEN); else { bIsFullscreen = false; mainscreen = SDL_SetVideoMode(resx,resy,32,SDL_SWSURFACE); } break; case SDLK_F11: bShowFPS = !bShowFPS; break; case SDLK_RETURN: if (GameState == 0) { if ( !bNoSound ) Mix_HaltMusic(); GameState = 3; texty.animframe = 3; } break; case SDLK_p: if ( (GameState == 1) && !bLostGame ) { GameState = 4; if ( !bNoSound ) Mix_PauseMusic(); texty.animframe = 4; } else if ( GameState == 4 ) { GameState = 1; if ( !bNoSound ) Mix_ResumeMusic(); texty.animframe = 3; } break; case SDLK_LEFT: case SDLK_a: if ( !bLostGame && (GameState == 1) && (player.pos.x+player.tbox.x1 > gamescreen.pos.x) ) { player.bLeft = true; player.vel.x = -60.f; } break; case SDLK_RIGHT: case SDLK_d: if ( !bLostGame && (GameState == 1) && (player.pos.x+player.tbox.x2 < gamescreen.pos.x+gamescreen.dim.w) ) { player.bLeft = false; player.vel.x = 60.f; } break; case SDLK_UP: case SDLK_w: case SDLK_z: case SDLK_LSHIFT: if ( !bLostGame && (GameState == 1) && !player.bIsJumping ) { player.bIsJumping = true; player.vel.y = -80.f; if ( !bNoSound ) Mix_PlayChannel(-1,stepsnd[2],0); } break; default: break; } break; case SDL_KEYUP: switch (Event.key.keysym.sym) { case SDLK_LEFT: case SDLK_a: if ( !bLostGame && (GameState == 1) ) player.vel.x = 0.f; break; case SDLK_RIGHT: case SDLK_d: if ( !bLostGame && (GameState == 1) ) player.vel.x = 0.f; break; default: break; } break; default: break; } } // clear screen SDL_FillRect(mainscreen,&scrrect,SDL_MapRGB(mainscreen->format,0,0,0)); SDL_FillRect(realscreen,&rscrrect,SDL_MapRGB(realscreen->format,0,0,0)); // process game logic switch (GameState) { case 0: // Title screen gamescreen.animframe = 2; RenderActor(realscreen,&gamescreen); snprintf(scorenumtxt.text,256,"%9u",score); scorenumtxt.pos.x = 320.f-(112.f+CalcTextW(&scorenumtxt)); scorenumtxt.pos.y = 144.f; scoretxt.pos.x = 112.f; scoretxt.pos.y = 144.f; snprintf(scoretxt.text,256,"Hi Score:"); RenderScrnText(realscreen,&scoretxt); RenderScrnText(realscreen,&scorenumtxt); break; case 2: // Lose screen gamescreen.animframe = 3; RenderActor(realscreen,&gamescreen); blink += deltatime; if ( blink >= 7.f ) { if ( !bNoSound ) Mix_PlayMusic(titlemus,-1); GameState = 0; } texty.animframe = 2; snprintf(scorenumtxt.text,256,"%9lu",cscore); scorenumtxt.pos.x = 320.f-(80.f+CalcTextW(&scorenumtxt)); scorenumtxt.pos.y = 164.f; scoretxt.pos.x = 168.f; scoretxt.pos.y = 164.f; snprintf(scoretxt.text,256,"Score:"); RenderScrnText(realscreen,&scoretxt); RenderScrnText(realscreen,&scorenumtxt); RenderActor(realscreen,&texty); break; case 3: // Game preparation gamescreen.animframe = 0; RenderActor(realscreen,&gamescreen); blink += deltatime; if ( blink > 0.25f ) { blinkcounter++; blink = 0.f; bDerp = !bDerp; if ( !bDerp ) texty.animframe = 3; else { if ( blinkcounter < 7 ) texty.animframe = 0; else texty.animframe = 1; } } if ( blinkcounter >= 8 ) { bDerp = false; blinkcounter = 0; GameState = 1; if ( !bNoSound ) Mix_PlayMusic(gamemus,-1); } difficulty = 0.f; cscore = 0; TimeUntilNextNasu = 2.0f; TimeUntilNextNasuB = 25.f; bLostGame = false; pts1time = 0.f; pts2time = 0.f; pts3time = 0.f; player.animframe = 0; player.bLeft = 0; player.bIsJumping = 0; player.pos.x = 160.f; player.pos.y = 149.f; nasu.pos.x = 4.f; nasu.pos.y = 4.f; nasu_b.pos.x = 12.f; nasu_b.pos.y = 4.f; points1.pos.x = 16.f; points1.pos.y = 16.f; points2.pos.x = 16.f; points2.pos.y = 32.f; points3.pos.x = 16.f; points3.pos.y = 48.f; RenderPlayer(realscreen,&player); snprintf(scorenumtxt.text,256,"%9lu",cscore); scorenumtxt.pos.x = 320.f-(80.f+CalcTextW(&scorenumtxt)); scorenumtxt.pos.y = 164.f; scoretxt.pos.x = 168.f; scoretxt.pos.y = 164.f; snprintf(scoretxt.text,256,"Score:"); RenderScrnText(realscreen,&scoretxt); RenderScrnText(realscreen,&scorenumtxt); RenderActor(realscreen,&texty); break; case 4: // Paused RenderActor(realscreen,&gamescreen); RenderPlayer(realscreen,&player); RenderActor(realscreen,&nasu); RenderActor(realscreen,&nasu_b); snprintf(scorenumtxt.text,256,"%9lu",cscore); scorenumtxt.pos.x = 320.f-(80.f+CalcTextW(&scorenumtxt)); scorenumtxt.pos.y = 164.f; scoretxt.pos.x = 168.f; scoretxt.pos.y = 164.f; snprintf(scoretxt.text,256,"Score:"); RenderScrnText(realscreen,&scoretxt); RenderScrnText(realscreen,&scorenumtxt); RenderActor(realscreen,&texty); break; default: // Main game if ( bLostGame ) { player.vel.x = 0.f; player.vel.y = 0.f; blink += deltatime; if ( blink > 0.125f ) { blinkcounter++; blink = 0.f; bDerp = !bDerp; if ( bDerp ) gamescreen.animframe = 0; else gamescreen.animframe = 1; } if ( blinkcounter >= 12 ) { blinkcounter = 0; if ( !bNoSound ) Mix_PlayMusic(losemus,0); blink = 0.f; GameState = 2; bDerp = false; } } else { gamescreen.animframe = 0; blink += deltatime; if ( blink > 0.125f ) { bDerp = !bDerp; blink = 0.f; if ( !bNoSound ) { if ( player.vel.x != 0.f && !player.bIsJumping ) { if ( bDerp ) Mix_PlayChannel(-1,stepsnd[0],0); else Mix_PlayChannel(-1,stepsnd[1],0); } } } if ( TimeUntilNextNasu > 0.f ) { TimeUntilNextNasu -= deltatime; nasu.pos.x = 4.f; nasu.pos.y = 4.f; if ( TimeUntilNextNasu <= 0.f ) { TimeUntilNextNasu = 0.f; nasu.pos.x = (float)(rand()%160+80); nasu.pos.y = 0.f; nasu.vel.y = 50.f+difficulty*0.3f; } } else { MoveActor(&nasu,deltatime); Nasupos = nasu.pos; if ( CollidePlayer(&nasu,&player) && player.bIsJumping ) { if ( (rand()%(30+(int)(difficulty*0.35f))) == 0 ) { cscore += 1000; if ( cscore > score ) score = cscore; TimeUntilNextNasu = 2.f-(difficulty*0.03f); if ( TimeUntilNextNasu <= 0.1f ) TimeUntilNextNasu = 0.1f; nasu.pos.x = 4.f; nasu.pos.y = 4.f; if ( !bNoSound ) Mix_PlayChannel(-1,getsnd[2],0); pts3time += 0.75f; points3.pos = Nasupos; points3.vel.y = -50.f; difficulty += 7.5f; } else { cscore += 10; if ( cscore > score ) score = cscore; TimeUntilNextNasu = 2.f-(difficulty*0.03f); if ( TimeUntilNextNasu <= 0.1f ) TimeUntilNextNasu = 0.1f; nasu.pos.x = 4.f; nasu.pos.y = 4.f; if ( !bNoSound ) Mix_PlayChannel(-1,getsnd[0],0); pts1time += 0.75f; points1.pos = Nasupos; points1.vel.y = -50.f; difficulty += 1.f; } } else if ( nasu.pos.y >= 160.f ) { if ( !bNoSound ) { Mix_HaltMusic(); Mix_PlayChannel(-1,losesnd,0); } bLostGame = true; } } if ( TimeUntilNextNasuB > 0.f ) { TimeUntilNextNasuB -= deltatime; nasu_b.pos.x = 12.f; nasu_b.pos.y = 4.f; if ( TimeUntilNextNasuB <= 0.f ) { TimeUntilNextNasuB = 0.f; int decideposb = rand()%2; switch (decideposb) { case 0: nasu_b.vel.x = (50.f+difficulty*0.15f); nasu_b.vel.y = 0.f; nasu_b.pos.x = 0.f; nasu_b.pos.y = 160.f; nasu_b.animframe = 2; break; default: nasu_b.vel.x = -(50.f+difficulty*0.15f); nasu_b.vel.y = 0.f; nasu_b.pos.x = 320.f; nasu_b.pos.y = 160.f; nasu_b.animframe = 1; break; } } } else { nasu_b.vel.y += (120.f+difficulty*0.75f)*deltatime; MoveActor(&nasu_b,deltatime); Nasubpos = nasu_b.pos; if ( CollidePlayer(&nasu_b,&player) && player.bIsJumping ) { cscore += 300; if ( cscore > score ) score = cscore; TimeUntilNextNasuB = 25.f+(difficulty*0.1f); nasu_b.pos.x = 12.f; nasu_b.pos.y = 4.f; if ( !bNoSound ) Mix_PlayChannel(-1,getsnd[1],0); pts2time += 0.75f; points2.pos = Nasubpos; points2.vel.y = -50.f; difficulty += 2.5f; } if ( (nasu_b.vel.x > 0.f) && (nasu_b.pos.x > gamescreen.pos.x+gamescreen.dim.w) ) { TimeUntilNextNasuB = 25.f+(difficulty*0.15f); nasu_b.pos.x = 12.f; nasu_b.pos.y = 4.f; } if ( (nasu_b.vel.x < 0.f) && (nasu_b.pos.x < gamescreen.pos.x) ) { TimeUntilNextNasuB = 25.f+(difficulty*0.15f); nasu_b.pos.x = 12.f; nasu_b.pos.y = 4.f; } if ( nasu_b.pos.y >= 160.f ) nasu_b.vel.y = -(80.f+difficulty*0.65f); } MovePlayer(&player,deltatime); if ( player.bIsJumping ) player.vel.y += 480.f*deltatime; if ( player.pos.y >= 149.f ) { player.pos.y = 149.f; player.bIsJumping = false; } if ( player.pos.x+player.tbox.x1 <= gamescreen.pos.x ) { player.pos.x = gamescreen.pos.x-player.tbox.x1; player.vel.x = 0; } if ( player.pos.x+player.tbox.x2 >= gamescreen.pos.x+gamescreen.dim.w ) { player.pos.x = (gamescreen.pos.x+gamescreen.dim.w)+player.tbox.x1; player.vel.x = 0; } if ( player.bIsJumping ) player.animframe = 3; else if ( player.vel.x != 0.f ) { if ( bDerp ) player.animframe = 2; else player.animframe = 1; } else player.animframe = 0; if ( pts1time > 0.f ) { pts1time -= deltatime; MoveActor(&points1,deltatime); if ( pts1time <= 0 ) { points1.vel.y = 0.f; points1.pos.x = 16.f; points1.pos.y = 16.f; } } if ( pts2time > 0.f ) { pts2time -= deltatime; MoveActor(&points2,deltatime); if ( pts2time <= 0 ) { points2.vel.y = 0.f; points2.pos.x = 16.f; points2.pos.y = 32.f; } } if ( pts3time > 0.f ) { pts3time -= deltatime; MoveActor(&points3,deltatime); if ( pts3time <= 0 ) { points3.vel.y = 0.f; points3.pos.x = 16.f; points3.pos.y = 48.f; } } } RenderActor(realscreen,&gamescreen); RenderPlayer(realscreen,&player); RenderActor(realscreen,&nasu); RenderActor(realscreen,&nasu_b); RenderActor(realscreen,&points1); RenderActor(realscreen,&points2); RenderActor(realscreen,&points3); snprintf(scorenumtxt.text,256,"%9lu",cscore); scorenumtxt.pos.x = 320.f-(80.f+CalcTextW(&scorenumtxt)); scorenumtxt.pos.y = 164.f; scoretxt.pos.x = 168.f; scoretxt.pos.y = 164.f; snprintf(scoretxt.text,256,"Score:"); RenderScrnText(realscreen,&scoretxt); RenderScrnText(realscreen,&scorenumtxt); break; } // render frame RenderActor(realscreen,&mainframe); // blit frame to screen SDL_Surface *resizedframe = Upscale(realscreen,ScreenMult); BlitAt(resizedframe,NULL,mainscreen,resx/2,resy/2,true,true); SDL_FreeSurface(resizedframe); // flip screen and calculate fps calfps = 1000.f/(SDL_GetTicks()-lastframe); deltatime = 1.f/calfps; snprintf(fpsnum.text,256,"%.2f",calfps); fpsnum.pos.x = resx-(4+CalcTextW(&fpsnum)); fpsnum.pos.y = 4.f; if ( bShowFPS ) RenderScrnText(mainscreen,&fpsnum); if (SDL_Flip(mainscreen) == -1) { fprintf(stderr,"error updating screen (%s)\n", SDL_GetError()); return 1; } lastframe = SDL_GetTicks(); } if ( !bNoSound ) { // Free audio Mix_FreeChunk(stepsnd[0]); Mix_FreeChunk(stepsnd[1]); Mix_FreeChunk(stepsnd[2]); Mix_FreeChunk(getsnd[0]); Mix_FreeChunk(getsnd[1]); Mix_FreeChunk(getsnd[2]); Mix_FreeChunk(losesnd); Mix_FreeMusic(titlemus); Mix_FreeMusic(gamemus); Mix_FreeMusic(losemus); Mix_AllocateChannels(0); Mix_CloseAudio(); } // Free surfaces SDL_FreeSurface(playersprites); SDL_FreeSurface(mainframeimg); SDL_FreeSurface(gamescreenimg); SDL_FreeSurface(nasuimg); SDL_FreeSurface(textyimg); // Free font TTF_CloseFont(basefont); // Quit stuff Mix_Quit(); TTF_Quit(); SDL_Quit(); return EXIT_SUCCESS; }
/** ** Initialize the video part for SDL. */ void InitVideoSdl() { Uint32 flags = 0; if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { #ifndef USE_WIN32 // Fix tablet input in full-screen mode SDL_putenv(strdup("SDL_MOUSE_RELATIVE=0")); #endif int res = SDL_Init( #ifdef DEBUG SDL_INIT_NOPARACHUTE | #endif SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_TIMER); if (res < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } // Clean up on exit atexit(SDL_Quit); #ifdef USE_MAEMO maemo_init(); #endif // If debug is enabled, Stratagus disable SDL Parachute. // So we need gracefully handle segfaults and aborts. #if defined(DEBUG) && !defined(USE_WIN32) signal(SIGSEGV, CleanExit); signal(SIGABRT, CleanExit); #endif // Set WindowManager Title if (!FullGameName.empty()) { SDL_WM_SetCaption(FullGameName.c_str(), FullGameName.c_str()); } else if (!Parameters::Instance.applicationName.empty()) { SDL_WM_SetCaption(Parameters::Instance.applicationName.c_str(), Parameters::Instance.applicationName.c_str()); } else { SDL_WM_SetCaption("Stratagus", "Stratagus"); } #if ! defined(USE_WIN32) && ! defined(USE_MAEMO) #if defined(USE_OPENGL) || defined(USE_GLES) // Make sure, that we not create OpenGL textures (and do not call OpenGL functions), when creating icon surface bool UseOpenGL_orig = UseOpenGL; UseOpenGL = false; #endif SDL_Surface *icon = NULL; CGraphic *g = NULL; struct stat st; std::string FullGameNameL = FullGameName; for (size_t i = 0; i < FullGameNameL.size(); ++i) { FullGameNameL[i] = tolower(FullGameNameL[i]); } std::string ApplicationName = Parameters::Instance.applicationName; std::string ApplicationNameL = ApplicationName; for (size_t i = 0; i < ApplicationNameL.size(); ++i) { ApplicationNameL[i] = tolower(ApplicationNameL[i]); } std::vector <std::string> pixmaps; pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameName + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameNameL + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameName + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameNameL + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationName + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationNameL + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationName + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationNameL + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + "Stratagus" + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + "stratagus" + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "Stratagus" + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "stratagus" + ".png"); for (size_t i = 0; i < pixmaps.size(); ++i) { if (stat(pixmaps[i].c_str(), &st) == 0) { if (g) { CGraphic::Free(g); } g = CGraphic::New(pixmaps[i].c_str()); g->Load(); icon = g->Surface; if (icon) { break; } } } if (icon) { SDL_WM_SetIcon(icon, 0); } if (g) { CGraphic::Free(g); } #if defined(USE_OPENGL) || defined(USE_GLES) UseOpenGL = UseOpenGL_orig; #endif #endif #ifdef USE_WIN32 HWND hwnd = NULL; HICON hicon = NULL; SDL_SysWMinfo info; SDL_VERSION(&info.version); if (SDL_GetWMInfo(&info)) { hwnd = info.window; } if (hwnd) { hicon = ExtractIcon(GetModuleHandle(NULL), Parameters::Instance.applicationName.c_str(), 0); } if (hicon) { SendMessage(hwnd, (UINT)WM_SETICON, ICON_SMALL, (LPARAM)hicon); SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hicon); } #endif } // Initialize the display #ifdef USE_MAEMO // TODO: Support window mode and portrait mode resolution on Maemo - Nokia N900 Video.FullScreen = 1; Video.Width = 800; Video.Height = 480; #endif #if !defined(USE_OPENGL) && !defined(USE_GLES) flags = SDL_HWSURFACE | SDL_HWPALETTE; #endif // Sam said: better for windows. /* SDL_HWSURFACE|SDL_HWPALETTE | */ if (Video.FullScreen) { flags |= SDL_FULLSCREEN; } #if defined(USE_OPENGL) || defined(USE_GLES) if (UseOpenGL) { #ifdef USE_GLES_NATIVE flags |= SDL_OPENGLES; #endif #ifdef USE_GLES_MAEMO if (SDL_GLES_Init(SDL_GLES_VERSION_1_1) < 0) { fprintf(stderr, "Couldn't initialize SDL_GLES: %s\n", SDL_GetError()); exit(1); } // Clean up GLES on exit atexit(SDL_GLES_Quit); flags |= SDL_SWSURFACE; #endif #ifdef USE_OPENGL flags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER; #endif } #endif if (!Video.Width || !Video.Height) { Video.Width = 640; Video.Height = 480; } if (!Video.Depth) { Video.Depth = 32; } #if defined(USE_OPENGL) || defined(USE_GLES) if (!Video.ViewportWidth || !Video.ViewportHeight) { Video.ViewportWidth = Video.Width; Video.ViewportHeight = Video.Height; } TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, flags); #else TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, Video.Depth, flags); #endif if (TheScreen && (TheScreen->format->BitsPerPixel != 16 && TheScreen->format->BitsPerPixel != 32)) { // Only support 16 and 32 bpp, default to 16 #if defined(USE_OPENGL) || defined(USE_GLES) TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, 16, flags); #else TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, 16, flags); #endif } if (TheScreen == NULL) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", Video.Width, Video.Height, Video.Depth, SDL_GetError()); exit(1); } Video.FullScreen = (TheScreen->flags & SDL_FULLSCREEN) ? 1 : 0; Video.Depth = TheScreen->format->BitsPerPixel; #if defined(USE_TOUCHSCREEN) && defined(USE_WIN32) // Must not allow SDL to switch to relative mouse coordinates // with touchscreen when going fullscreen. So we don't hide the // cursor, but instead set a transparent 1px cursor Uint8 emptyCursor[] = {'\0'}; Video.blankCursor = SDL_CreateCursor(emptyCursor, emptyCursor, 1, 1, 0, 0); SDL_SetCursor(Video.blankCursor); #else // Turn cursor off, we use our own. SDL_ShowCursor(SDL_DISABLE); #endif // Make default character translation easier SDL_EnableUNICODE(1); #if defined(USE_OPENGL) || defined(USE_GLES) if (UseOpenGL) { #ifdef USE_GLES_MAEMO SDL_GLES_Context *context = SDL_GLES_CreateContext(); if (!context) { fprintf(stderr, "Couldn't initialize SDL_GLES_CreateContext: %s\n", SDL_GetError()); exit(1); } if (SDL_GLES_MakeCurrent(context) < 0) { fprintf(stderr, "Couldn't initialize SDL_GLES_MakeCurrent: %s\n", SDL_GetError()); exit(1); } // atexit(GLES_DeleteContext(context)); #endif #ifdef USE_GLES_EGL // Get the SDL window handle SDL_SysWMinfo sysInfo; //Will hold our Window information SDL_VERSION(&sysInfo.version); //Set SDL version if (SDL_GetWMInfo(&sysInfo) <= 0) { fprintf(stderr, "Unable to get window handle\n"); exit(1); } eglDisplay = eglGetDisplay((EGLNativeDisplayType)sysInfo.info.x11.display); if (!eglDisplay) { fprintf(stderr, "Couldn't open EGL Display\n"); exit(1); } if (!eglInitialize(eglDisplay, NULL, NULL)) { fprintf(stderr, "Couldn't initialize EGL Display\n"); exit(1); } // Find a matching config EGLint configAttribs[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE}; EGLint numConfigsOut = 0; EGLConfig eglConfig; if (eglChooseConfig(eglDisplay, configAttribs, &eglConfig, 1, &numConfigsOut) != EGL_TRUE || numConfigsOut == 0) { fprintf(stderr, "Unable to find appropriate EGL config\n"); exit(1); } eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)sysInfo.info.x11.window, 0); if (eglSurface == EGL_NO_SURFACE) { fprintf(stderr, "Unable to create EGL surface\n"); exit(1); } // Bind GLES and create the context eglBindAPI(EGL_OPENGL_ES_API); EGLint contextParams[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE}; EGLContext eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL); if (eglContext == EGL_NO_CONTEXT) { fprintf(stderr, "Unable to create GLES context\n"); exit(1); } if (eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) == EGL_FALSE) { fprintf(stderr, "Unable to make GLES context current\n"); exit(1); } #endif InitOpenGL(); } #endif InitKey2Str(); ColorBlack = Video.MapRGB(TheScreen->format, 0, 0, 0); ColorDarkGreen = Video.MapRGB(TheScreen->format, 48, 100, 4); ColorLightBlue = Video.MapRGB(TheScreen->format, 52, 113, 166); ColorBlue = Video.MapRGB(TheScreen->format, 0, 0, 252); ColorOrange = Video.MapRGB(TheScreen->format, 248, 140, 20); ColorWhite = Video.MapRGB(TheScreen->format, 252, 248, 240); ColorLightGray = Video.MapRGB(TheScreen->format, 192, 192, 192); ColorGray = Video.MapRGB(TheScreen->format, 128, 128, 128); ColorDarkGray = Video.MapRGB(TheScreen->format, 64, 64, 64); ColorRed = Video.MapRGB(TheScreen->format, 252, 0, 0); ColorGreen = Video.MapRGB(TheScreen->format, 0, 252, 0); ColorYellow = Video.MapRGB(TheScreen->format, 252, 252, 0); UI.MouseWarpPos.x = UI.MouseWarpPos.y = -1; }