Rename Android and EGL files
[freeglut] / src / android / fg_window_android.c
1 /*
2  * freeglut_window_android.c
3  *
4  * Window management methods for Android
5  *
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
10  *
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:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
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.
27  */
28
29 #define FREEGLUT_BUILDING_LIB
30 #include <GL/freeglut.h>
31 #include "fg_internal.h"
32 extern EGLSurface fghEGLPlatformOpenWindow( EGLNativeWindowType handle );
33
34 /*
35  * Opens a window. Requires a SFG_Window object created and attached
36  * to the freeglut structure. OpenGL context is created here.
37  */
38 void fgPlatformOpenWindow( SFG_Window* window, const char* title,
39                            GLboolean positionUse, int x, int y,
40                            GLboolean sizeUse, int w, int h,
41                            GLboolean gameMode, GLboolean isSubWindow )
42 {
43   printf("fgPlatformOpenWindow %p ID=%d\n", (void*)window, window->ID);
44
45   /* TODO: only one full-screen window possible? */
46   static int nb_windows = 0;
47   if (nb_windows == 0) {
48     nb_windows++;
49     fgDisplay.pDisplay.single_window = window;
50     printf("=> %p ID=%d\n", (void*)fgDisplay.pDisplay.single_window, fgDisplay.pDisplay.single_window->ID);
51   } else {
52     return;
53   }
54
55   /* Wait until window is available and OpenGL context is created */
56   /* Normally events are processed through glutMainLoop(), but the
57      user didn't call it yet, and the Android may not have initialized
58      the View yet.  So we need to wait for that to happen. */
59   /* We can't return from this function before the OpenGL context is
60      properly made current with a valid surface. So we wait for the
61      surface. */
62   while (fgDisplay.pDisplay.single_window->Window.Handle == NULL) {
63     /* APP_CMD_INIT_WINDOW will do the job */
64     fgPlatformProcessSingleEvent();
65   }
66
67   EGLDisplay display = fgDisplay.pDisplay.eglDisplay;
68   EGLint format = fgDisplay.pDisplay.eglContextFormat;
69   ANativeWindow_setBuffersGeometry(window->Window.Handle, 0, 0, format);
70   window->Window.pContext.eglSurface = fghEGLPlatformOpenWindow(window->Window.Handle);
71
72   window->State.Visible = GL_TRUE;
73 }
74
75 void fgPlatformSetWindow ( SFG_Window *window )
76 {
77   /* TODO: only a single window possible? */
78 }
79
80 /*
81  * This function makes the current window visible
82  */
83 void fgPlatformGlutShowWindow( void )
84 {
85   fprintf(stderr, "fgPlatformGlutShowWindow: STUB\n");
86 }
87
88 /*
89  * This function hides the current window
90  */
91 void fgPlatformGlutHideWindow( void )
92 {
93   fprintf(stderr, "fgPlatformGlutHideWindow: STUB\n");
94 }
95
96 /*
97  * Iconify the current window (top-level windows only)
98  */
99 void fgPlatformGlutIconifyWindow( void )
100 {
101   fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n");
102 }
103
104 /*
105  * Set the current window's title
106  */
107 void fgPlatformGlutSetWindowTitle( const char* title )
108 {
109   fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n");
110 }
111
112 /*
113  * Set the current window's iconified title
114  */
115 void fgPlatformGlutSetIconTitle( const char* title )
116 {
117   fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n");}
118
119 /*
120  * Change the current window's position
121  */
122 void fgPlatformGlutPositionWindow( int x, int y )
123 {
124   fprintf(stderr, "fgPlatformGlutPositionWindow: STUB\n");
125 }
126
127 /*
128  * Lowers the current window (by Z order change)
129  */
130 void fgPlatformGlutPushWindow( void )
131 {
132   fprintf(stderr, "fgPlatformGlutPushWindow: STUB\n");
133 }
134
135 /*
136  * Raises the current window (by Z order change)
137  */
138 void fgPlatformGlutPopWindow( void )
139 {
140   fprintf(stderr, "fgPlatformGlutPopWindow: STUB\n");
141 }
142
143 /*
144  * Resize the current window so that it fits the whole screen
145  */
146 void fgPlatformGlutFullScreen( SFG_Window *win )
147 {
148   fprintf(stderr, "fgPlatformGlutFullScreen: STUB\n");
149 }
150
151 /*
152  * If we are fullscreen, resize the current window back to its original size
153  */
154 void fgPlatformGlutLeaveFullScreen( SFG_Window *win )
155 {
156   fprintf(stderr, "fgPlatformGlutLeaveFullScreen: STUB\n");
157 }
158
159 /*
160  * Toggle the window's full screen state.
161  */
162 void fgPlatformGlutFullScreenToggle( SFG_Window *win )
163 {
164   fprintf(stderr, "fgPlatformGlutFullScreenToggle: STUB\n");
165 }