EWS Entry Point#

/*!***************************************************************************
 \File         OpenGLESHelloAPI_EWS.cpp
 \Title        OpenGL ES 2.0 HelloAPI Tutorial
 \Author       PowerVR by Imagination, Developer Technology Team
 \Copyright    Copyright (c) Imagination Technologies Limited.
 \brief  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 <EWS/ews.h>

 /*!***************************************************************************
 \param[out]        nativeWindow                Native window type to create
 \param[out]        nativeDisplay               Native display to create
 \return        Whether the function succeeded or not.
 \brief Creates a native window and display for the application to render into.
 *****************************************************************************/
 bool CreateWindowAndDisplay(EWS_WINDOW& nativeWindow, EWS_DISPLAY& nativeDisplay, SurfaceData surfaceData)
 {

Open the display for use.

nativeDisplay = EWSOpenDisplay(EWS_DEFAULT_DISPLAY, 0);

Set the position of the window to create.

EWS_COORD windowPosition;
windowPosition.iX = 0;
windowPosition.iY = 0;

Set the size of the window to create.

EWS_SIZE windowSize;
windowSize.uiHeight = surfaceData.width;
windowSize.uiWidth = surfaceData.height;

Create the native window.

   nativeWindow = EWSCreateWindow(nativeDisplay, windowPosition, windowSize, EWS_PIXEL_FORMAT_ARGB_8888, EWS_ROTATE_0);

   return true;
}

/*!***************************************************************************
\param[in]         nativeDisplay               The native display to release
\param[in]         nativeWindow                The native window to destroy
\brief Releases all resources allocated by the windowing system
*****************************************************************************/
void ReleaseWindowAndDisplay(EWS_WINDOW nativeWindow, EWS_DISPLAY nativeDisplay)
{

Destroy the window.

if (nativeWindow)
{
    EWSDestroyWindow(nativeWindow);
}

Release the native display.

   if (nativeDisplay)
   {
       EWSCloseDisplay(nativeDisplay);
   }
}

/*!***************************************************************************
\param[in] argc                        Number of arguments passed to the application, ignored.
\param[in] argv                        Command line strings passed to the application, ignored.
\return        Result code to send to the Operating System
\brief Main function of the program, executes other functions.
******************************************************************************/
int main(int /*argc*/, char** /*argv*/)
{

Windows variables.

EWS_WINDOW nativeWindow = 0;
EWS_DISPLAY nativeDisplay = 0;

OpenGLESAPI helloAPI;

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

CreateWindowAndDisplay(nativeWindow, nativeDisplay, helloAPI._surfaceData);

helloAPI._surfaceData.deviceContext = (EGLNativeDisplayType)nativeDisplay;
helloAPI._surfaceData.window = (EGLNativeWindowType)nativeWindow;

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(nativeWindow, nativeDisplay);

Destroy the eglWindow.

   return 0;
}