SDL Wiki
(This is the documentation for SDL3, which is the current stable version. SDL2 was the previous version!)

SDL_CreateWindowWithProperties

Create a window with the specified properties.

Header File

Defined in <SDL3/SDL_video.h>

Syntax

SDL_Window * SDL_CreateWindowWithProperties(SDL_PropertiesID props);

Function Parameters

SDL_PropertiesID props the properties to use.

Return Value

(SDL_Window *) Returns the window that was created or NULL on failure; call SDL_GetError() for more information.

Remarks

These are the supported properties:

These are additional supported properties on macOS:

These are additional supported properties on Wayland:

These are additional supported properties on Windows:

These are additional supported properties with X11:

The window is implicitly shown if the "hidden" property is not set.

Windows with the "tooltip" and "menu" properties are popup windows and have the behaviors and guidelines outlined in SDL_CreatePopupWindow().

If this window is being created to be used with an SDL_Renderer, you should not add a graphics API specific property (SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, etc), as SDL will handle that internally when it chooses a renderer. However, SDL might need to recreate your window at that point, which may cause the window to appear briefly, and then flicker as it is recreated. The correct approach to this is to create the window with the SDL_PROP_WINDOW_CREATE_HIDDEN_BOOLEAN property set to true, then create the renderer, then show the window with SDL_ShowWindow().

Version

This function is available since SDL 3.1.3.

Code Examples

// Example program
// Use SDL3 to create a window with properties

#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_PropertiesID props = SDL_CreateProperties();
  if(props == 0) {
    SDL_Log("Unable to create properties: %s", SDL_GetError());
    return 0;
  }

  // Assume the following calls succeed
  SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, "My Window");
  SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN, true);
  SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, 640);
  SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, 480);

  SDL_Window *window = SDL_CreateWindowWithProperties(props);
  if(window == NULL) {
    SDL_Log("Unable to create window: %s", SDL_GetError());
    return 0;
  }

  // A game loop goes here

  SDL_DestroyWindow(window);
  SDL_DestroyProperties(props);

  return 0;
}

See Also


CategoryAPI, CategoryAPIFunction, CategoryVideo


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.