Skip to main content
gamedev.net
🔒 Locked

SDL - ApplySurface function

Started by Stromberg 5 replies 3.2k views
Original Post
Stromberg
Stromberg
My function "ApplySurface" does not work, and by no stretch of the imagination I know why. Can you help me?

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
using namespace std;

SDL_Surface * LoadImage(const string &filename);
void ApplySurface(short x, short y, SDL_Surface *source, SDL_Surface *destination);

//Variables
SDL_Surface *screen = NULL;
SDL_Surface *image = NULL;
SDL_Event event;
bool end = false;

int main(int argc, char *args[])
{
    if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
    {
        return 1;
    }

    screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
    if(screen == NULL)
    {
        return 1;
    }

    image = LoadImage("monster.jpg");
    if(image == NULL)
    {
        return 1;
    }

    //ApplySurface(0,0,image,screen);  //Here it stops!

    if(SDL_Flip(screen) == -1)
    {
        return 1;
    }

    while(!end)
    {
        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                end = true;
            }
        }
    }


    return 0;
}

SDL_Surface * LoadImage(const string &filename)
{
    SDL_Surface * Image = NULL;
    SDL_Surface * OptimizedImage = NULL;
    Image = IMG_Load(filename.c_str());
    if((Image) != NULL)
    {
        OptimizedImage = SDL_DisplayFormat(Image);
        SDL_FreeSurface(Image);
    }
}

void ApplySurface(short x, short y, SDL_Surface *source, SDL_Surface *destination)
{
    SDL_Rect rect;
    rect.x = x;
    rect.y = y;
    SDL_BlitSurface(source, NULL, destination, ▭);
}
Thanks Stromberg.
SiCrane
SiCrane
It seems likely that your problem has something to do with the fact that your LoadImage() function never returns a value.
Stromberg
Stromberg
Oh, embarrassing :(
Stromberg
Stromberg
My IDE is Code::blocks, and the Compiler is MinGW. Know I fixed the option "Enable all compiler warnings", but it still not works! :(

http://www.bilder-space.de/show.php?file=QCcJNLhisoudBJm.JPG

Stromberg
sprite_hound
sprite_hound
Quote:
Original post by Stromberg
My IDE is Code::blocks, and the Compiler is MinGW. Know I fixed the option "Enable all compiler warnings", but it still not works! :(

http://www.bilder-space.de/show.php?file=QCcJNLhisoudBJm.JPG

Stromberg


What do you mean by "not works"? compiler error (if so post it)? crash (if so use a debugger to see where (and maybe why))?
Stromberg
Stromberg
The compiler sends no warnings.

Stromberg

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.