#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#include "SDL.h"
int main( int argc, char* argv[] )
{
SDL_Init ( SDL_INIT_VIDEO ) ;
SDL_Surface* screen;
screen = SDL_SetVideoMode ( 1024 , 768 , 0, SDL_FULLSCREEN ) ;
SDL_Surface* pic;
SDL_Rect dest;
dest.x = 500;
dest.y = 400;
int k = 1;
pic = SDL_LoadBMP("rect.bmp");
while(k == 1)
{
int b=5
SDL_Event event;
if(b==5)
{
// line of bug SDL_BlitSurface(pic,NULL,screen,&dest);
}
SDL_Flip(screen);
SDL_PollEvent(&event);
if ( event.type == SDL_QUIT )
{
k = 2;
}
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
k = 2;
}
}
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_UP )
{
dest.x +=1;
dest.y +=1;
SDL_BlitSurface(pic,NULL,screen,&dest);
SDL_Flip(screen);
SDL_FreeSurface(pic);
SDL_Surface* pic = SDL_LoadBMP("rect");
SDL_BlitSurface(pic,NULL,screen,&dest);
SDL_Flip(screen);
}
}
}
//done
return ( 0 ) ;
}
I need help with a bug in my program.
SDL_Surface* pic = SDL_LoadBMP("rect");
Needs to be:
SDL_Surface* pic = SDL_LoadBMP("rect.bmp");
I would strongly suggest that you do not release and reload thaat BMP every movement either [smile]. Just load it once, use it as much as you want, then release it at the very end. Take a look at my Starting with SDL tutorial in my sig. It shows how to do this quite well [wink] (It even has the source code!)
Needs to be:
SDL_Surface* pic = SDL_LoadBMP("rect.bmp");
I would strongly suggest that you do not release and reload thaat BMP every movement either [smile]. Just load it once, use it as much as you want, then release it at the very end. Take a look at my Starting with SDL tutorial in my sig. It shows how to do this quite well [wink] (It even has the source code!)
It still does it,but the only auto left is pic now.I tried
pic = SDL_SetVideoMode(),but it did'nt do anything.
pic = SDL_SetVideoMode(),but it did'nt do anything.
And after "pic = SDL_LoadBMP("rect.bmp");"
You should check the result also!
And do the same for the screen variable.
You should check the result also!
if (! pic) { cout << "Error: " << SDL_GetError() << endl; return 1;}
And do the same for the screen variable.
DOH! Also I need to correct my first post -
SDL_Surface* pic = SDL_LoadBMP("rect");
Needs to be:
pic = SDL_LoadBMP("rect.bmp");
What is happening is that you declare another variable in the same scope as the first variable, so it never reloads the correct bmp. Take out that SDL_Surface* and it should work, if not definitly do what qbic has suggested to make sure the image can be found in the first place. That is an important concept to keep in mind as well.
- Drew
SDL_Surface* pic = SDL_LoadBMP("rect");
Needs to be:
pic = SDL_LoadBMP("rect.bmp");
What is happening is that you declare another variable in the same scope as the first variable, so it never reloads the correct bmp. Take out that SDL_Surface* and it should work, if not definitly do what qbic has suggested to make sure the image can be found in the first place. That is an important concept to keep in mind as well.
- Drew
a couple 'o things(from my humble knowledge of SDL):
It will crash if the img is bigger than the window. Check that.
PollEvent(&event);
should be while(SDL_PollEvent(&event)
{
//end this while at the end of the keys checking,at the last if.
}
at the beginning of the source file, put atexit(SDL_Quit);
and change return 0; to exit(0);(I think you need to include stdlib.h or stdio.h).
It will crash if the img is bigger than the window. Check that.
PollEvent(&event);
should be while(SDL_PollEvent(&event)
{
//end this while at the end of the keys checking,at the last if.
}
at the beginning of the source file, put atexit(SDL_Quit);
and change return 0; to exit(0);(I think you need to include stdlib.h or stdio.h).
Quote:Original post by supercrazy7474
and change return 0; to exit(0);(I think you need to include stdlib.h or stdio.h).
Actually use both, it is not required, but it is ALWAYS good practice to return back to the OS.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement