Original Post
Hi, im trying to blit two images together using SDL but everytime i compile i get: I call two functions in game.cpp, marked below. The functions are in images.cpp. game.cpp images.cpp Thanks in advance
error: cannot convert 'SDL_Surface' to 'SDL_Surface*' in assignment
#include <string>
#include <stdlib.h>
#include <iostream>
#include "SDL/SDL.h"
#include "game.h"
#include "images.h"
using namespace std;
//attributes of the screen
const int SCREEN_BPP = 32;
//surfaces to be used
SDL_Surface *cross = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
Game::Game()
{
initiate();
Image *image = new Image();
//create background
setBackground(*image);
}
Game::~Game(void)
{
}
bool Game::initiate()
{
//Initialize all SDL subsystems
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return false;
}
//set up the screen
screen = SDL_SetVideoMode(600, 400, SCREEN_BPP, SDL_SWSURFACE);
//If there was an error in setting up the screen
if( screen == NULL )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption("Residual Hope", NULL);
return true;
}
int Game::setBackground(Image image)
{
background = image.load_image("Pics/background.jpg"); <<<ERROR IS HERE
cross = image.load_image("Pics/cross.jpg"); <<<AND HERE
image.apply_surface(100, 100, cross, background);
//If there was a problem in loading the image
if(background == NULL)
{
cout << "Error loading image";
return 1;
}
}
#include <string.h>
#include <iostream>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "images.h"
using namespace std;
SDL_Surface *load_image(string filename)
{
//image to be loaded
SDL_Surface* loadedImage = NULL;
//optimized image
SDL_Surface* optimizedImage = NULL;
//load the image
loadedImage = IMG_Load(filename.c_str());
//if the image loaded
if(loadedImage != NULL)
{
//create optimized image
optimizedImage = SDL_DisplayFormat(loadedImage);
//free the old image
SDL_FreeSurface(loadedImage);
}
//return the optimized image
return optimizedImage;
}
void Image::apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
//temp rectangle to hold the offsets
SDL_Rect offset;
//give offsets to the rectangle
offset.x = x;
offset.y = y;
//blit the surface
SDL_BlitSurface(source, NULL, destination, &offset);
}