void AndroidEGL::InitSurface(bool bUseSmallSurface) { ANativeWindow* window = (ANativeWindow*)FPlatformMisc::GetHardwareWindow(); while(window == NULL) { FPlatformMisc::LowLevelOutputDebugString(TEXT("Waiting for Native window in AndroidEGL::InitSurface")); FPlatformProcess::Sleep(0.001f); window = (ANativeWindow*)FPlatformMisc::GetHardwareWindow(); } PImplData->Window = (ANativeWindow*)window; int32 Width = 8, Height = 8; if (!bUseSmallSurface) { FPlatformRect WindowSize = FAndroidWindow::GetScreenRect(); Width = WindowSize.Right; Height = WindowSize.Bottom; } ANativeWindow_setBuffersGeometry(PImplData->Window, Width, Height, PImplData->NativeVisualID); CreateEGLSurface(PImplData->Window ); PImplData->SharedContext.eglSurface = PImplData->auxSurface; PImplData->RenderingContext.eglSurface = PImplData->eglSurface; PImplData->SingleThreadedContext.eglSurface = PImplData->eglSurface; }
/*!***************************************************************************************************************************************** @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*/) { // X11 variables Display* nativeDisplay = NULL; Window nativeWindow = 0; // EGL variables EGLDisplay eglDisplay = NULL; EGLConfig eglConfig = NULL; EGLSurface eglSurface = NULL; EGLContext eglContext = NULL; // A vertex buffer object to store our model data. GLuint vertexBuffer = 0; // Get access to a native display if (!CreateNativeDisplay(&nativeDisplay)) { goto cleanup; } // Setup the windowing system, create a window if (!CreateNativeWindow(nativeDisplay, &nativeWindow)) { goto cleanup; } // Create and Initialise an EGLDisplay from the native display if (!CreateEGLDisplay(nativeDisplay, eglDisplay)) { goto cleanup; } // Choose an EGLConfig for the application, used when setting up the rendering surface and EGLContext if (!ChooseEGLConfig(eglDisplay, eglConfig)) { goto cleanup; } // Create an EGLSurface for rendering from the native window if (!CreateEGLSurface(nativeWindow, eglDisplay, eglConfig, eglSurface)) { goto cleanup; } // Setup the EGL Context from the other EGL constructs created so far, so that the application is ready to submit OpenGL ES commands if (!SetupEGLContext(eglDisplay, eglConfig, eglSurface, eglContext)) { goto cleanup; } // Initialise the vertex data in the application if (!InitialiseBuffer(vertexBuffer)) { goto cleanup; } // Renders a triangle for 800 frames using the state setup in the previous function for (int i = 0; i < 800; ++i) { if (!RenderScene(eglDisplay, eglSurface, nativeDisplay)) { break; } } // Release any resources we created in the Initialise functions DeInitialiseBuffer(vertexBuffer); cleanup: // Release the EGL State ReleaseEGLState(eglDisplay); // Release the windowing system resources ReleaseNativeResources(nativeDisplay, nativeWindow); // Destroy the eglWindow return 0; }
/*!***************************************************************************************************************************************** @Function WinMain @Input applicationInstance Application instance created by the Operating System @Input previousInstance Always NULL @Input commandLineString Command line string passed from the Operating System, ignored. @Input showCommand Specifies how the window is to be shown, ignored. @Return Result code to send to the Operating System @Description Main function of the program, executes other functions. *******************************************************************************************************************************************/ int WINAPI WinMain(HINSTANCE applicationInstance, HINSTANCE previousInstance, TCHAR* /*commandLineString*/, int /*showCommand*/) { // Windows variables HWND nativeWindow = NULL; HDC deviceContext = NULL; // EGL variables EGLDisplay eglDisplay = NULL; EGLConfig eglConfig = NULL; EGLSurface eglSurface = NULL; EGLContext eglContext = NULL; // A vertex buffer object to store our model data. GLuint vertexBuffer = 0; // Setup the windowing system, getting a window and a display if (!CreateWindowAndDisplay(applicationInstance, nativeWindow, deviceContext)) { goto cleanup; } // Create and Initialise an EGLDisplay from the native display if (!CreateEGLDisplay(deviceContext, eglDisplay)) { goto cleanup; } // Choose an EGLConfig for the application, used when setting up the rendering surface and EGLContext if (!ChooseEGLConfig(eglDisplay, eglConfig)) { goto cleanup; } // Create an EGLSurface for rendering from the native window if (!CreateEGLSurface(nativeWindow, eglDisplay, eglConfig, eglSurface)) { goto cleanup; } // Setup the EGL Context from the other EGL constructs created so far, so that the application is ready to submit OpenGL ES commands if (!SetupEGLContext(eglDisplay, eglConfig, eglSurface, eglContext, nativeWindow)) { goto cleanup; } // Initialise the vertex data in the application if (!InitialiseBuffer(vertexBuffer, nativeWindow)) { goto cleanup; } // Renders a triangle for 800 frames using the state setup in the previous function for (int i = 0; i < 800; ++i) { if (!RenderScene(eglDisplay, eglSurface, nativeWindow)) { break; } } // Release any resources we created in the Initialise functions DeInitialiseBuffer(vertexBuffer); cleanup: // Release the EGL State ReleaseEGLState(eglDisplay); // Release the windowing system resources ReleaseWindowAndDisplay(nativeWindow, deviceContext); // Destroy the eglWindow return 0; }