Why does "SDL_SetVideoMode" return an adress?

Hello,

I would want to know why the function SDL_SetVideoMode() does return an
adress.

Indeed, if I don’t store it into a pointer, and, so, if i use it like a
void function, it works perfectly !

So, SDL_SetVideoMode should be a void function, no ?

It returns a SDL_Surface*, which means you can directly manipulate the
pixels I’d you desire. In SDL 1.x, some functions that took a surface
pointer as a parameter could be passed a NULL, which implied the created
video surface.On 29 Jun 2014 10:54, “Dorian VEGARA” <dorian.vegara at gmail.com> wrote:

Hello,

I would want to know why the function SDL_SetVideoMode() does return an
adress.

Indeed, if I don’t store it into a pointer, and, so, if i use it like a
void function, it works perfectly !

So, SDL_SetVideoMode should be a void function, no ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ok, thanks :slight_smile:

2014-06-29 17:00 GMT+02:00 Alex Barry <alex.barry at gmail.com>:> It returns a SDL_Surface*, which means you can directly manipulate the

pixels I’d you desire. In SDL 1.x, some functions that took a surface
pointer as a parameter could be passed a NULL, which implied the created
video surface.
On 29 Jun 2014 10:54, “Dorian VEGARA” <@Dorian_VEGARA> wrote:

Hello,

I would want to know why the function SDL_SetVideoMode() does return an
adress.

Indeed, if I don’t store it into a pointer, and, so, if i use it like a
void function, it works perfectly !

So, SDL_SetVideoMode should be a void function, no ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hey, I wanted to print a simple rectangle in my surface. I read the
documentation, and I could write a little program that does it. But it does
not work. So i used Google, and read tutorials, but it did not help me…

So can you look at my code, and tell me what is wrong pls ?

#include <SDL/SDL.h>

SDL_Surface* affichage;

int main (void) {

// Init of the window (not important for you)
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
affichage = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
SDL_WM_SetCaption("Test", NULL);

// The rectangle
SDL_Rect rectangle;
rectangle.x = 50;
rectangle.y = 50;
rectangle.w = 100;
rectangle.h = 100;

// The color
SDL_PixelFormat* format = (*affichage).format;
Uint32 color = SDL_MapRGB(format, 50, 50, 50);

// I print the rectangle
SDL_FillRect(affichage, &rectangle, color);


// User event that closes the program (not important for you :p)
SDL_Event event;
do
    SDL_WaitEvent(&event);
while (event.type != SDL_QUIT);

return 0;
}

2014-06-29 17:37 GMT+02:00 Dorian VEGARA <@Dorian_VEGARA>:> Ok, thanks :slight_smile:

2014-06-29 17:00 GMT+02:00 Alex Barry <alex.barry at gmail.com>:

It returns a SDL_Surface*, which means you can directly manipulate the

pixels I’d you desire. In SDL 1.x, some functions that took a surface
pointer as a parameter could be passed a NULL, which implied the created
video surface.
On 29 Jun 2014 10:54, “Dorian VEGARA” <@Dorian_VEGARA> wrote:

Hello,

I would want to know why the function SDL_SetVideoMode() does return an
adress.

Indeed, if I don’t store it into a pointer, and, so, if i use it like a
void function, it works perfectly !

So, SDL_SetVideoMode should be a void function, no ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

How is your program behave ?

SDL_FillRect(affichage, &rectangle, color);
SDL_Flip( affichage);

You didnt update the screen

Dorian VEGARA wrote:> Hey, I wanted to print a simple rectangle in my surface. I read the documentation, and I could write a little program that does it. But it does not work. So i used Google, and read tutorials, but it did not help me…

So can you look at my code, and tell me what is wrong pls ?

#include <SDL/SDL.h>

SDL_Surface* affichage;

int main (void) {

??? // Init of the window (not important for you)
??? SDL_Init(SDL_INIT_VIDEO);
??? atexit(SDL_Quit);
??? affichage = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
??? SDL_WM_SetCaption(“Test”, NULL);

??? // The rectangle
??? SDL_Rect rectangle;
??? rectangle.x = 50;
??? rectangle.y = 50;
??? rectangle.w = 100;
??? rectangle.h = 100;

??? // The color
??? SDL_PixelFormat* format = (*affichage).format;
??? Uint32 color = SDL_MapRGB(format, 50, 50, 50);

??? // I print the rectangle
??? SDL_FillRect(affichage, &rectangle, color);

??? // User event that closes the program (not important for you :p)
??? SDL_Event event;
??? do
??? SDL_WaitEvent(&event);
??? while (event.type != SDL_QUIT);
?? return 0;
}

2014-06-29 17:37 GMT+02:00 Dorian VEGARA <dorian.vegara at gmail.com (dorian.vegara at gmail.com)>:

Ok, thanks :slight_smile:

2014-06-29 17:00 GMT+02:00 Alex Barry <alex.barry at gmail.com (alex.barry at gmail.com)>:

It returns a SDL_Surface*, which means you can directly manipulate the pixels I’d you desire.?? In SDL 1.x, some functions that took a surface pointer as a parameter could be passed a NULL, which implied the created video surface. On 29 Jun 2014 10:54, “Dorian VEGARA” <dorian.vegara at gmail.com (dorian.vegara at gmail.com)> wrote:

Hello,

I would want to know why the function SDL_SetVideoMode() does return an adress.

Indeed, if I don’t store it into a pointer, and, so, if i use it like a void function, it works perfectly !

So, SDL_SetVideoMode should be a void function, no ?


SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)


SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

It shows a black window.

2014-06-29 17:52 GMT+02:00 mr_tawan <mr_tawan at hotmail.com>:> How is your program behave ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

@AlexRou : ah ok, now it works, tx !

I read in the doc that it’s better to use the SDL_UpdateRect (because Flip
does not work on all the hardware). What do you think about it ?

2014-06-29 17:54 GMT+02:00 Dorian VEGARA <@Dorian_VEGARA>:> It shows a black window.

2014-06-29 17:52 GMT+02:00 mr_tawan <mr_tawan at hotmail.com>:

How is your program behave ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well first find a hardware for your target platform and OS that flip doesnt work, sides its just a one line change if you have to change it.

Dorian VEGARA wrote:> @AlexRou : ah ok, now it works, tx !

I read in the doc that it’s better to use the SDL_UpdateRect (because Flip does not work on all the hardware). What do you think about it ?

2014-06-29 17:54 GMT+02:00 Dorian VEGARA <dorian.vegara at gmail.com (dorian.vegara at gmail.com)>:

It shows a black window.

2014-06-29 17:52 GMT+02:00 mr_tawan <mr_tawan at hotmail.com (mr_tawan at hotmail.com)>:

  How is your program behave ?

SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

I read in the doc that it’s better to use the SDL_UpdateRect (because
Flip does not work on all the hardware). What do you think about it ?

Flip works on all hardware: if there isn’t hardware-supported flipping,
it will just SDL_UpdateRect() the whole window for you.

–ryan.