-1

IDE: Code::blocks Compiler: MinGW

I have SDL and SDL_image installed correctly (it doesn't give any errors when built). Everything compiles fine but when I run it, the SDL window comes up, but the image never blits, the window. I use SDL_image so I can load PNG images (or so I'm hoping).

The code:

#include <cstdlib>
#include <iostream>
#include "SDL_image.h"
#include <SDL/SDL.h>

int main ( int argc, char** argv )
{
    SDL_Surface* test = NULL;
    SDL_Surface* screen = NULL;
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    //Name the window
    SDL_WM_SetCaption( "Test-1", NULL );
    //Set up screen
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

    //Load image
    test = IMG_Load("Test.png");
    //Apply image to screen
    SDL_BlitSurface( test, NULL, screen, NULL );
    //Update Screen
    SDL_Flip( screen );

    //Pause
    SDL_Delay( 2000 );
    //Free the loaded image
    SDL_FreeSurface( test );

    //Quit SDL
    SDL_Quit();

    return 0;
}

1 Answers1

0

Maybe you could try creating a window and then a surface and then blit the image onto the window through the surface? Then you can try with this function: SDL_UpdateWindowSurface(*windowinstance*)

More information here: link (although this is loading a *.bmp file, but I'm sure the concept is the same). Also try the above mentioned answer also. Might be just that the image cannot be found...