Implemented fg_window_blackberry.c to initialize and cleanup windows Implemented...
[freeglut] / src / blackberry / fg_window_blackberry.c
1 /*
2  * fg_window_blackberry.c
3  *
4  * Window management methods for BlackBerry
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  * Copyright (C) 2013  Vincent Simonetti
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
25  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  */
29
30 #define FREEGLUT_BUILDING_LIB
31 #include <GL/freeglut.h>
32 #include "fg_internal.h"
33 #include "egl/fg_window_egl.h"
34 #include <screen/screen.h>
35 #include <bps/screen.h>
36
37 /*
38  * Opens a window. Requires a SFG_Window object created and attached
39  * to the freeglut structure. OpenGL context is created here.
40  */
41 void fgPlatformOpenWindow( SFG_Window* window, const char* title,
42                            GLboolean positionUse, int x, int y,
43                            GLboolean sizeUse, int w, int h,
44                            GLboolean gameMode, GLboolean isSubWindow )
45 {
46   /* TODO: only one full-screen window possible? */
47   if (fgDisplay.pDisplay.single_native_window != NULL) {
48     fgWarning("You can't have more than one window on BlackBerry");
49     return;
50   }
51
52   /* Create window */
53   if (screen_create_context(&window->Window.pContext.screenContext, 0)) {
54     fgError("Could not create screen context");
55         return;
56   }
57   screen_window_t sWindow;
58   if (screen_create_window(&sWindow, window->Window.pContext.screenContext)) {
59         screen_destroy_context(window->Window.pContext.screenContext);
60         fgError("Could not create window");
61         return;
62   }
63   fgDisplay.pDisplay.single_native_window = sWindow;
64
65   /* Set window properties */
66   int screenFormat = SCREEN_FORMAT_RGBA8888;
67 #ifdef __X86__
68   int screenUsage = SCREEN_USAGE_OPENGL_ES2;
69 #else
70   int screenUsage = SCREEN_USAGE_DISPLAY | SCREEN_USAGE_OPENGL_ES2; // Physical device copy directly into physical display
71 #endif
72   if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) {
73         screen_destroy_window(sWindow);
74         screen_destroy_context(window->Window.pContext.screenContext);
75         fgError("Could not set window format");
76         return;
77   }
78   if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_USAGE, &screenUsage)) {
79         screen_destroy_window(sWindow);
80         screen_destroy_context(window->Window.pContext.screenContext);
81         fgError("Could not set window usage");
82         return;
83   }
84
85   /* Could set size based on what is specified for window. Work on another time
86   int size[2];
87   size[0] = w;
88   size[1] = h;
89   if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) {
90         screen_destroy_window(sWindow);
91         screen_destroy_context(window->Window.pContext.screenContext);
92         fgError("Could not set window buffer size");
93         return;
94   }*/
95
96   /* Create window buffers */
97   if (screen_create_window_buffers(sWindow, 2)) {
98         screen_destroy_window(sWindow);
99         screen_destroy_context(window->Window.pContext.screenContext);
100         fgError("Could not create window buffers");
101         return;
102   }
103
104   /* Request window events */
105   screen_request_events(window->Window.pContext.screenContext);
106
107   /* Save window */
108   window->Window.Handle = fgDisplay.pDisplay.single_native_window;
109   window->State.WorkMask |= GLUT_INIT_WORK;
110
111   /* Create context */
112   fghChooseConfig(&window->Window.pContext.egl.Config);
113   window->Window.Context = fghCreateNewContextEGL(window);
114
115   /* Create EGL window */
116   fghPlatformOpenWindowEGL(window);
117
118   window->State.Visible = GL_TRUE;
119 }
120
121 /*
122  * Request a window resize
123  */
124 void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )
125 {
126   fprintf(stderr, "fgPlatformReshapeWindow: STUB\n");
127 }
128
129 /*
130  * Closes a window, destroying the frame and OpenGL context
131  */
132 void fgPlatformCloseWindow( SFG_Window* window )
133 {
134   fghPlatformCloseWindowEGL(window);
135
136   screen_stop_events(window->Window.pContext.screenContext);
137
138   screen_destroy_window((screen_window_t)window->Window.Handle);
139
140   screen_destroy_context(window->Window.pContext.screenContext);
141 }
142
143 /*
144  * This function makes the specified window visible
145  */
146 void fgPlatformShowWindow( void )
147 {
148   fprintf(stderr, "fgPlatformShowWindow: STUB\n");
149 }
150
151 /*
152  * This function hides the specified window
153  */
154 void fgPlatformHideWindow( SFG_Window *window )
155 {
156   fprintf(stderr, "fgPlatformHideWindow: STUB\n");
157 }
158
159 /*
160  * Iconify the specified window (top-level windows only)
161  */
162 void fgPlatformIconifyWindow( SFG_Window *window )
163 {
164   fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n");
165 }
166
167 /*
168  * Set the current window's title
169  */
170 void fgPlatformGlutSetWindowTitle( const char* title )
171 {
172   fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n");
173 }
174
175 /*
176  * Set the current window's iconified title
177  */
178 void fgPlatformGlutSetIconTitle( const char* title )
179 {
180   fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n");}
181
182 /*
183  * Change the specified window's position
184  */
185 void fgPlatformPositionWindow( SFG_Window *window, int x, int y )
186 {
187   fprintf(stderr, "fgPlatformPositionWindow: STUB\n");
188 }
189
190 /*
191  * Lowers the specified window (by Z order change)
192  */
193 void fgPlatformPushWindow( SFG_Window *window )
194 {
195   fprintf(stderr, "fgPlatformPushWindow: STUB\n");
196 }
197
198 /*
199  * Raises the specified window (by Z order change)
200  */
201 void fgPlatformPopWindow( SFG_Window *window )
202 {
203   fprintf(stderr, "fgPlatformPopWindow: STUB\n");
204 }
205
206 /*
207  * Toggle the window's full screen state.
208  */
209 void fgPlatformFullScreenToggle( SFG_Window *win )
210 {
211   fprintf(stderr, "fgPlatformFullScreenToggle: STUB\n");
212 }