SDL

So I did the tutorial and it gave me errors and I don't know why it said too many arguments but there were not ... at all:
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//Header files
#include <stdio.h>
#include <stdlib.h>

#include <SDL/SDL.h>

//Globals
SDL_Surface *back;
SDL_Surface *image;
SDL_Surface *screen;

//also location ints
int xpos=0,ypos=0;

int InitImages()
{
  //2 images InitImages is used to creat a image
  back = SDL_LoadBMP("bg.bmp");
  image = SDL_LoadBMP("image.bmp");
  return 0;
}
//This puts the images onto the screen
int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect,
                        SDL_Surface *dst, SDL_Rect *dstrect);
//This defines th image
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 DrawBG()
{
  DrawIMG(back, 0, 0);
}
//This actualy draws it
void DrawScene()
{
  DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);
  DrawIMG(image, xpos, ypos);

  SDL_Flip(screen);
}
//and finally the main file
int main(int argc, char *argv[])
{
  Uint8* keys;
//error checking
  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);
  }
  //init theimages and draw the background
  InitImages();
  DrawBG();
    int done=0;
//If the program closes or user presses esc then quit SDL
  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; }
      }
    }
//Checks if keys are being held down or oressed
    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; }
//Draw the scene
    DrawScene();
  }
//and finnaly the end of the loop
  return 0;
}

sorry its so long guys
also I used cone3d's tutorial's
Last edited on
Line 26 :
void DrawIMG(SDL_Surface *img, int x, int y) //function defined as taking 3 parameters

Line 41:
DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2); // ERROR - attempting to call the function with 7 parameters
Last edited on
So in a noobish attempt to fix it I separated the values then remembered its a function so no offense but what do I do?
From memory

1
2
3
//This puts the images onto the screen
int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect,
                        SDL_Surface *dst, SDL_Rect *dstrect);


Isn't SDL_BlitSurface one of sdls actual functions so take the int away.
Your right Mythios I removed it and the semicolon and it continued to work however it's made that way for the void right under it also
1
2
3
4
5
6
7
8
//This defines th image
void DrawIMG(SDL_Surface * img, int x, int y)
{
  SDL_Rect dest;
  dest.x = x;
  dest.y = y;
  SDL_BlitSurface(img, NULL, screen, &dest);
}
continues to tell me it has too many parameters
Because when your calling it instead of giving it 3 arguments your giving it 7
DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);
sorry for being a noob but what do I do?I replaced it but it still gives me errors
Topic archived. No new replies allowed.