Jump to content

[Resolvido] SDL background não aparece


Recommended Posts

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*/
 //create an optimized image
 //Free the old image -> Apagar da memória
//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
//Blit the surface
int main(int argc, char* args[]) {
//START SDL, se falhar faz return 1 para fechar o programa
 return 1;
//Set up the screen

//Se falhar a criação do screen, fecha o programa
 return 1;
//Na parte superior da janela(caption), escreve Hello World
SDL_WM_SetCaption("Hello World",NULL);
//Load the images -> call funtion load_Image
//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
//Update the screen
 return 1;
//Wait 2 seconds
SDL_Delay(2000); //miliseconds
//Free the surfaces
//Quit SDL

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

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
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.