SDL problem

I'm having some problem on bliting an image on to my buffer in SDL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <SDL/SDL.h>
#include "SDL/SDL_image.h"



int x = 100;
int y = 100;

void MoveBall();

int main (int argc, char *args[])
{
    SDL_Init(SDL_INIT_EVERYTHING); //initialize
    SDL_WM_SetCaption("Yay!", NULL); //set caption
    Uint8 *key;
    SDL_Event event;
    while (event.type != SDL_QUIT)
    {
          SDL_PollEvent(&event);
          MoveBall();
          
          }
          
    
    //SDL_FreeSurface(buffer); - ikke nødvendig
    SDL_Quit();
    return 0;
}


void MoveBall()
{
     Uint8 *key;
     key = SDL_GetKeyState( NULL);
     if  (key[SDLK_UP])
     ++y;
     else if (key[SDLK_DOWN])
     --y;
     if (key[SDLK_RIGHT])
     ++x;
     else if (key[SDLK_LEFT])
     --x;
     SDL_Rect tmp = {x, y, 40, 40};
     SDL_Surface *buffer;
     buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE);
     SDL_Surface *ball;
     ball = IMG_Load("ball.png");
     SDL_BlitSurface(ball, NULL, buffer, tmp);

     SDL_Flip (buffer);
     SDL_FreeSurface(buffer);
     SDL_FreeSurface(ball);
     }
     
     


The error is: cannot convert `SDL_Rect' to `SDL_Rect*' for argument `4' to `int SDL_UpperBlit(SDL_Surface*, SDL_Rect*, SDL_Surface*, SDL_Rect*)'
SDL_BlitSurface(InputSurface, &InputRect, OutputSurface, &OutputRect);

Note a &-operator at the calls for the SDLRect!

For your code change row 48 to
SDL_BlitSurface(ball, NULL, buffer, &tmp);

EDIT:
RTFM (sorry! :) ): http://wiki.libsdl.org/moin.cgi/CategoryAPI

EDIT2:
http://wiki.libsdl.org/moin.cgi/SDL_BlitSurface?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29
JUST by looking from manuals you WOULD see that SDL_BlitSurface takes as parameters 4 pointers (or memory addresses).
SO, if you create a variable as "normal" it is task for the computer handle variable address. BUT if you want to pass an address of a single variable to function you need to use &-operator.
Of course pointers (like SDL_Surface's) are created as a pointer (like SDL_Surface * screen;) so that if you give variable name "straight" if will give the address that type of variable.

p.s. sorry for bad english
Last edited on
Topic archived. No new replies allowed.