4 * Window management methods for Android
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Copied for Platform code by Evan Felix <karcaw at gmail.com>
9 * Copyright (C) 2012 Sylvain Beucler
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
25 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #define FREEGLUT_BUILDING_LIB
30 #include <GL/freeglut.h>
31 #include "fg_internal.h"
32 #include "egl/fg_window_egl.h"
33 #include "android/fg_main_android.h"
36 * Opens a window. Requires a SFG_Window object created and attached
37 * to the freeglut structure. OpenGL context is created here.
39 void fgPlatformOpenWindow( SFG_Window* window, const char* title,
40 GLboolean positionUse, int x, int y,
41 GLboolean sizeUse, int w, int h,
42 GLboolean gameMode, GLboolean isSubWindow )
44 /* TODO: only one full-screen window possible? */
45 static int nb_windows = 0;
46 if (nb_windows == 0) {
48 fgDisplay.pDisplay.single_window = window;
53 fghChooseConfig(&window->Window.pContext.egl.Config);
54 window->Window.Context = fghCreateNewContextEGL(window);
56 /* Wait until window is available and OpenGL context is created */
57 /* Normally events are processed through glutMainLoop(), but the
58 user didn't call it yet, and the Android may not have initialized
59 the View yet. So we need to wait for that to happen. */
60 /* We can't return from this function before the OpenGL context is
61 properly made current with a valid surface. So we wait for the
63 while (fgDisplay.pDisplay.single_window->Window.Handle == NULL) {
64 /* APP_CMD_INIT_WINDOW will do the job */
65 fgPlatformProcessSingleEvent();
68 EGLDisplay display = fgDisplay.pDisplay.egl.Display;
70 /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
71 * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
72 * As soon as we picked a EGLConfig, we can safely reconfigure the
73 * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
75 eglGetConfigAttrib(display, window->Window.pContext.egl.Config,
76 EGL_NATIVE_VISUAL_ID, &vid);
77 ANativeWindow_setBuffersGeometry(window->Window.Handle, 0, 0, vid);
79 fghPlatformOpenWindowEGL(window);
81 window->State.Visible = GL_TRUE;
85 * Closes a window, destroying the frame and OpenGL context
87 void fgPlatformCloseWindow( SFG_Window* window )
89 fghPlatformCloseWindowEGL(window);
90 /* Window pre-created by Android, no way to delete it */
94 * This function makes the current window visible
96 void fgPlatformGlutShowWindow( void )
98 fprintf(stderr, "fgPlatformGlutShowWindow: STUB\n");
102 * This function hides the current window
104 void fgPlatformGlutHideWindow( void )
106 fprintf(stderr, "fgPlatformGlutHideWindow: STUB\n");
110 * Iconify the current window (top-level windows only)
112 void fgPlatformGlutIconifyWindow( void )
114 fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n");
118 * Set the current window's title
120 void fgPlatformGlutSetWindowTitle( const char* title )
122 fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n");
126 * Set the current window's iconified title
128 void fgPlatformGlutSetIconTitle( const char* title )
130 fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n");}
133 * Change the current window's position
135 void fgPlatformGlutPositionWindow( int x, int y )
137 fprintf(stderr, "fgPlatformGlutPositionWindow: STUB\n");
141 * Lowers the current window (by Z order change)
143 void fgPlatformGlutPushWindow( void )
145 fprintf(stderr, "fgPlatformGlutPushWindow: STUB\n");
149 * Raises the current window (by Z order change)
151 void fgPlatformGlutPopWindow( void )
153 fprintf(stderr, "fgPlatformGlutPopWindow: STUB\n");
157 * Resize the current window so that it fits the whole screen
159 void fgPlatformGlutFullScreen( SFG_Window *win )
161 fprintf(stderr, "fgPlatformGlutFullScreen: STUB\n");
165 * If we are fullscreen, resize the current window back to its original size
167 void fgPlatformGlutLeaveFullScreen( SFG_Window *win )
169 fprintf(stderr, "fgPlatformGlutLeaveFullScreen: STUB\n");
173 * Toggle the window's full screen state.
175 void fgPlatformGlutFullScreenToggle( SFG_Window *win )
177 fprintf(stderr, "fgPlatformGlutFullScreenToggle: STUB\n");