3

I've just started learning SDL2 in Linux. I am reading the very first tutorial from LazyFoo and I see have that code:

//The window we'll be rendering to 
SDL_Window* window = NULL;

Where can I find the definition of SDL_Window in order to read about it ?

1 Answers1

20

This structure isn't exposed to user side; SDL_video.h file contains forward declaration of it:

typedef struct SDL_Window SDL_Window;

Forward declaration means you can only use it as pointer type because actual data layout is hidden from you.

Actual type struct SDL_Window is currently declared in src/video/SDL_sysvideo.h (in SDL Source Code:, not in 'Development Libraries:') as:

struct SDL_Window
{
    const void *magic;
    Uint32 id;
    char *title;
    SDL_Surface *icon;
    int x, y;
    int w, h;
    int min_w, min_h;
    int max_w, max_h;
    Uint32 flags;
    Uint32 last_fullscreen_flags;

    /* Stored position and size for windowed mode */
    SDL_Rect windowed;

    SDL_DisplayMode fullscreen_mode;

    float brightness;
    Uint16 *gamma;
    Uint16 *saved_gamma;        /* (just offset into gamma) */

    SDL_Surface *surface;
    SDL_bool surface_valid;

    SDL_bool is_hiding;
    SDL_bool is_destroying;

    SDL_WindowShaper *shaper;

    SDL_HitTest hit_test;
    void *hit_test_data;

    SDL_WindowUserData *data;

    void *driverdata;

    SDL_Window *prev;
    SDL_Window *next;
};

However, if you're not developing/debugging SDL, this information is pretty much useless, and, most importantly, can change in any future release. Also most interesting part - pointer to SDL_WindowUserData - is platform-specific and varies between different OSes and SDL videodrivers.

You should use SDL2 video API instead.

Burak Serdar
  • 46,455
  • 3
  • 40
  • 59
keltar
  • 17,711
  • 2
  • 37
  • 42
  • Mr. keltar, please let me the question: How are parameters x, y, related with screen pixels? Regards. – George Theodosiou Jun 25 '19 at 09:58
  • @GeorgeTheodosiou answering that would require digging into specific window system implementation in use (windows/x11/cocoa/android/...); generic answer is "don't access these fields, use SDL2 video API". I would recommend asking separate question with better description of what you're trying to solve. – keltar Jun 26 '19 at 08:58
  • please accept my many thanks for your answer. It's instructive though. It shows me the limits of knowledge about SDL. Regards. – George Theodosiou Jun 26 '19 at 13:59