From: Joel Dudley [mailto:Joel.Dudley@DevelopOnline.com]
Sent: Friday, August 03, 2001 12:16 PM
To: 'sdl at libsdl.org’
Subject: RE: [SDL] bitmap wont draw
Hmmm, I changed the code and still nothing is drawn. Since the image is
loaded the surface must exist somewhere. Why doesn’t it get drawn to the
screen with SDL_BlitSurface?? Thanks for the great responses!
#include “SDL.h”
#include <stdio.h>
#include <unistd.h>
SDL_Surface *load_bmp(char *fileName);
int main()
{
SDL_Surface *screen, *woods;
char myBmp[] = “Woods.bmp”;
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(800, 600, 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 = SDL_LoadBMP("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);
sleep(5);
SDL_Quit();
return(0);
}
-----Original Message-----
From: Ti Leggett [mailto:leggett@eecs.tulane.edu]
Sent: Friday, August 03, 2001 11:28 AM
To: 'sdl at libsdl.org’
Subject: Re: [SDL] bitmap wont draw
Couple of things I don’t understand why you’re doing them.
- What is the purpose of your load_bmp function? Why not just call
SDL_LoadBMP or IMG_Load?
- Why are you doing an UpdateRect immediately followed by a Flip? Why not
just call Flip?
I’d try substituting SDL_LoadBMP for your load_bmp to see if it then
works. If it does, you know it’s something wrong in your function (going
out of scope?).
On Fri, 3 Aug 2001, Joel Dudley wrote:
Hello,
Newbie here. I can’t seem to get my bitmap to draw. I thought it was
because I had to flip my buffer once everything was drawn but that did not
help. All I get is a black screen. It appears that the BMP is loading
successfully. Thanks in advance. The code follows.
#include “SDL.h”
#include <stdio.h>
#include <unistd.h>
SDL_Surface *load_bmp(char *fileName);
int main()
{
SDL_Surface *screen, *woods;
char myBmp[] = “Woods.bmp”;
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(800, 600, 16, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Could'nt set 640x480 video mode: %s\n",
SDL_GetError());
exit(-1);
}
printf("Set 640x480 at %d bpp mode\n",
screen->format->BitsPerPixel);
/* Load graphics */
woods = load_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);
SDL_Flip(screen);
sleep(5);
SDL_Quit();
return(0);
}
SDL_Surface *load_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);
}
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl