GDL Entry Point#

/*!***************************************************************************
\File         OpenGLESHelloAPI_GDL.cpp
\Title        OpenGL ES 2.0 HelloAPI Tutorial
\Author       PowerVR by Imagination, Developer Technology Team
\Copyright    Copyright (c) Imagination Technologies Limited.
\Description  Basic Tutorial that shows step-by-step how to initialise OpenGL ES 2.0, use it for drawing a triangle and terminate it.
              Entry Point: main
*****************************************************************************/

#include <stdio.h>

#include "OpenGLESHelloAPI.h"

#include "libgdl.h"

/*****************************************************************************
 Application Functions
*****************************************************************************/

/*!***************************************************************************
\Function      CreateWindowAndDisplay
\Return        Whether the function succeeded or not.
\Description   Creates a native window and display for the application to render into. GDL's state is stored globally and does not
               interact with egl, so there is no need to pass handles in or out.
*****************************************************************************/
bool CreateWindowAndDisplay(SurfaceData surfaceData)
{

Initialise GDL.

gdl_init(0);

Setup rectangles to use.

gdl_ret_t returnValue = GDL_SUCCESS;

Create a GDL plane.

gdl_plane_id_t gdlPlane = GDL_PLANE_ID_UPP_C;
returnValue = gdl_plane_config_begin(gdlPlane);
if (returnValue != GDL_SUCCESS)
{
    printf("Failed to begin config of GDL plane. (Error code 0x%x)\n", returnValue);
    return false;
}

Set the colour space for the plane’s source to linear RGB.

gdl_color_space_t colorSpace = GDL_COLOR_SPACE_RGB;
returnValue = gdl_plane_set_attr(GDL_PLANE_SRC_COLOR_SPACE, &colorSpace);
if (returnValue != GDL_SUCCESS)
{
    printf("Failed to set color space of GDL plane. (Error code 0x%x)\n", returnValue);
    return false;
}

Set the pixel format of the plane.

gdl_pixel_format_t pixelFormat = GDL_PF_ARGB_32;
returnValue = gdl_plane_set_attr(GDL_PLANE_PIXEL_FORMAT, &pixelFormat);
if (returnValue != GDL_SUCCESS)
{
    printf("Failed to set pixel format of GDL plane. (Error code 0x%x)\n", returnValue);
    return false;
}

Set the plane’s source and destination sizes. Setting them the same ensures no scaling occurs to the render.

gdl_rectangle_t sourceRectangle, destinationRectangle;
sourceRectangle.origin.x = destinationRectangle.origin.x = 0;
sourceRectangle.origin.y = destinationRectangle.origin.y = 0;
sourceRectangle.width = destinationRectangle.width = surfaceData.width;
sourceRectangle.height = destinationRectangle.height = surfaceData.height;

Set the plane’s destination rectangle.

returnValue = gdl_plane_set_attr(GDL_PLANE_DST_RECT, &destinationRectangle);
if (returnValue != GDL_SUCCESS)
{
    printf("Failed to set destination rectangle of GDL plane. (Error code 0x%x)\n", returnValue);
    return false;
}

Set the plane’s source rectangle.

returnValue = gdl_plane_set_attr(GDL_PLANE_SRC_RECT, &sourceRectangle);
if (returnValue != GDL_SUCCESS)
{
    printf("Failed to set source rectangle of GDL plane. (Error code 0x%x)\n", returnValue);
    return false;
}

Commit the changes to the plane to lock it down and initialise it.

   returnValue = gdl_plane_config_end(GDL_FALSE);
   if (returnValue != GDL_SUCCESS)
   {
       gdl_plane_config_end(GDL_TRUE);
       printf("Failed to end config of GDL plane. (Error code 0x%x)\n", returnValue);
       return false;
   }

   return true;
}

/*!***************************************************************************
\Function      ReleaseWindowAndDisplay
\Description   Releases all resources allocated by the windowing system
*****************************************************************************/
void ReleaseWindowAndDisplay()
{

Release all gdl resources.

   gdl_close();
}

/*!***************************************************************************
\Function      main
 @Input            argc                        Number of arguments passed to the application, ignored.
 @Input            argv                        Command line strings passed to the application, ignored.
\Return        Result code to send to the Operating System
\Description   Main function of the program, executes other functions.
*****************************************************************************/
int main(int /*argc*/, char** /*argv*/)
{
   OpenGLESAPI helloAPI;

Setup the windowing system, getting a window and a display.

CreateWindowAndDisplay(helloAPI._surfaceData);

helloAPI._surfaceData.deviceContext = (EGLNativeDisplayType)EGL_DEFAULT_DISPLAY;
helloAPI._surfaceData.window = (EGLNativeWindowType)0;

helloAPI.initializeEGL();
helloAPI.initializeGLES();

Renders a triangle for 800 frames using the state setup in the previous function.

for (int i = 0; i < 800; ++i)
{
    if (!helloAPI.drawFrame() || !helloAPI.swapEGLBuffers())
    {
        break;
    }
}

Release the EGL State and OpenGL ES objects.

helloAPI.releaseGLState();
helloAPI.releaseEGLState();

Release the windowing system resources.

ReleaseWindowAndDisplay();

Destroy the eglWindow.

   return 0;
}