Create a window

Use screen_create_window_type() to create an application window.

To create a window:
  1. Create a variable for the context and window instances and create a variable to store the name of the window group.
    screen_context_t   screen_context = 0;
    screen_window_t    screen_window = 0;
    char               window_group_name[64];
                        
  2. Create a context. The context describes the relationship between the application and the underlying windowing system.
    screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT);
                       
  3. Create a window. The screen_create_window() function takes the window variable and the context variable that you created in the first step.
    screen_create_window(&screen_window, screen_context);
                        
  4. Retrieve the window ID, as a string, so that child windows can use it to join this window's group. The SCREEN_PROPERTY_ID property is guaranteed to be unique within the system.

    This is the name of the window group that's used by any child window wishing to join this group. You must add any child window to a window group in order to make the child window visible.

    screen_get_window_property_cv(screen_window,\
                                  SCREEN_PROPERTY_ID,\
                                  sizeof(window_group_name),\
                                  window_group_name );
                        
  5. Set the window properties. In the following step, the pixel format and usage values are set for the window. In this example, the window will be used to display a video.
    int format = SCREEN_FORMAT_RGBA8888;
    screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format);
    
    int usage = SCREEN_USAGE_NATIVE;
    screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage);
                        
  6. Create a window buffer. In this example, the buffer is used to store video data for the window. The screen_create_window_buffers() function takes the window and an integer that defines the number of buffers to create for this window.
    screen_create_window_buffers(screen_window, 1);
                        

Although any instances created are destroyed when the application exits, it is best practice to destroy any window, pixmap, and context instances that you created but no longer require.

The following code snippet is included at the end of the application above:

screen_destroy_window(screen_window);
screen_destroy_context(screen_context);