comparison src/SDL_compat.c @ 1682:7ae8018b2e5d SDL-1.3

Default palette entries to white, instead of black. More palettized video mode support...
author Sam Lantinga <slouken@libsdl.org>
date Fri, 16 Jun 2006 06:00:31 +0000
parents 80a5e6a4e1e2
children 396a35389351
comparison
equal deleted inserted replaced
1681:80a5e6a4e1e2 1682:7ae8018b2e5d
216 int i; 216 int i;
217 Uint32 window_flags; 217 Uint32 window_flags;
218 Uint32 desktop_format; 218 Uint32 desktop_format;
219 Uint32 desired_format; 219 Uint32 desired_format;
220 Uint32 texture_format; 220 Uint32 texture_format;
221 Uint32 surface_flags;
221 222
222 if (!SDL_GetVideoDevice()) { 223 if (!SDL_GetVideoDevice()) {
223 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { 224 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
224 return NULL; 225 return NULL;
225 } 226 }
260 } 261 }
261 SDL_VideoWindow = 262 SDL_VideoWindow =
262 SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags); 263 SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags);
263 if (!SDL_VideoWindow) { 264 if (!SDL_VideoWindow) {
264 return NULL; 265 return NULL;
266 }
267
268 window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
269 surface_flags = SDL_SCREEN_SURFACE;
270 if (window_flags & SDL_WINDOW_FULLSCREEN) {
271 surface_flags |= SDL_FULLSCREEN;
272 }
273 if (window_flags & SDL_WINDOW_OPENGL) {
274 surface_flags |= SDL_OPENGL;
275 }
276 if (window_flags & SDL_WINDOW_RESIZABLE) {
277 surface_flags |= SDL_RESIZABLE;
278 }
279 if (window_flags & SDL_WINDOW_BORDERLESS) {
280 surface_flags |= SDL_NOFRAME;
265 } 281 }
266 282
267 /* Set up the desired display mode */ 283 /* Set up the desired display mode */
268 desktop_mode = SDL_GetDesktopDisplayMode(); 284 desktop_mode = SDL_GetDesktopDisplayMode();
269 desktop_format = desktop_mode->format; 285 desktop_format = desktop_mode->format;
321 } 337 }
322 if (SDL_SetDisplayMode(&mode) < 0) { 338 if (SDL_SetDisplayMode(&mode) < 0) {
323 return NULL; 339 return NULL;
324 } 340 }
325 341
342 /* If we're in OpenGL mode, just create a stub surface and we're done! */
343 if (flags & SDL_OPENGL) {
344 SDL_VideoSurface =
345 SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
346 if (!SDL_VideoSurface) {
347 return NULL;
348 }
349 SDL_VideoSurface->flags |= surface_flags;
350 SDL_PublicSurface = SDL_VideoSurface;
351 return SDL_PublicSurface;
352 }
353
326 /* Create a renderer for the window */ 354 /* Create a renderer for the window */
327 if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) { 355 if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
328 return NULL; 356 return NULL;
329 } 357 }
330 358
343 /* Create the screen surface */ 371 /* Create the screen surface */
344 SDL_VideoSurface = SDL_CreateRGBSurfaceFromTexture(SDL_VideoTexture); 372 SDL_VideoSurface = SDL_CreateRGBSurfaceFromTexture(SDL_VideoTexture);
345 if (!SDL_VideoSurface) { 373 if (!SDL_VideoSurface) {
346 return NULL; 374 return NULL;
347 } 375 }
376 SDL_VideoSurface->flags |= surface_flags;
348 377
349 /* Set a default screen palette */ 378 /* Set a default screen palette */
350 if (SDL_VideoSurface->format->palette) { 379 if (SDL_VideoSurface->format->palette) {
351 SDL_VideoSurface->flags |= SDL_HWPALETTE; 380 SDL_VideoSurface->flags |= SDL_HWPALETTE;
352 SDL_DitherColors(SDL_VideoSurface->format->palette->colors, 381 SDL_DitherColors(SDL_VideoSurface->format->palette->colors,
353 SDL_VideoSurface->format->BitsPerPixel); 382 SDL_VideoSurface->format->BitsPerPixel);
354 SDL_SetTexturePalette(SDL_VideoTexture, 383 SDL_SetTexturePalette(SDL_VideoTexture,
355 SDL_VideoSurface->format->palette->colors, 0, 384 SDL_VideoSurface->format->palette->colors, 0,
385 SDL_VideoSurface->format->palette->ncolors);
386 SDL_SetDisplayPalette(SDL_VideoSurface->format->palette->colors, 0,
356 SDL_VideoSurface->format->palette->ncolors); 387 SDL_VideoSurface->format->palette->ncolors);
357 } 388 }
358 389
359 /* Create a shadow surface if necessary */ 390 /* Create a shadow surface if necessary */
360 if (((bpp != SDL_VideoSurface->format->BitsPerPixel) 391 if (((bpp != SDL_VideoSurface->format->BitsPerPixel)
375 SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0); 406 SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0);
376 } 407 }
377 if (!SDL_ShadowSurface) { 408 if (!SDL_ShadowSurface) {
378 return NULL; 409 return NULL;
379 } 410 }
411 surface_flags &= ~SDL_SCREEN_SURFACE;
412 surface_flags |= SDL_SHADOW_SURFACE;
413 SDL_ShadowSurface->flags |= surface_flags;
380 414
381 /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */ 415 /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
382 if (SDL_ShadowSurface->format->palette) { 416 if (SDL_ShadowSurface->format->palette) {
383 SDL_ShadowSurface->flags |= SDL_HWPALETTE; 417 SDL_ShadowSurface->flags |= SDL_HWPALETTE;
384 SDL_DitherColors(SDL_ShadowSurface->format->palette->colors, 418 SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
613 SDL_VERSION(&version); 647 SDL_VERSION(&version);
614 return &version; 648 return &version;
615 } 649 }
616 650
617 int 651 int
618 SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors, 652 SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
619 int firstcolor, int ncolors) 653 int firstcolor, int ncolors)
620 { 654 {
621 SDL_SetColors(surface, colors, firstcolor, ncolors); 655 SDL_SetColors(surface, colors, firstcolor, ncolors);
622 } 656 }
623 657
624 int 658 int
625 SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor, 659 SDL_SetScreenColors(SDL_Surface * screen, const SDL_Color * colors,
626 int ncolors) 660 int firstcolor, int ncolors)
627 { 661 {
628 SDL_Palette *pal; 662 SDL_Palette *pal;
629 int gotall; 663 int gotall;
630 int palsize; 664 int palsize;
631 665