1 Replies - 339 Views - Last Post: 26 April 2010 - 05:58 AM Rate Topic: -----

#1 bijan311  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 31-January 10

.PNG image will not show up

Posted 25 April 2010 - 05:14 PM

When I compile the code below the file does not show up, and does not return -1

here is my code

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

#define KEY_NONE 0
#define KEY_DOWN 1
#define KEY_UP 2

SDL_Surface *buffer = 0;
SDL_Surface *man = 0;

char key[323] = {0};

void draw_surface(SDL_Surface* sur, int x, int y){
    SDL_Rect pos;
    pos.x = x;
    pos.y = y;

    SDL_BlitSurface(sur, 0, buffer, &pos);
}

SDL_Surface *load_image(const char *filename){

    SDL_Surface *img = IMG_Load(filename);

    if(img != 0){
        SDL_SetColorKey(img, SDL_SRCCOLORKEY, 0x002496);
    }
    return(img);
}

int main(int argc, char *argv[]){
    SDL_Init(SDL_INIT_VIDEO);
    buffer = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

    man = load_image("man.png");

    if(man == 0){
        return -1;
    }

    bool run = true;
    SDL_Event event;

    while(run){
        while(SDL_PollEvent(&event)){
        if(event.type == SDL_QUIT){
            run = false;
        }
        if(event.type == SDL_KEYDOWN){
            key[event.key.keysym.sym] = KEY_DOWN;
        }
        else if(event.type == SDL_KEYUP){
            key[event.key.keysym.sym] = KEY_UP;
        }
    }
    if(key[SDLK_ESCAPE] == KEY_UP){
        run = false;
    }
    draw_surface(man, 0, 0);
    }

    SDL_FreeSurface(man);
    SDL_Quit();
    return 1;
}


I'm not sure if this means anything but when I open the .exe from windows explorer the window closes automatically.

Is This A Good Question/Topic? 0
  • +

Replies To: .PNG image will not show up

#2 bijan311  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 31-January 10

Re: .PNG image will not show up

Posted 26 April 2010 - 05:58 AM

Oh, I forgot to flip the buffer... problem solved

This post has been edited by bijan311: 26 April 2010 - 05:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1