#include "SDL/SDL.h"
const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32;
SDL_Surface *screen = NULL;
SDL_Surface *background = NULL;
SDL_Surface* Eng_LoadImage(char* file)
{
SDL_Surface *img = NULL;
SDL_Surface *tmp_img = NULL;
tmp_img = SDL_LoadBMP(file);
if(tmp_img != NULL)
{
img = SDL_DisplayFormat(tmp_img);
SDL_FreeSurface(tmp_img);
}
return img;
}
void Eng_DrawSurface(SDL_Surface *source, SDL_Surface *destination, int x, int y)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface( source, NULL, destination, &offset );
}
int main( int argc, char* args[] )
{
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
background = Eng_LoadImage("bugz.bmp");
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
Eng_DrawSurface(screen, background, 0,0);
SDL_Flip(screen);
SDL_WM_SetCaption( "Hello World", NULL );
SDL_Delay(2000);
//QuitSDL
SDL_Quit();
return 0;
}
SDL beginner
Hi maybe this answer is stupid enough to not be answered but i am having trouble with the following code to load a bitmap and draw it into screen
this line
img = SDL_DisplayFormat(tmp_img); gives me back NULL (tmp_img is not null)
i also tried passing tmp_img variable so that it would be the one drawn... but that doesnt help me either.
Any help?
SDL_DisplayFormat must know the display format of the main video screen. Hence you need to call it after SDL_SetVideoMode(...);
Could it be that you are blitting from the screen to the loaded image?
See here:
void Eng_DrawSurface(SDL_Surface *source, SDL_Surface *destination, int x, int y);
Eng_DrawSurface(screen, background, 0,0);
See here:
void Eng_DrawSurface(SDL_Surface *source, SDL_Surface *destination, int x, int y);
Eng_DrawSurface(screen, background, 0,0);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement