Sign in to follow this  

SDL beginner

This topic is 4245 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?
#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;
}

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

This topic is 4245 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this