1 //**************************************************************************
5 //**************************************************************************
17 #include "p_local.h" // for P_AproxDistance
25 int screenWidth = SCREENWIDTH*2;
26 int screenHeight = SCREENHEIGHT*2;
28 int ratioLimit = 0; // Zero if none.
31 int DisplayTicker = 0;
35 extern void OGL_InitData();
36 extern void OGL_InitRenderer();
37 extern void OGL_ResetData();
38 extern void OGL_ResetLumpTexData();
40 void I_StartupNet (void);
41 void I_ShutdownNet (void);
42 void I_ReadExternDriver(void);
43 void GrabScreen (void);
45 extern int usemouse, usejoystick;
47 extern void **lumpcache;
50 externdata_t *i_ExternData;
51 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)
97 SDL_Color cmap[ 256 ];
107 for( ; c != cend; c++ )
109 //_outbyte(PEL_DATA, (gammatable[usegamma][*palette++])>>2);
111 c->r = gammatable[usegamma][*palette++];
112 c->g = gammatable[usegamma][*palette++];
113 c->b = gammatable[usegamma][*palette++];
115 SDL_SetColors( sdl_screen, cmap, 0, 256 );
120 ============================================================================
124 ============================================================================
127 byte *pcscreen, *destscreen, *destview;
138 extern int screenblocks;
142 if(UpdateState == I_NOUPDATE)
145 SDL_GL_SwapBuffers();
146 UpdateState = I_NOUPDATE;
149 //--------------------------------------------------------------------------
151 // PROC I_InitGraphics
153 //--------------------------------------------------------------------------
155 void I_InitGraphics(void)
159 Uint32 flags = SDL_OPENGL;
166 p = M_CheckParm ("-fullscreen");
168 flags |= SDL_FULLSCREEN;
169 setenv ("MESA_GLX_FX","fullscreen", 1);
171 setenv ("MESA_GLX_FX","disable",1);
173 p = M_CheckParm ("-height");
174 if (p && p < myargc - 1)
176 screenHeight = atoi (myargv[p+1]);
178 p = M_CheckParm ("-width");
179 if (p && p < myargc - 1) {
180 screenWidth = atoi(myargv[p+1]);
182 ST_Message("Screen size: %dx%d\n",screenWidth, screenHeight);
184 if(SDL_SetVideoMode(screenWidth, screenHeight, 8, flags) == NULL)
186 fprintf( stderr, "Couldn't set video mode %dx%d: %s\n",
187 screenWidth, screenHeight, SDL_GetError() );
193 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
195 // Print some OpenGL information.
196 ST_Message( "I_InitGraphics: OpenGL information:\n" );
197 ST_Message( " Vendor: %s\n", glGetString(GL_VENDOR) );
198 ST_Message( " Renderer: %s\n", glGetString(GL_RENDERER) );
199 ST_Message( " Version: %s\n", glGetString(GL_VERSION) );
200 ST_Message( " GLU Version: %s\n", gluGetString((GLenum)GLU_VERSION) );
202 // Check the maximum texture size.
203 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTexSize );
204 ST_Message(" Maximum texture size: %d\n", maxTexSize);
205 if( maxTexSize == 256 )
207 //ST_Message(" Is this Voodoo? Using size ratio limit.\n");
211 if( M_CheckParm("-3dfxtest") )
214 ST_Message(" 3dfx test mode.\n");
217 // Only grab if we want to
218 if (!M_CheckParm ("--nograb") && !M_CheckParm ("-g")) {
219 SDL_WM_GrabInput (SDL_GRAB_ON);
223 snprintf (text, 20, "HHexen v%s", HHEXEN_VERSION);
224 SDL_WM_SetCaption( text, "HHEXEN" );
227 //I_SetPalette( W_CacheLumpName("PLAYPAL", PU_CACHE) );
230 //--------------------------------------------------------------------------
232 // PROC I_ShutdownGraphics
234 //--------------------------------------------------------------------------
236 void I_ShutdownGraphics(void)
239 OGL_ResetLumpTexData ();
243 //===========================================================================
246 // Translates the key
249 int xlatekey(SDL_keysym *key)
256 case SDLK_LEFT: rc = KEY_LEFTARROW; break;
257 case SDLK_RIGHT: rc = KEY_RIGHTARROW; break;
258 case SDLK_DOWN: rc = KEY_DOWNARROW; break;
259 case SDLK_UP: rc = KEY_UPARROW; break;
260 case SDLK_ESCAPE: rc = KEY_ESCAPE; break;
261 case SDLK_RETURN: rc = KEY_ENTER; break;
262 case SDLK_F1: rc = KEY_F1; break;
263 case SDLK_F2: rc = KEY_F2; break;
264 case SDLK_F3: rc = KEY_F3; break;
265 case SDLK_F4: rc = KEY_F4; break;
266 case SDLK_F5: rc = KEY_F5; break;
267 case SDLK_F6: rc = KEY_F6; break;
268 case SDLK_F7: rc = KEY_F7; break;
269 case SDLK_F8: rc = KEY_F8; break;
270 case SDLK_F9: rc = KEY_F9; break;
271 case SDLK_F10: rc = KEY_F10; break;
272 case SDLK_F11: rc = KEY_F11; break;
273 case SDLK_F12: rc = KEY_F12; break;
275 case SDLK_INSERT: rc = KEY_INS; break;
276 case SDLK_DELETE: rc = KEY_DEL; break;
277 case SDLK_PAGEUP: rc = KEY_PGUP; break;
278 case SDLK_PAGEDOWN: rc = KEY_PGDN; break;
279 case SDLK_HOME: rc = KEY_HOME; break;
280 case SDLK_END: rc = KEY_END; break;
282 case SDLK_BACKSPACE: rc = KEY_BACKSPACE; break;
284 case SDLK_PAUSE: rc = KEY_PAUSE; break;
286 case SDLK_EQUALS: rc = KEY_EQUALS; break;
289 case SDLK_MINUS: rc = KEY_MINUS; break;
318 /* This processes SDL events */
319 void I_GetEvent(SDL_Event *Event)
328 mod = SDL_GetModState ();
329 if (mod & KMOD_RALT || mod & KMOD_LALT) {
330 if (Event->key.keysym.sym == 'g') {
331 if (SDL_WM_GrabInput (SDL_GRAB_QUERY) == SDL_GRAB_OFF)
332 SDL_WM_GrabInput (SDL_GRAB_ON);
334 SDL_WM_GrabInput (SDL_GRAB_OFF);
337 event.type = ev_keydown;
338 event.data1 = xlatekey(&Event->key.keysym);
339 H2_PostEvent(&event);
344 event.type = ev_keyup;
345 event.data1 = xlatekey(&Event->key.keysym);
346 H2_PostEvent(&event);
349 case SDL_MOUSEBUTTONDOWN:
350 case SDL_MOUSEBUTTONUP:
351 buttonstate = SDL_GetMouseState(NULL, NULL);
352 event.type = ev_mouse;
354 | (buttonstate & SDL_BUTTON(1) ? 1 : 0)
355 | (buttonstate & SDL_BUTTON(2) ? 2 : 0)
356 | (buttonstate & SDL_BUTTON(3) ? 4 : 0);
357 event.data2 = event.data3 = 0;
358 H2_PostEvent(&event);
361 case SDL_MOUSEMOTION:
362 /* Ignore mouse warp events */
363 if ( (Event->motion.x != SCREENWIDTH/2) ||
364 (Event->motion.y != SCREENHEIGHT/2) )
366 /* Warp the mouse back to the center */
367 event.type = ev_mouse;
369 | (Event->motion.state & SDL_BUTTON(1) ? 1 : 0)
370 | (Event->motion.state & SDL_BUTTON(2) ? 2 : 0)
371 | (Event->motion.state & SDL_BUTTON(3) ? 4 : 0);
372 event.data2 = Event->motion.xrel << 3;
373 event.data3 = -Event->motion.yrel << 3;
374 H2_PostEvent(&event);
387 void I_StartTic (void)
391 while ( SDL_PollEvent(&Event) )
397 ============================================================================
401 ============================================================================
413 int I_TimerISR (void)
420 ============================================================================
424 ============================================================================
435 void I_StartupMouse (void)
440 static int makeUniqueFilename( char* filename )
444 for( i = 0; i < 100; i++ )
446 sprintf( filename, "hexen%02d.bmp", i );
448 if( access( filename, F_OK ) == -1 )
450 // It does not exist.
465 if (makeUniqueFilename(filename)) {
466 image = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight,
467 24, 0x0000FF, 0x00FF00, 0xFF0000,0xFFFFFF);
468 temp = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight,
469 24, 0x0000FF, 0x00FF00, 0xFF0000, 0xFFFFFF);
471 glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB,
472 GL_UNSIGNED_BYTE, image->pixels);
473 for (idx = 0; idx < screenHeight; idx++)
475 memcpy(temp->pixels + 3 * screenWidth * idx,
476 (char *)image->pixels + 3
477 * screenWidth*(screenHeight - idx),
480 memcpy(image->pixels,temp->pixels,screenWidth * screenHeight * 3);
481 SDL_SaveBMP(image, filename);
482 SDL_FreeSurface(image);