Hello everybody
I am new to sdl and c/c++ …so be patient!
i use SDL-1.2.6 in mandrake 9.2
i try to understand how thinks work but is not very easy when you start,
i have some questions
i try the rotozoom with background one image
but when draw the picture to rotate i see all the picture in,
the main problem that i dont understand how to fix
is this (i thing)
if (SDL_LockSurface (background) == 0)
{
Uint32 black;
Uint8 *pixels;
black = SDL_MapRGB (background->format, 0, 0, 0);
pixels = (Uint8 *) background->pixels;
for (i = 0; i < background-> h; ++i)
{
memset (pixels, black, background->w *
background->format->BytesPerPixel);
pixels += background->pitch;
}
SDL_UnlockSurface (background);
this is for black screen but i have a picture and i dont know yet how to
make
below i have the small program
of course is full of mistakes (but i hope to lern one day!)-------------------------------------------------------------------------------
#include <SDL.h>
#include <SDL_image.h>
#include “SDL_rotozoom.h”
int main(void) {
FILE *file;
SDL_Surface *surface;
SDL_Surface *image;
SDL_Surface *screen;
SDL_Surface *background;
SDL_Surface *picture;
SDL_Rect rect;
SDL_Event event;
SDL_Rect src, dest;
Uint32 colorkey;
int done = 0;
int main(int argc, char *argv[]) {
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(1);
}
}
atexit(SDL_Quit);
void
HandleEvent () {
{
int i;
/* Set the screen to black */
if (SDL_LockSurface (background) == 0)
{
Uint32 black;
Uint8 *pixels;
black = SDL_MapRGB (background->format, 0, 0, 0);
pixels = (Uint8 *) background->pixels;
for (i = 0; i < background-> h; ++i)
{
memset (pixels, black, background->w *
background->format->BytesPerPixel);
pixels += background->pitch;
}
SDL_UnlockSurface (background);
}
}
}
screen = SDL_SetVideoMode(800, 600, 32, SDL_DOUBLEBUF | SDL_NOFRAME);
if(!screen){
printf(“Couldn’t set video mode: %s\n”, SDL_GetError());
exit(-1);
}
void
RotatePicture ( SDL_Surface * background, SDL_Surface * picture, int rotate,
int smooth)
{
SDL_Surface *rotozoom_picture;
SDL_Rect dest;
int framecount, framemax, frameinc;
float zoomf;
/* Rotate and display the picture */
framemax = 4 * 180;
frameinc = 2;
for (framecount = 180; framecount < framemax; framecount += frameinc)
{
if ((framecount %180) == 0)
frameinc++;
zoomf = (float) framecount / (float) framemax;
zoomf = 1.5 * zoomf * zoomf;
if ((rotozoom_picture =
rotozoomSurface (picture, framecount * rotate, zoomf,
smooth)) != NULL)
{
dest.x = (background->w - rotozoom_picture->w) / 2;;
dest.y = (background->h - rotozoom_picture->h) / 2;
dest.w = rotozoom_picture->w;
dest.h = rotozoom_picture->h;
if (SDL_BlitSurface (rotozoom_picture, NULL, screen, &dest) < 0)
{
fprintf (stderr, "Blit failed: %s\n", SDL_GetError ());
break;
}
SDL_FreeSurface (rotozoom_picture);
}
/* Display by flipping screens */
SDL_UpdateRect (screen, 0, 0, 0, 0);
}
if (rotate)
{
/* Final display with angle=0 */
if ((rotozoom_picture =
rotozoomSurface (picture, 0.1, zoomf, smooth)) != NULL)
{
dest.x = (background->w - rotozoom_picture->w) / 2;;
dest.y = (background->h - rotozoom_picture->h) / 2;
dest.w = rotozoom_picture->w;
dest.h = rotozoom_picture->h;
if (SDL_BlitSurface (rotozoom_picture, NULL, screen, &dest) < 0)
{
fprintf (stderr, "Blit failed: %s\n", SDL_GetError ());
return;
}
SDL_FreeSurface (rotozoom_picture);
}
/* Display by flipping screens */
SDL_UpdateRect (screen, 0, 0, 0, 0);
}
SDL_Delay (1000);
}
void
Draw (SDL_Surface * background)
{
background = SDL_LoadBMP (“sky.bmp”);
picture = SDL_LoadBMP (“ufo.bmp”);
src.x = 0; /* Draw the background. */
src.y = 0;
src.w = background->w;
src.h = background->h;
dest.x = 0;
dest.y = 0;
dest.w = background->w;
dest.h = background->h;
colorkey = SDL_MapRGB(picture->format, 0, 0, 255);
SDL_SetColorKey (picture, SDL_SRCCOLORKEY, colorkey);
SDL_BlitSurface (background, &src, screen, &dest);
RotatePicture (screen, picture, 2, SMOOTHING_ON);
SDL_FreeSurface (background);
SDL_FreeSurface (picture);
return;
}
SDL_ShowCursor(0);
Draw (background);
while(!done && SDL_WaitEvent(&event)!=-1)
{
switch(event.type){
case SDL_KEYDOWN:
switch( event.key.keysym.sym ){
case SDLK_ESCAPE:
done=1;
break;
case SDLK_F1:
background = SDL_LoadBMP("sky.bmp");
picture = SDL_LoadBMP ("ufo2.bmp");
SDL_BlitSurface(background, &src, screen, &dest);
colorkey = SDL_MapRGB(picture->format, 0, 0, 255);
SDL_SetColorKey(picture, SDL_SRCCOLORKEY,
colorkey);
RotatePicture (background, picture, 2, SMOOTHING_ON);
SDL_FreeSurface (background);
SDL_FreeSurface (picture);
break;
case SDLK_F2:
image = IMG_Load("sky2.jpg");
SDL_BlitSurface(image,0,screen,0);
SDL_Flip(screen);
SDL_Delay(5*1000);
screen = SDL_SetVideoMode(200, 200, 32, SDL_DOUBLEBUF | SDL_NOFRAME);
image = IMG_Load("sky2.jpg");
SDL_BlitSurface(image,0,screen,0);
SDL_Flip(screen);
break;
}
}
}
SDL_UpdateRect(screen, 0, 0, 0, 0);
return 0;
}
few small questions
how i delete the picture
like after e few minutes i want to delete the picture
in case SDLK_F2 i change the window how to make the picture to have the same
size? And is possible to place the window in the specific position?
i try to put some video with smpeg but i cant make it,
i want to put a video until the picture for background,
is this possible?
if yes can you put some code!
Thank you
Petros ppap
PS: Sorry for my english is not my native language i am from Greece
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail