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 intances 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.
    	if (screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT) != 0) {
    		return EXIT_FAILURE;
    	}
  3. Create a window. The screen_create_window() function takes the window variable and the context variable that you created in the first step.
    	if (screen_create_window(&screen_window, screen_context) != 0) {
    		
    		screen_destroy_context(screen_context);
    		return EXIT_FAILURE;
    	}
  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.
    	if (screen_create_window_group(screen_window, window_group_name) != 0) {
    		return EXIT_FAILURE;
    	}
  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;
    	if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) {
    		return EXIT_FAILURE;
    	}
    
    	int usage = SCREEN_USAGE_NATIVE;
    	if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) {
    		return EXIT_FAILURE;
    	}
  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.
    	if (screen_create_window_buffers(screen_window, 1) != 0) {
    		return EXIT_FAILURE;
    	}}

Be sure to always create and destroy any window and context instances that you create. The following code snippet is included at the end of the application above. When the application exits, the window and context instance are destroyed.

	if (screen_destroy_window(screen_window) != 0) {
		return EXIT_FAILURE;
	}

	if (screen_destroy_context(screen_context) != 0) {
		return EXIT_FAILURE;
	}