\r
@Title OpenGL ES 2.0 HelloAPI Tutorial\r
\r
- @Version \r
+ @Version\r
\r
@Copyright Copyright (c) Imagination Technologies Limited.\r
\r
@Return bool true if no EGL error was detected\r
@Description Tests for an EGL error and prints it\r
******************************************************************************/\r
-bool TestEGLError(HWND hWnd, char* pszLocation)\r
+bool TestEGLError(HWND hWnd, const char* pszLocation)\r
{\r
/*\r
eglGetError returns the last error that has happened using egl,\r
}\r
\r
/*!****************************************************************************\r
+ @Function Cleanup\r
+ @Input eglDisplay Handle to the EGL display\r
+ @Input hWnd Handle to the window\r
+ @Input hDC Handle to the device context\r
+ @Return int result code to OS\r
+ @Description Clean up before program termination on error or normal exit\r
+******************************************************************************/\r
+int Cleanup(EGLDisplay eglDisplay, HWND hWnd, HDC hDC)\r
+{\r
+ /*\r
+ eglTerminate takes care of destroying any context or surface created\r
+ with this display, so we don't need to call eglDestroySurface or\r
+ eglDestroyContext here.\r
+ */\r
+\r
+ eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);\r
+ eglTerminate(eglDisplay);\r
+\r
+ /*\r
+ Destroy the eglWindow.\r
+ This is platform specific and delegated to a separate function.\r
+ */\r
+\r
+ // Release the device context\r
+ if (hDC) ReleaseDC(hWnd, hDC);\r
+\r
+ return 0;\r
+}\r
+\r
+/*!****************************************************************************\r
@Function WinMain\r
@Input hInstance Application instance from OS\r
@Input hPrevInstance Always NULL\r
};\r
\r
// Fragment and vertex shaders code\r
- char* pszFragShader = "\\r
+ const char* pszFragShader = "\\r
void main (void)\\r
{\\r
gl_FragColor = vec4(1.0, 1.0, 0.66 ,1.0);\\r
}";\r
- char* pszVertShader = "\\r
+ const char* pszVertShader = "\\r
attribute highp vec4 myVertex;\\r
uniform mediump mat4 myPMVMatrix;\\r
void main(void)\\r
if (!hDC)\r
{\r
MessageBox(0, _T("Failed to create the device context"), _T("Error"), MB_OK|MB_ICONEXCLAMATION);\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
/*\r
if (!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion))\r
{\r
MessageBox(0, _T("eglInitialize() failed."), _T("Error"), MB_OK|MB_ICONEXCLAMATION);\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
/*\r
eglBindAPI(EGL_OPENGL_ES_API);\r
if (!TestEGLError(hWnd, "eglBindAPI"))\r
{\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
/*\r
if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1))\r
{\r
MessageBox(0, _T("eglChooseConfig() failed."), _T("Error"), MB_OK|MB_ICONEXCLAMATION);\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
/*\r
\r
if (!TestEGLError(hWnd, "eglCreateWindowSurface"))\r
{\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
/*\r
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, ai32ContextAttribs);\r
if (!TestEGLError(hWnd, "eglCreateContext"))\r
{\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
/*\r
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);\r
if (!TestEGLError(hWnd, "eglMakeCurrent"))\r
{\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
/*\r
MessageBox(hWnd, i32InfoLogLength ? pszInfoLog : _T(""), _T("Failed to compile fragment shader"), MB_OK|MB_ICONEXCLAMATION);\r
delete[] pszInfoLog;\r
\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
// Loads the vertex shader in the same way\r
\r
delete[] pszInfoLog;\r
\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
// Create the shader program\r
MessageBox(hWnd, i32InfoLogLength ? pszInfoLog : _T(""), _T("Failed to link program"), MB_OK|MB_ICONEXCLAMATION);\r
\r
delete[] pszInfoLog;\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
// Actually use the created program\r
\r
// We're going to draw a triangle to the screen so create a vertex buffer object for our triangle\r
GLuint ui32Vbo; // Vertex buffer object handle\r
- \r
+\r
// Interleaved vertex data\r
GLfloat afVertices[] = { -0.4f,-0.4f,0.0f, // Position\r
0.4f ,-0.4f,0.0f,\r
eglSwapBuffers(eglDisplay, eglSurface);\r
if (!TestEGLError(hWnd, "eglSwapBuffers"))\r
{\r
- goto cleanup;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
// Managing the window messages\r
\r
/*\r
Step 10 - Terminate OpenGL ES and destroy the window (if present).\r
- eglTerminate takes care of destroying any context or surface created\r
- with this display, so we don't need to call eglDestroySurface or\r
- eglDestroyContext here.\r
- */\r
-cleanup:\r
- eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);\r
- eglTerminate(eglDisplay);\r
-\r
- /*\r
- Step 11 - Destroy the eglWindow.\r
- Again, this is platform specific and delegated to a separate function.\r
*/\r
-\r
- // Release the device context\r
- if (hDC) ReleaseDC(hWnd, hDC);\r
-\r
- // Destroy the eglWindow\r
- return 0;\r
+ return Cleanup(eglDisplay, hWnd, hDC);\r
}\r
\r
/******************************************************************************\r