Original Post
Hiya all I got all the image, SDL.dll, resource files and everythings on same folder and it should work... my questions is why doesnt work? I show the were the error when I run the program. I using Bloodshed Version 5. I would be delight if anyone can help me.... cheer [edit: use source tags for large blocks of code, please. -superpig] [Edited by - superpig on November 27, 2004 10:53:39 AM]
// "Graphics with SDL" turorial series Lesson 2
// by Marius Andra (http;//cone3d.gamedev.net/)
//
// NOTE: don't be alarmed if running this from
// Dev-C++ turns up a black screen. Compile it and then
// run it from the sources folder.
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
SDL_Surface *back; <<< ERROR
SDL_Surface *image;
SDL_Surface *screen;
int xpos=0,ypos=0;
int InitImages()
{
back = SDL_LoadBMP("bg.bmp");
image = SDL_LoadBMP("image.bmp");
return 0;
}
void DrawIMG(SDL_Surface *img, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);
}
void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_Rect dest2;
dest2.x = x2;
dest2.y = y2;
dest2.w = w;
dest2.h = h;
SDL_BlitSurface(img, &dest2, screen, &dest);
}
void DrawBG()
{
DrawIMG(back, 0, 0);
}
void DrawScene()
{
DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);
DrawIMG(image, xpos, ypos);
SDL_Flip(screen);
}
int main(int argc, char *argv[])
{
Uint8* keys;
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen=SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( screen == NULL )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}
InitImages();
DrawBG();
int done=0;
while(done == 0)
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}
keys = SDL_GetKeyState(NULL);
if ( keys[SDLK_UP] ) { ypos -= 1; }
if ( keys[SDLK_DOWN] ) { ypos += 1; }
if ( keys[SDLK_LEFT] ) { xpos -= 1; }
if ( keys[SDLK_RIGHT] ) { xpos += 1; }
DrawScene();
}
return 0;
}