I would like show my code to you.
I have a problem, I can’t show my images and I don’t understand why.
tnx
**** File name: game.h ****
#ifndef SDL_H
#define SDL_H
#include “SDL.h”
#endif
//////////////////////////////////////////////////////////////////////
#ifndef GAME_H
#define GAME_H
class Game
{
protected:
SDL_Surface *screen;
public:
Game(Uint32);
Game();
~Game();
public:
int videomode(int,int,int,Uint32,char*,char*,const char*);
void upall(void);
};
#endif
//////////////////////////////////////////////////////////////////////
**** File name: game.cc ****
#include <stdlib.h>
#include “game.h”
//////////////////////////////////////////////////////////////////////
Game::Game()
{
}
//
Game::Game(Uint32 flag)
{
if (SDL_Init(flag) < 0)
fprintf(stderr, “game.cc function Game():\n\t\t%s\n”,
SDL_GetError());
atexit(SDL_Quit);
}
//
Game::~Game()
{
SDL_Quit();
}
//
int Game::videomode(int w, int h, int bpp, Uint32 flags, char* wint,
char* icot, const char* icof)
{
if ( (screen = SDL_SetVideoMode(w,h,bpp,flags) ) == NULL )
{
fprintf(stderr, “game.cc fucntion videomode():\n\t\t%s\n”,
SDL_GetError());
return 1;
}
SDL_WM_SetCaption(wint, icot);
if (icof != NULL)
SDL_WM_SetIcon(SDL_LoadBMP(icof), NULL);
}
//
void Game::upall(void)
{
SDL_UpdateRect(screen,0,0,0,0);
}
//////////////////////////////////////////////////////////////////////
**** File name: image.h ****
#ifndef GAME_H
#define GAME_H
#include “game.h”
#endif
//////////////////////////////////////////////////////////////////////
#ifndef IMAGE_H
#define IMAGE_H
class Image : public Game
{
public:
SDL_Surface *image;
public:
int load(const char* file);
void show(int sx, int sy, int sw, int sh, int dx, int dy, int dw,
int dh);
void remove(void);
};
#endif
//////////////////////////////////////////////////////////////////////
**** File name: image.cc ****
#include <stdlib.h>
#include “game.h”
#include “image.h”
//////////////////////////////////////////////////////////////////////
int Image::load(const char *file_name)
{
if ( (image = SDL_LoadBMP(file_name)) == NULL )
{
fprintf(stderr, “image.cc function load():\n\t\t%s\n”,
SDL_GetError());
return 1;
}
return 0;
}
//
void Image::show(int sx, int sy, int sw, int sh, int dx, int dy, int dw,
int dh)
{
SDL_Rect src, dst;
src.x = sx;
src.y = sy;
src.w = sw;
src.h = sh;
dst.x = dx;
dst.y = dy;
dst.w = dw;
dst.h = dh;
SDL_BlitSurface(image, &src, screen, &dst);
}
//
void Image::remove(void)
{
SDL_FreeSurface(image);
}
//////////////////////////////////////////////////////////////////////
**** File name: main.cc ****
#include “game.h”
#include “image.h”
int main(int argc, char* argv[])
{
bool quit = 0;
Game game(SDL_INIT_VIDEO);
game.videomode(640,480,16,SDL_HWSURFACE|SDL_DOUBLEBUF,“prova”,“prova”,NULL);
/*
while(!quit)
{
}
*/
Image bg;
bg.load(“background.bmp”);
bg.show(0,0,bg.image->w,bg.image->h,0,0,bg.image->w,bg.image->h);
Image main;
main.load(“main.bmp”);
main.show(0,0,main.image->w,main.image->h,0,0,main.image->w,main.image->h);
game.upall();
SDL_Delay(3000);
main.remove();
bg.remove();
return 0;
}
Tnx for your support
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031008/d2e06268/attachment.pgp