/* ** SWimp_SetPalette ** ** System specific palette setting routine. A NULL palette means ** to use the existing palette. The palette is expected to be in ** a padded 4-byte xRGB format. */ void SWimp_SetPalette( const unsigned char *palette ) { // MGL - what the f**k was kendall doing here?! // clear screen to black and change palette // for (i=0 ; i<vid.height ; i++) // memset (vid.buffer + i*vid.rowbytes, 0, vid.width); if ( !palette ) palette = ( const unsigned char * ) sw_state.currentpalette; if ( !sw_state.fullscreen ) { DIB_SetPalette( ( const unsigned char * ) palette ); } else { DDRAW_SetPalette( ( const unsigned char * ) palette ); } }
void DDraw_Init (void) { int i; if (DirectDrawCreate (NULL, &lpDirectDraw, NULL) != DD_OK) Sys_Error ("DirectDrawCreate failed"); if (lpDirectDraw->lpVtbl->SetCooperativeLevel (lpDirectDraw, mainwindow, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ) != DD_OK ) { Sys_Error ("SetCooperativeLevel failed"); } if (lpDirectDraw->lpVtbl->SetDisplayMode (lpDirectDraw, vid.width, vid.height, 8) != DD_OK ) { Sys_Error ("SetDisplayMode failed"); } memset( &ddsd, 0, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; Com_Printf ("...creating front buffer: "); if ( ( ddrval = lpDirectDraw->lpVtbl->CreateSurface( lpDirectDraw, &ddsd, &lpddsFrontBuffer, NULL ) ) != DD_OK ) { //Com_Printf ("failed - %s\n", DDrawError( ddrval ) ); Sys_Error (""); } Com_Printf ( "ok\n" ); /* ** create our back buffer */ ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; Com_Printf ("...creating back buffer: " ); if ( ( ddrval = lpddsFrontBuffer->lpVtbl->GetAttachedSurface( lpddsFrontBuffer, &ddsd.ddsCaps, &lpddsBackBuffer ) ) != DD_OK ) { //Com_Printf( "failed - %s\n", DDrawError( ddrval ) ); //goto fail; Sys_Error ("GetAttachedSurface failed"); } Com_Printf( "ok\n" ); /* ** create our rendering buffer */ memset( &ddsd, 0, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; ddsd.dwHeight = vid.height; ddsd.dwWidth = vid.width; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; Com_Printf( "...creating offscreen buffer: " ); if ( ( ddrval = lpDirectDraw->lpVtbl->CreateSurface( lpDirectDraw, &ddsd, &lpddsOffScreenBuffer, NULL ) ) != DD_OK ) { //Com_Printf( "failed - %s\n", DDrawError( ddrval ) ); goto fail; } Com_Printf( "ok\n" ); /* ** create our DIRECTDRAWPALETTE */ Com_Printf ( "...creating palette: " ); if ( ( ddrval = lpDirectDraw->lpVtbl->CreatePalette( lpDirectDraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palentries, &lpddpPalette, NULL ) ) != DD_OK ) { //Com_Printf( "failed - %s\n", DDrawError( ddrval ) ); goto fail; } Com_Printf( "ok\n" ); Com_Printf( "...setting palette: " ); if ( ( ddrval = lpddsFrontBuffer->lpVtbl->SetPalette( lpddsFrontBuffer, lpddpPalette ) ) != DD_OK ) { //Com_Printf ("failed - %s\n", DDrawError(ddrval)); goto fail; } Com_Printf( "ok\n" ); DDRAW_SetPalette( ( const unsigned char * ) currentpalette ); /* ** lock the back buffer */ memset( &ddsd, 0, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); Com_Printf ( "...locking backbuffer: " ); if ( ( ddrval = lpddsOffScreenBuffer->lpVtbl->Lock( lpddsOffScreenBuffer, NULL, &ddsd, DDLOCK_WAIT, NULL ) ) != DD_OK ) { //Com_Printf( "failed - %s\n", DDrawError( ddrval ) ); goto fail; } Com_Printf ("ok\n" ); //*ppbuffer = ddsd.lpSurface; vid.buffer = ddsd.lpSurface; vid.direct = vid.buffer; //*ppitch = ddsd.lPitch; vid.rowbytes = ddsd.lPitch; for ( i = 0; i < vid.height; i++ ) { //memset( *ppbuffer + i * *ppitch, 0, *ppitch ); memset( vid.buffer + i * vid.rowbytes, 0, vid.rowbytes ); } // sww_state.palettized = true; modestate = MS_FULLDIB; return; fail: Sys_Error ("directdraw failure"); }
void VID_SetPalette (unsigned char *palette) { setcurrentpalette (palette); DDRAW_SetPalette (currentpalette); }