• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Cross-Platform OpenGL Windowing Library


Commit MetaInfo

Revisione4dad582e2f58b9ae1e55247257c97c25a9f12bb (tree)
Zeit2022-04-01 11:37:25
AutorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Report errors from Glow_CreateWindow and Glow_CreateContext.

This only implements this change for X11 and Win32, the Haiku and SDL2 backends
will need to be updated.

Ändern Zusammenfassung

Diff

--- a/glow.h
+++ b/glow.h
@@ -164,10 +164,11 @@ GLOW_EXPORT GLOW_CONST unsigned Glow_WindowStructSize(void);
164164 * @brief Creates a Window
165165 *
166166 * The window is hidden by default.
167+ * @returns 0 on success, -1 on failure.
167168 *
168169 * @sa Glow_ShowWindow
169170 */
170-GLOW_EXPORT void Glow_CreateWindow(struct Glow_Window *out,
171+GLOW_EXPORT int Glow_CreateWindow(struct Glow_Window *out,
171172 unsigned w, unsigned h, const char *title, int flags);
172173
173174 /**
--- a/glow_win32.c
+++ b/glow_win32.c
@@ -332,9 +332,18 @@ void *Glow_GetProcAddress(const char *name){
332332
333333 /******************************************************************************/
334334
335-void Glow_CreateWindow(struct Glow_Window *out,
335+int Glow_CreateWindow(struct Glow_Window *out,
336336 unsigned w, unsigned h, const char *title, int flags){
337337
338+ RECT size;
339+ /* Set the style based on the flags. */
340+ const DWORD style =
341+ (((flags & GLOW_UNDECORATED) == 0) ?
342+ GLOW_WINDOW_STYLE : WS_OVERLAPPED) |
343+ (((flags & GLOW_RESIZABLE) == 0) ?
344+ 0 : (WS_THICKFRAME | WS_MAXIMIZEBOX));
345+ DWORD adj_w, adj_h;
346+
338347 if(glow_app == NULL){
339348 const HINSTANCE app = glow_app = GetModuleHandle(NULL);
340349 const HICON icon = LoadIcon(app, MAKEINTRESOURCE(101));
@@ -355,33 +364,33 @@ void Glow_CreateWindow(struct Glow_Window *out,
355364 RegisterClass(&wc);
356365 }
357366
358- {
359- RECT size;
360- /* Set the style based on the flags. */
361- const DWORD style =
362- (((flags & GLOW_UNDECORATED) == 0) ?
363- GLOW_WINDOW_STYLE : WS_OVERLAPPED) |
364- (((flags & GLOW_RESIZABLE) == 0) ?
365- 0 : (WS_THICKFRAME | WS_MAXIMIZEBOX));
366-
367- size.left = 0;
368- size.top = 0;
369- size.right = w;
370- size.bottom = h;
371- /* Note that AdjustWindowRect will center the client area around the
372- * left/top of the input, so we will need to use the differences for
373- * the actual window dimensions. */
374- AdjustWindowRect(&size, style, TRUE);
375- out->win = CreateWindow(GLOW_CLASS_NAME,
376- title,
377- style,
378- 64, 64, size.right - size.left, size.bottom - size.top,
379- NULL, NULL,
380- glow_app,
381- out);
382- out->adaptive_vsync = (flags & GLOW_ADAPTIVE_VSYNC) != 0;
383- out->vsync = (flags & GLOW_VSYNC) != 0;
367+ size.left = 0;
368+ size.top = 0;
369+ size.right = w;
370+ size.bottom = h;
371+ /* Note that AdjustWindowRect will center the client area around the
372+ * left/top of the input, so we will need to use the differences for
373+ * the actual window dimensions. */
374+ if(AdjustWindowRect(&size, style, TRUE)){
375+ adj_w = size.right - size.left;
376+ adj_h = size.bottom - size.top;
384377 }
378+ else{
379+ adj_w = w;
380+ adj_w = h;
381+ }
382+ out->win = CreateWindow(GLOW_CLASS_NAME,
383+ title,
384+ style,
385+ 64, 64, w, h,
386+ NULL, NULL,
387+ glow_app,
388+ out);
389+ if(out->win == NULL)
390+ return -1;
391+ out->adaptive_vsync = (flags & GLOW_ADAPTIVE_VSYNC) != 0;
392+ out->vsync = (flags & GLOW_VSYNC) != 0;
393+ return 0;
385394 }
386395
387396 /******************************************************************************/
--- a/glow_x11.c
+++ b/glow_x11.c
@@ -118,7 +118,7 @@ void *Glow_GetProcAddress(const char *name){
118118
119119 /******************************************************************************/
120120
121-void Glow_CreateWindow(struct Glow_Window *window,
121+int Glow_CreateWindow(struct Glow_Window *window,
122122 unsigned w, unsigned h, const char *title, int flags){
123123
124124 window->w = w;
@@ -132,8 +132,8 @@ void Glow_CreateWindow(struct Glow_Window *window,
132132 window->ctx = NULL;
133133
134134 if(window->dpy == NULL){
135- fputs("Could not open an X11 display\n", stderr);
136- return;
135+ /* fputs("Could not open an X11 display\n", stderr); */
136+ return -1;
137137 }
138138
139139 window->scr = DefaultScreenOfDisplay(window->dpy);
@@ -145,10 +145,10 @@ void Glow_CreateWindow(struct Glow_Window *window,
145145 GLXFBConfig *const config = glXChooseFBConfig(window->dpy,
146146 window->scr_id, glow_attribs, &num);
147147 if(config == NULL || num == 0){
148- fputs("Could not get glX framebuffer configuration\n", stderr);
148+ /* fputs("Could not get glX framebuffer configuration\n", stderr); */
149149 XCloseDisplay(window->dpy);
150150 window->dpy = NULL;
151- return;
151+ return -1;
152152 }
153153 for(i = 0; i < num; i++){
154154 XVisualInfo *const info =
@@ -179,16 +179,16 @@ void Glow_CreateWindow(struct Glow_Window *window,
179179 /* Get a glX visual info for the fbconfig */
180180 window->vis = glXGetVisualFromFBConfig(window->dpy, window->fbconfig);
181181 if(window->vis == NULL){
182- fputs("Could not create a glX visual\n", stderr);
182+ /* fputs("Could not create a glX visual\n", stderr); */
183183 XCloseDisplay(window->dpy);
184184 window->dpy = NULL;
185- return;
185+ return -1;
186186 }
187187 if(window->scr_id != window->vis->screen){
188- fputs("Screen does not match a given visual\n", stderr);
188+ /* fputs("Screen does not match a given visual\n", stderr); */
189189 XCloseDisplay(window->dpy);
190190 window->dpy = NULL;
191- return;
191+ return -1;
192192 }
193193
194194 /* Open the window. */
@@ -212,6 +212,7 @@ void Glow_CreateWindow(struct Glow_Window *window,
212212 XSelectInput(window->dpy, window->wnd, GLOW_X_EVENT_MASK);
213213
214214 XSync(window->dpy, False);
215+ return 0;
215216 }
216217
217218 /******************************************************************************/