Skip to content

Commit

Permalink
SDL3/SDL_GetDisplayForWindow: Add a code example
Browse files Browse the repository at this point in the history
  • Loading branch information
mariobadr authored and SDLWikiBot committed Nov 5, 2024
1 parent 68eb4d3 commit d110d4c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions SDL3/SDL_GetDisplayForWindow.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ containing the center of the window on success or 0 on failure; call
This function is available since SDL 3.1.3.
## Code Examples
```c
// Example program
// Use SDL3 to log which display a window was created on
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_video.h>
int
main(int argc, char** argv)
{
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
return 0;
}
SDL_Window* window = SDL_CreateWindow("My Window", 640, 480, 0);
if(window == NULL) {
SDL_Log("Unable to create window: %s", SDL_GetError());
return 0;
}
SDL_DisplayID display_id = SDL_GetDisplayForWindow(window);
SDL_Log("Window created on display '%s'", SDL_GetDisplayName(display_id));
SDL_DestroyWindow(window);
return 0;
}
```

## See Also

- [SDL_GetDisplayBounds](SDL_GetDisplayBounds)
Expand Down

0 comments on commit d110d4c

Please sign in to comment.