polska Posted June 22, 2012 at 07:28 PM Report Share #465021 Posted June 22, 2012 at 07:28 PM O programa apenas faz o load da imagem hello e mostra no canto superior esquerdo, mas deve mostrar ao centro sobreposta as 4 imagens de background.. #include "SDL.h" #include <string> /* The attributes of the screen */ const int SCREEN_WIDTH=640; // largura const int SCREEN_HEIGHT=480; // altura const int SCREEN_BPP=32; // bits per pixel -> 32-bit colour /* The surfaces that will be used */ SDL_Surface* message=NULL; //hello image SDL_Surface* screen=NULL; SDL_Surface* background=NULL; SDL_Surface *load_Image(std::string filename){ /*Temporary storage for the image that's loaded*/ SDL_Surface* loadedImage=NULL; /*The optimized image that will be used*/ SDL_Surface* optimizedImage=NULL; /*Load the image*/ loadedImage=SDL_LoadBMP(filename.c_str()); //a imagem não deve ser logo usada pois é de 24 bits e a janela(screen) é de 32 bits /*if image sucesseful loaded*/ if(loadedImage!=NULL){ //create an optimized image optimizedImage=SDL_DisplayFormat(loadedImage); //Free the old image -> Apagar da memória SDL_FreeSurface(loadedImage); } //return the oprimized image return optimizedImage; } void apply_surface(int x,int y,SDL_Surface* source,SDL_Surface* destination){ //Make a temporary rectangle to hold the offsets SDL_Rect offset; //Give the offsets to the rectangle offset.x=x; offset.y=y; //Blit the surface SDL_BlitSurface(source,NULL,destination,NULL); } int main(int argc, char* args[]) { //START SDL, se falhar faz return 1 para fechar o programa if(SDL_Init(SDL_INIT_EVERYTHING)==-1) return 1; //Set up the screen screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE); //Se falhar a criação do screen, fecha o programa if(screen==NULL) return 1; //Na parte superior da janela(caption), escreve Hello World SDL_WM_SetCaption("Hello World",NULL); //Load the images -> call funtion load_Image message=load_Image("hello.bmp"); background=load_Image("background.bmp"); //Apply the background to the screen apply_surface(0,0,background,screen); //canto superior esquerdo apply_surface(320, 0, background, screen); //canto superior direito apply_surface(0, 240, background, screen); //canto inferior esquerdo apply_surface(320, 240, background, screen); //canto inferior direito //Apply the message to the screen apply_surface(180,140,message,screen); //Update the screen if(SDL_Flip(screen)==-1) return 1; //Wait 2 seconds SDL_Delay(2000); //miliseconds //Free the surfaces SDL_FreeSurface(message); SDL_FreeSurface(background); //Quit SDL SDL_Quit(); return 0; } Corrige um sábio e ele mais sábio ficará. Corrige um ignorante e um inimigo ganharás. Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 22, 2012 at 07:33 PM Report Share #465022 Posted June 22, 2012 at 07:33 PM SDL_BlitSurface(source,NULL,destination,NULL); >> SDL_BlitSurface(source,NULL,destination,&offset); IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
polska Posted June 22, 2012 at 07:34 PM Author Report Share #465023 Posted June 22, 2012 at 07:34 PM SDL_BlitSurface(source,NULL,destination,NULL); >> SDL_BlitSurface(source,NULL,destination,&offset); It worked! 👍 Corrige um sábio e ele mais sábio ficará. Corrige um ignorante e um inimigo ganharás. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now