[SDL] FLTK in combination with SDL

Torsten Giebl wizard at syntheticsoft.com
Sat Aug 18 14:46:01 PDT 2001


But that would make too much sense ;-P

Load_and_format_bmp() gives me the problem.

- Joel Dudley
<NewbieCode>
#include "SDL.h"
#include <stdio.h>

SDL_Surface *load_bmp(char *fileName);

int main()
{
	SDL_Surface *screen, *woods;
	SDL_Event event;
	SDLKey key;
	int done = 0;

	printf("Initializing SDL.\n");

	/* Initialize defaults, Video and Audio */

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		printf("Could not initialize SDL: %s.\n", SDL_GetError());
		exit(-1);
	}

	printf("SDL Initialized.\n");

	/* 
	 * Initialize the display in a 640x480 8-bit palettized mode
	 * requesting a software surface
	 */
	
	screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
	if ( screen == NULL ) {
		fprintf(stderr, "Could'nt set 800x600 video mode: %s\n",
SDL_GetError());
		exit(-1);
	}

	printf("Set 640x480 at %d bpp mode\n",
screen->format->BitsPerPixel);

	/* Load graphics */
	woods = load_and_format_bmp("Woods.bmp");

	/* Palettized screen modes will have a default pallette
	 *          * (a standard 8x8x4 color cube), but if the image is 
	 *                   * palettized as well, we can use that palette
for 
	 *                            * nicer color matching
	 *                                     */
	 if ( woods->format->palette && screen->format->palette) {
		 SDL_SetColors(screen, woods->format->palette->colors, 0,
			 woods->format->palette->ncolors);
        }

	/* Blit onto the screen surface */
	if(SDL_BlitSurface(woods, NULL, screen, NULL) != 0)
		fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

	SDL_UpdateRect(screen, 0, 0, woods->w, woods->h);

	do {

	while (SDL_PollEvent(&event) != 0) {
		if (event.type == SDL_KEYDOWN) {
			key = event.key.keysym.sym;

			if (key == SDLK_ESCAPE)
				done = 1;
		}
	}
	}
	while (done == 0);
	
	SDL_Quit();
	
	return(0);
}

/* loads the BMP and formats it for the video surface */

SDL_Surface *load_and_format_bmp(char *fileName)
{
	SDL_Surface *tmp, *surface;

	/* Load the BMP file into a surface */
	tmp = SDL_LoadBMP(fileName);
	if (tmp == NULL) {
		fprintf(stderr, "Could'nt load %s: %s\n", fileName,
SDL_GetError());
		return;
	}

	surface = SDL_DisplayFormat(tmp);
	SDL_FreeSurface(tmp);

	printf("Successfully loaded BMP file (%s)\n", fileName);

	return(surface);
}
</NewbieCode>

-----Original Message-----
From: Ryan C. Gordon [mailto:icculus at clutteredmind.org] 
Sent: Monday, August 06, 2001 6:28 PM
To: sdl at libsdl.org
Subject: RE: [SDL] windows funnyness


> Ironicly there was indeed a return in that function. Like so.
>
> return(screen);
>
> Which was a pointer to SDL_Surface.

...can we actually SEE this code, so we can stop guessing as to the
nature of the problem?

--ryan.




_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl




More information about the SDL mailing list