1 //**************************************************************************
5 //**************************************************************************
16 #include "p_local.h" // for P_AproxDistance
23 int screenWidth = SCREENWIDTH*2;
24 int screenHeight = SCREENHEIGHT*2;
26 int ratioLimit = 0; // Zero if none.
29 int DisplayTicker = 0;
33 extern void OGL_InitData();
34 extern void OGL_InitRenderer();
35 extern void OGL_ResetData();
36 extern void OGL_ResetLumpTexData();
38 void I_StartupNet (void);
39 void I_ShutdownNet (void);
40 void I_ReadExternDriver(void);
41 void GrabScreen (void);
43 extern int usemouse, usejoystick;
45 extern void **lumpcache;
48 externdata_t *i_ExternData;
49 boolean useexterndriver;
57 boolean novideo; // if true, stay in text mode for debugging
66 //--------------------------------------------------------------------------
70 //--------------------------------------------------------------------------
72 void I_WaitVBL(int vbls)
80 SDL_Delay( 16667/1000 );
84 //--------------------------------------------------------------------------
88 // Palette source must use 8 bit RGB elements.
90 //--------------------------------------------------------------------------
92 void I_SetPalette(byte *palette)
94 // This is a nop in GL for the most part, but I need a way to
95 // force a palette update :/ - DDOI
99 ============================================================================
103 ============================================================================
106 byte *pcscreen, *destscreen, *destview;
117 extern int screenblocks;
121 if(UpdateState == I_NOUPDATE)
124 SDL_GL_SwapBuffers();
125 UpdateState = I_NOUPDATE;
128 //--------------------------------------------------------------------------
130 // PROC I_InitGraphics
132 //--------------------------------------------------------------------------
134 void I_InitGraphics(void)
137 Uint32 flags = SDL_OPENGL;
145 p = M_CheckParm ("-windowed");
147 flags |= SDL_FULLSCREEN;
148 setenv ("MESA_GLX_FX","fullscreen", 1);
150 setenv ("MESA_GLX_FX","disable",1);
152 p = M_CheckParm ("-height");
153 if (p && p < myargc - 1)
155 screenHeight = atoi (myargv[p+1]);
157 p = M_CheckParm ("-width");
158 if (p && p < myargc - 1) {
159 screenWidth = atoi(myargv[p+1]);
161 printf("Screen size: %dx%d\n",screenWidth, screenHeight);
163 if(SDL_SetVideoMode(screenWidth, screenHeight, 8, flags) == NULL)
165 fprintf( stderr, "Couldn't set video mode %dx%d: %s\n",
166 screenWidth, screenHeight, SDL_GetError() );
172 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
174 // Print some OpenGL information.
175 printf( "I_InitGraphics: OpenGL information:\n" );
176 printf( " Vendor: %s\n", glGetString(GL_VENDOR) );
177 printf( " Renderer: %s\n", glGetString(GL_RENDERER) );
178 printf( " Version: %s\n", glGetString(GL_VERSION) );
179 printf( " GLU Version: %s\n", gluGetString((GLenum)GLU_VERSION) );
181 // Check the maximum texture size.
182 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTexSize );
183 printf(" Maximum texture size: %d\n", maxTexSize);
184 if( maxTexSize == 256 )
186 //printf(" Is this Voodoo? Using size ratio limit.\n");
190 if( M_CheckParm("-3dfxtest") )
193 printf(" 3dfx test mode.\n");
196 // Only grab if we want to
197 if (M_CheckParm ("-nograb")) {
201 SDL_WM_GrabInput (1);
204 snprintf (text, 20, "HHeretic v%s", HHERETIC_VERSION);
206 SDL_WM_SetCaption( text, "HHERETIC" );
209 //I_SetPalette( W_CacheLumpName("PLAYPAL", PU_CACHE) );
212 //--------------------------------------------------------------------------
214 // PROC I_ShutdownGraphics
216 //--------------------------------------------------------------------------
218 void I_ShutdownGraphics(void)
221 OGL_ResetLumpTexData ();
225 //===========================================================================
228 // Translates the key
231 int xlatekey(SDL_keysym *key)
238 case SDLK_LEFT: rc = KEY_LEFTARROW; break;
239 case SDLK_RIGHT: rc = KEY_RIGHTARROW; break;
240 case SDLK_DOWN: rc = KEY_DOWNARROW; break;
241 case SDLK_UP: rc = KEY_UPARROW; break;
242 case SDLK_ESCAPE: rc = KEY_ESCAPE; break;
243 case SDLK_RETURN: rc = KEY_ENTER; break;
244 case SDLK_F1: rc = KEY_F1; break;
245 case SDLK_F2: rc = KEY_F2; break;
246 case SDLK_F3: rc = KEY_F3; break;
247 case SDLK_F4: rc = KEY_F4; break;
248 case SDLK_F5: rc = KEY_F5; break;
249 case SDLK_F6: rc = KEY_F6; break;
250 case SDLK_F7: rc = KEY_F7; break;
251 case SDLK_F8: rc = KEY_F8; break;
252 case SDLK_F9: rc = KEY_F9; break;
253 case SDLK_F10: rc = KEY_F10; break;
254 case SDLK_F11: rc = KEY_F11; break;
255 case SDLK_F12: rc = KEY_F12; break;
257 case SDLK_INSERT: rc = KEY_INS; break;
258 case SDLK_DELETE: rc = KEY_DEL; break;
259 case SDLK_PAGEUP: rc = KEY_PGUP; break;
260 case SDLK_PAGEDOWN: rc = KEY_PGDN; break;
261 case SDLK_HOME: rc = KEY_HOME; break;
262 case SDLK_END: rc = KEY_END; break;
264 case SDLK_BACKSPACE: rc = KEY_BACKSPACE; break;
266 case SDLK_PAUSE: rc = KEY_PAUSE; break;
268 case SDLK_EQUALS: rc = KEY_EQUALS; break;
271 case SDLK_MINUS: rc = KEY_MINUS; break;
300 /* This processes SDL events */
301 void I_GetEvent(SDL_Event *Event)
309 event.type = ev_keydown;
310 event.data1 = xlatekey(&Event->key.keysym);
315 event.type = ev_keyup;
316 event.data1 = xlatekey(&Event->key.keysym);
320 case SDL_MOUSEBUTTONDOWN:
321 case SDL_MOUSEBUTTONUP:
322 buttonstate = SDL_GetMouseState(NULL, NULL);
323 event.type = ev_mouse;
325 | (buttonstate & SDL_BUTTON(1) ? 1 : 0)
326 | (buttonstate & SDL_BUTTON(2) ? 2 : 0)
327 | (buttonstate & SDL_BUTTON(3) ? 4 : 0);
328 event.data2 = event.data3 = 0;
332 case SDL_MOUSEMOTION:
333 /* Ignore mouse warp events */
334 if ( (Event->motion.x != SCREENWIDTH/2) ||
335 (Event->motion.y != SCREENHEIGHT/2) )
337 /* Warp the mouse back to the center */
339 SDL_WarpMouse(SCREENWIDTH/2, SCREENHEIGHT/2);
341 event.type = ev_mouse;
343 | (Event->motion.state & SDL_BUTTON(1) ? 1 : 0)
344 | (Event->motion.state & SDL_BUTTON(2) ? 2 : 0)
345 | (Event->motion.state & SDL_BUTTON(3) ? 4 : 0);
346 event.data2 = Event->motion.xrel << 3;
347 event.data3 = -Event->motion.yrel << 3;
361 void I_StartTic (void)
365 while ( SDL_PollEvent(&Event) )
371 ============================================================================
375 ============================================================================
387 int I_TimerISR (void)
394 ============================================================================
398 ============================================================================
409 void I_StartupMouse (void)
414 static int makeUniqueFilename( char* filename )
418 for( i = 0; i < 100; i++ )
420 sprintf( filename, "hexen%02d.bmp", i );
422 if( access( filename, F_OK ) == -1 )
424 // It does not exist.
440 if (makeUniqueFilename(filename)) {
441 image = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight,
442 24, 0x0000FF, 0x00FF00, 0xFF0000,0xFFFFFF);
443 temp = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight,
444 24, 0x0000FF, 0x00FF00, 0xFF0000, 0xFFFFFF);
446 glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB,
447 GL_UNSIGNED_BYTE, image->pixels);
448 for (idx = 0; idx < screenHeight; idx++)
450 memcpy(temp->pixels + 3 * screenWidth * idx,
451 (char *)image->pixels + 3
452 * screenWidth*(screenHeight - idx),
455 memcpy(image->pixels,temp->pixels,screenWidth * screenHeight * 3);
456 SDL_SaveBMP(image, filename);
457 SDL_FreeSurface(image);