1 //**************************************************************************
5 //**************************************************************************
15 #include "p_local.h" // for P_AproxDistance
22 int screenWidth = SCREENWIDTH*2;
23 int screenHeight = SCREENHEIGHT*2;
25 int ratioLimit = 0; // Zero if none.
28 int DisplayTicker = 0;
32 extern void OGL_InitData();
33 extern void OGL_InitRenderer();
34 extern void OGL_ResetData();
35 extern void OGL_ResetLumpTexData();
37 void I_StartupNet (void);
38 void I_ShutdownNet (void);
39 void I_ReadExternDriver(void);
40 void GrabScreen (void);
42 extern int usemouse, usejoystick;
44 extern void **lumpcache;
47 externdata_t *i_ExternData;
48 boolean useexterndriver;
56 boolean novideo; // if true, stay in text mode for debugging
65 //--------------------------------------------------------------------------
69 //--------------------------------------------------------------------------
71 void I_WaitVBL(int vbls)
79 SDL_Delay( 16667/1000 );
83 //--------------------------------------------------------------------------
87 // Palette source must use 8 bit RGB elements.
89 //--------------------------------------------------------------------------
91 void I_SetPalette(byte *palette)
93 // This is a nop in GL for the most part, but I need a way to
94 // force a palette update :/ - DDOI
98 ============================================================================
102 ============================================================================
105 byte *pcscreen, *destscreen, *destview;
116 extern int screenblocks;
120 if(UpdateState == I_NOUPDATE)
123 SDL_GL_SwapBuffers();
124 UpdateState = I_NOUPDATE;
127 //--------------------------------------------------------------------------
129 // PROC I_InitGraphics
131 //--------------------------------------------------------------------------
133 void I_InitGraphics(void)
136 Uint32 flags = SDL_OPENGL;
144 p = M_CheckParm ("-windowed");
146 flags |= SDL_FULLSCREEN;
147 setenv ("MESA_GLX_FX","fullscreen", 1);
149 setenv ("MESA_GLX_FX","disable",1);
151 p = M_CheckParm ("-height");
152 if (p && p < myargc - 1)
154 screenHeight = atoi (myargv[p+1]);
156 p = M_CheckParm ("-width");
157 if (p && p < myargc - 1) {
158 screenWidth = atoi(myargv[p+1]);
160 printf("Screen size: %dx%d\n",screenWidth, screenHeight);
162 if(SDL_SetVideoMode(screenWidth, screenHeight, 8, flags) == NULL)
164 fprintf( stderr, "Couldn't set video mode %dx%d: %s\n",
165 screenWidth, screenHeight, SDL_GetError() );
171 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
173 // Print some OpenGL information.
174 printf( "I_InitGraphics: OpenGL information:\n" );
175 printf( " Vendor: %s\n", glGetString(GL_VENDOR) );
176 printf( " Renderer: %s\n", glGetString(GL_RENDERER) );
177 printf( " Version: %s\n", glGetString(GL_VERSION) );
179 // Check the maximum texture size.
180 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTexSize );
181 printf(" Maximum texture size: %d\n", maxTexSize);
182 if( maxTexSize == 256 )
184 //printf(" Is this Voodoo? Using size ratio limit.\n");
188 if( M_CheckParm("-3dfxtest") )
191 printf(" 3dfx test mode.\n");
194 // Only grab if we want to
195 if (M_CheckParm ("-nograb")) {
199 SDL_WM_GrabInput (1);
202 snprintf (text, 20, "HHeretic v%s", HHERETIC_VERSION);
204 SDL_WM_SetCaption( text, "HHERETIC" );
207 //I_SetPalette( W_CacheLumpName("PLAYPAL", PU_CACHE) );
210 //--------------------------------------------------------------------------
212 // PROC I_ShutdownGraphics
214 //--------------------------------------------------------------------------
216 void I_ShutdownGraphics(void)
219 OGL_ResetLumpTexData ();
223 //===========================================================================
226 // Translates the key
229 int xlatekey(SDL_keysym *key)
236 case SDLK_LEFT: rc = KEY_LEFTARROW; break;
237 case SDLK_RIGHT: rc = KEY_RIGHTARROW; break;
238 case SDLK_DOWN: rc = KEY_DOWNARROW; break;
239 case SDLK_UP: rc = KEY_UPARROW; break;
240 case SDLK_ESCAPE: rc = KEY_ESCAPE; break;
241 case SDLK_RETURN: rc = KEY_ENTER; break;
242 case SDLK_F1: rc = KEY_F1; break;
243 case SDLK_F2: rc = KEY_F2; break;
244 case SDLK_F3: rc = KEY_F3; break;
245 case SDLK_F4: rc = KEY_F4; break;
246 case SDLK_F5: rc = KEY_F5; break;
247 case SDLK_F6: rc = KEY_F6; break;
248 case SDLK_F7: rc = KEY_F7; break;
249 case SDLK_F8: rc = KEY_F8; break;
250 case SDLK_F9: rc = KEY_F9; break;
251 case SDLK_F10: rc = KEY_F10; break;
252 case SDLK_F11: rc = KEY_F11; break;
253 case SDLK_F12: rc = KEY_F12; break;
255 case SDLK_INSERT: rc = KEY_INS; break;
256 case SDLK_DELETE: rc = KEY_DEL; break;
257 case SDLK_PAGEUP: rc = KEY_PGUP; break;
258 case SDLK_PAGEDOWN: rc = KEY_PGDN; break;
259 case SDLK_HOME: rc = KEY_HOME; break;
260 case SDLK_END: rc = KEY_END; break;
262 case SDLK_BACKSPACE: rc = KEY_BACKSPACE; break;
264 case SDLK_PAUSE: rc = KEY_PAUSE; break;
266 case SDLK_EQUALS: rc = KEY_EQUALS; break;
269 case SDLK_MINUS: rc = KEY_MINUS; break;
298 /* This processes SDL events */
299 void I_GetEvent(SDL_Event *Event)
307 event.type = ev_keydown;
308 event.data1 = xlatekey(&Event->key.keysym);
313 event.type = ev_keyup;
314 event.data1 = xlatekey(&Event->key.keysym);
318 case SDL_MOUSEBUTTONDOWN:
319 case SDL_MOUSEBUTTONUP:
320 buttonstate = SDL_GetMouseState(NULL, NULL);
321 event.type = ev_mouse;
323 | (buttonstate & SDL_BUTTON(1) ? 1 : 0)
324 | (buttonstate & SDL_BUTTON(2) ? 2 : 0)
325 | (buttonstate & SDL_BUTTON(3) ? 4 : 0);
326 event.data2 = event.data3 = 0;
330 case SDL_MOUSEMOTION:
331 /* Ignore mouse warp events */
332 if ( (Event->motion.x != SCREENWIDTH/2) ||
333 (Event->motion.y != SCREENHEIGHT/2) )
335 /* Warp the mouse back to the center */
337 SDL_WarpMouse(SCREENWIDTH/2, SCREENHEIGHT/2);
339 event.type = ev_mouse;
341 | (Event->motion.state & SDL_BUTTON(1) ? 1 : 0)
342 | (Event->motion.state & SDL_BUTTON(2) ? 2 : 0)
343 | (Event->motion.state & SDL_BUTTON(3) ? 4 : 0);
344 event.data2 = Event->motion.xrel << 3;
345 event.data3 = -Event->motion.yrel << 3;
359 void I_StartTic (void)
363 while ( SDL_PollEvent(&Event) )
369 ============================================================================
373 ============================================================================
385 int I_TimerISR (void)
392 ============================================================================
396 ============================================================================
407 void I_StartupMouse (void)
412 static int makeUniqueFilename( char* filename )
416 for( i = 0; i < 100; i++ )
418 sprintf( filename, "hexen%02d.bmp", i );
420 if( access( filename, F_OK ) == -1 )
422 // It does not exist.
438 if (makeUniqueFilename(filename)) {
439 image = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight,
440 24, 0x0000FF, 0x00FF00, 0xFF0000,0xFFFFFF);
441 temp = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight,
442 24, 0x0000FF, 0x00FF00, 0xFF0000, 0xFFFFFF);
444 glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB,
445 GL_UNSIGNED_BYTE, image->pixels);
446 for (idx = 0; idx < screenHeight; idx++)
448 memcpy(temp->pixels + 3 * screenWidth * idx,
449 (char *)image->pixels + 3
450 * screenWidth*(screenHeight - idx),
453 memcpy(image->pixels,temp->pixels,screenWidth * screenHeight * 3);
454 SDL_SaveBMP(image, filename);
455 SDL_FreeSurface(image);