// Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // // $Id: i_video.c,v 1.2 2007-07-19 14:38:37 unix Exp $ // // Copyright (C) 1993-1996 by id Software, Inc. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // $Log: i_video.c,v $ // Revision 1.2 2007-07-19 14:38:37 unix // // converted string end characters // // Revision 1.1.1.1 2007-07-19 14:34:10 unix // // First release // // // // DESCRIPTION: // DOOM graphics stuff for X11, UNIX. // 19.07.2007: Rewritten for SDL Support by [unix] // //----------------------------------------------------------------------------- static const char rcsid[] = "$Id: i_video.c,v 1.2 2007-07-19 14:38:37 unix Exp $"; #include #include #include #include #include #include #include #include #include #include #include "doomstat.h" #include "i_system.h" #include "v_video.h" #include "m_argv.h" #include "d_main.h" #include "doomdef.h" #include "SDL.h" SDL_Surface *sdl_screen; SDL_Color colors[256]; SDL_Event S_event; // // Translates the key currently in X_event // int xlatekey(SDL_keysym *key) { int rc = 0; switch(key->sym) { case SDLK_LEFT: rc = KEY_LEFTARROW; break; case SDLK_RIGHT: rc = KEY_RIGHTARROW; break; case SDLK_DOWN: rc = KEY_DOWNARROW; break; case SDLK_UP: rc = KEY_UPARROW; break; case SDLK_ESCAPE: rc = KEY_ESCAPE; break; case SDLK_RETURN: rc = KEY_ENTER; break; case SDLK_TAB: rc = KEY_TAB; break; case SDLK_F1: rc = KEY_F1; break; case SDLK_F2: rc = KEY_F2; break; case SDLK_F3: rc = KEY_F3; break; case SDLK_F4: rc = KEY_F4; break; case SDLK_F5: rc = KEY_F5; break; case SDLK_F6: rc = KEY_F6; break; case SDLK_F7: rc = KEY_F7; break; case SDLK_F8: rc = KEY_F8; break; case SDLK_F9: rc = KEY_F9; break; case SDLK_F10: rc = KEY_F10; break; case SDLK_F11: rc = KEY_F11; break; case SDLK_F12: rc = KEY_F12; break; case SDLK_1: rc = 0x0031; break; case SDLK_2: rc = 0x0032; break; case SDLK_3: rc = 0x0033; break; case SDLK_4: rc = 0x0034; break; case SDLK_5: rc = 0x0035; break; case SDLK_6: rc = 0x0036; break; case SDLK_7: rc = 0x0037; break; case SDLK_BACKSPACE: case SDLK_DELETE: rc = KEY_BACKSPACE; break; case SDLK_PAUSE: rc = KEY_PAUSE; break; case SDLK_KP_EQUALS: case SDLK_EQUALS: rc = KEY_EQUALS; break; case SDLK_KP_MINUS: case SDLK_MINUS: rc = KEY_MINUS; break; case SDLK_RSHIFT: case SDLK_LSHIFT: rc = KEY_RSHIFT; break; case SDLK_RCTRL: case SDLK_LCTRL: rc = KEY_RCTRL; break; case SDLK_RALT: case SDLK_LALT: case SDLK_RMETA: case SDLK_LMETA: rc = KEY_RALT; break; case SDLK_SPACE: rc = ' '; break; default: if (rc >= SDLK_SPACE && rc <= SDLK_BACKQUOTE) rc = rc - SDLK_SPACE + ' '; if (key->sym >= 'a' && key->sym <= 'z') { rc = key->sym; break; } break; } return rc; } void I_ShutdownGraphics(void) { SDL_FreeSurface(sdl_screen); SDL_ShowCursor(SDL_ENABLE); SDL_Quit; } // // I_StartFrame // void I_StartFrame (void) { // er? } static int lastmousex = 0; static int lastmousey = 0; boolean mousemoved = false; int I_MState(Uint8 buttonstate) { return 0 | (buttonstate & SDL_BUTTON(1) ? 1 : 0) | (buttonstate & SDL_BUTTON(2) ? 2 : 0) | (buttonstate & SDL_BUTTON(3) ? 4 : 0); } void I_GetEvent(SDL_Event *sdl_event) { event_t event; // put event-grabbing stuff in here switch (sdl_event->type) { case SDL_KEYDOWN: event.type = ev_keydown; event.data1 = xlatekey(&sdl_event->key.keysym); D_PostEvent(&event); // fprintf(stderr, "k"); break; case SDL_KEYUP: event.type = ev_keyup; event.data1 = xlatekey(&sdl_event->key.keysym); D_PostEvent(&event); // fprintf(stderr, "ku"); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: event.type = ev_mouse; event.data1 = I_MState(SDL_GetMouseState(NULL, NULL)); event.data2 = event.data3 = 0; D_PostEvent(&event); // fprintf(stderr, "bu"); break; case SDL_MOUSEMOTION: event.type = ev_mouse; event.data1 = I_MState(sdl_event->motion.state); event.data2 = sdl_event->motion.xrel << 5; event.data3 = -sdl_event->motion.yrel << 5; D_PostEvent(&event); mousemoved = true; break; default: break; } } // // I_StartTic // void I_StartTic (void) { SDL_Event sdl_event; while (SDL_PollEvent(&sdl_event)) I_GetEvent(&sdl_event); mousemoved = false; } // // I_UpdateNoBlit // void I_UpdateNoBlit (void) { // what is this? } // // I_FinishUpdate // void I_FinishUpdate (void) { // if(SDL_MUSTLOCK(sdl_screen)) { SDL_LockSurface(sdl_screen); //int w, i, h; byte *src; byte *dest; // do scale dest=sdl_screen->pixels; src=screens[0]; memcpy(dest,src,(320*200)); SDL_UnlockSurface(sdl_screen); //} SDL_Flip(sdl_screen); } // // I_ReadScreen // void I_ReadScreen (byte* scr) { memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT); } // // Palette stuff. // //static XColor colors[256]; void I_SetPalette(byte *palette) { register int i; register int c; static boolean firstcall = true; // initialize the colormap if (firstcall) { firstcall = false; for (i=0 ; i<256 ; i++) { colors[i].r = i; colors[i].g = i; colors[i].b = i; } } // set the SDL colormap entries for (i=0 ; i<256 ; i++) { c = gammatable[usegamma][*palette++]; colors[i].r = (c<<8) + c; c = gammatable[usegamma][*palette++]; colors[i].g = (c<<8) + c; c = gammatable[usegamma][*palette++]; colors[i].b = (c<<8) + c; } // store the colors to the current colormap SDL_SetColors(sdl_screen, colors, 0, 256); } // // I_SetPalette // // // This function is probably redundant, // if XShmDetach works properly. // ddt never detached the XShm memory, // thus there might have been stale // handles accumulating. // void grabsharedmemory(int size) { } void I_InitGraphics(void) { SDL_Init(SDL_INIT_VIDEO); sdl_screen=SDL_SetVideoMode(320, 200, 8, SDL_HWSURFACE|SDL_FULLSCREEN); //maybe hwpalette? SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(SDL_DISABLE); }