Create a window

Before you can render an animation or display video, you must create a window for your application. There are a number of different window types. The following procedure describes how to create a window that can be used to display video.

To create a window:
  1. Create a variable for the context and window instances and create a variable to store the name of the windowgroup.
    screen_context_t   screen_context = 0;
    screen_window_t    screen_window = 0;
    static const char  *window_group_name = "mainwindowgroup";
  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. Create a window group. The window_group_name variable stores the name of the main window group. Remember that the name of the window group must be unique. You must add your application window to a window group in order to make the window visible.
    screen_create_window_group(screen_window, 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.