SDl

I know how to program in SDL,but I do not know what exatly does each command.
Can explain me?

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "SDL/SDL.h"

int main(int argc, char* args[])//why I need that?
{
    
    SDL_Init(SDL_INIT_EVERYTHING);//it starts sdl,but what exactly does?

    SDL_Surface *screen;//What is "sdl_suraface"? And why needs to be pointer?
    
    SDL_Quit();//it close that,but there is a better explanation?
    
    return 0;    
}


Thank you a lot!!!
If you are using Code::Blocks, if you select function with right mouse button and press "Find Declaration", you will be sent to header file including this function, and brief explanation in comments from SDL developers.

If you still don't understand what it is, then you may want to go to reference( SDL 1.2 has it somewhere, as far as I'm concerned). There you can find functions and classes explained.

Or you can just find tutorial, which describes them :)

Anyway.

1
2
3
4
int main(int argc, char* argv[] )
{
//code....
}


It's just a main function. Every program needs a main function, and well, this is what full main function looks like( void main() or int main() aren't, well, "complete"; it's used for what is called "command line arguments" - http://www.cplusplus.com/articles/DEN36Up4/ )
You need it this way, because SDL kinda overwrites main function with their main.

SDL_Init starts SDL. It loads modules for SDL, like video, mixer, timer, and so on.

SDL_Surface is representing some sort of surface in your window. It is pointer, because you will be allocating it dynamically. Again, try pressing right mouse button to check it out :)

SDL_Quit does just opposite of SDL_Init - it unloads everything, plus it takes care of destroying surface allocated with SDL_SetVideoMode() in SDL 1.2 .


Anyway, the best way to learn is to do something. Anything. Don't stand there, wondering what every function does. These are created because you simply aren't good enough to create them( yet ;) ) by yourself, so you're using them. Also, no point in reinventing the wheel.
You should just understand what each function does(but not how), and how you should use it.

SDL_Init - you need to use it at the beggining of SDL program to initialize SDL, and inside you set flags for modules you want to use. Simple as that. You don't need any fancy information about how it deals with it. If you knew, you wouldn't be using it, you would be creating it.

Good luck!
What is the problem with .w and .h

par.w=1;
par.h=10;

and

var.w=10;
var.h=100;

Has different values but still the width and the height of both is the same.
WHY?
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
#include <SDL/SDL.h>

SDL_Event event;

int main(int argc, char* argv[])
{
    SDL_Init( SDL_INIT_EVERYTHING );

    SDL_WM_SetCaption("SDL TUTORIALS",NULL);

    SDL_Surface *screen = SDL_SetVideoMode(400,400,32,SDL_SWSURFACE);
    SDL_Surface *image1 = SDL_LoadBMP("image.bmp");

    SDL_Rect var;
    SDL_Rect par;

    par.w=1;
    par.h=10;
    par.x=0;
    par.y=20;

    var.w=10;
    var.h=100;
    var.x=0;
    var.y=200;





    while(event.type != SDL_QUIT)
    {
        SDL_PollEvent(&event);

        SDL_BlitSurface(image1,NULL,screen,&var);
        SDL_BlitSurface(image1,NULL,screen,&par);

        SDL_Flip(screen);
    }

    SDL_Quit();

    return 0;

}
Topic archived. No new replies allowed.