Cross-Platform OpenGL Windowing Library
リビジョン | e4dad582e2f58b9ae1e55247257c97c25a9f12bb (tree) |
---|---|
日時 | 2022-04-01 11:37:25 |
作者 | AlaskanEmily <emily@alas...> |
コミッター | AlaskanEmily |
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.
@@ -164,10 +164,11 @@ GLOW_EXPORT GLOW_CONST unsigned Glow_WindowStructSize(void); | ||
164 | 164 | * @brief Creates a Window |
165 | 165 | * |
166 | 166 | * The window is hidden by default. |
167 | + * @returns 0 on success, -1 on failure. | |
167 | 168 | * |
168 | 169 | * @sa Glow_ShowWindow |
169 | 170 | */ |
170 | -GLOW_EXPORT void Glow_CreateWindow(struct Glow_Window *out, | |
171 | +GLOW_EXPORT int Glow_CreateWindow(struct Glow_Window *out, | |
171 | 172 | unsigned w, unsigned h, const char *title, int flags); |
172 | 173 | |
173 | 174 | /** |
@@ -332,9 +332,18 @@ void *Glow_GetProcAddress(const char *name){ | ||
332 | 332 | |
333 | 333 | /******************************************************************************/ |
334 | 334 | |
335 | -void Glow_CreateWindow(struct Glow_Window *out, | |
335 | +int Glow_CreateWindow(struct Glow_Window *out, | |
336 | 336 | unsigned w, unsigned h, const char *title, int flags){ |
337 | 337 | |
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 | + | |
338 | 347 | if(glow_app == NULL){ |
339 | 348 | const HINSTANCE app = glow_app = GetModuleHandle(NULL); |
340 | 349 | const HICON icon = LoadIcon(app, MAKEINTRESOURCE(101)); |
@@ -355,33 +364,33 @@ void Glow_CreateWindow(struct Glow_Window *out, | ||
355 | 364 | RegisterClass(&wc); |
356 | 365 | } |
357 | 366 | |
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; | |
384 | 377 | } |
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; | |
385 | 394 | } |
386 | 395 | |
387 | 396 | /******************************************************************************/ |
@@ -118,7 +118,7 @@ void *Glow_GetProcAddress(const char *name){ | ||
118 | 118 | |
119 | 119 | /******************************************************************************/ |
120 | 120 | |
121 | -void Glow_CreateWindow(struct Glow_Window *window, | |
121 | +int Glow_CreateWindow(struct Glow_Window *window, | |
122 | 122 | unsigned w, unsigned h, const char *title, int flags){ |
123 | 123 | |
124 | 124 | window->w = w; |
@@ -132,8 +132,8 @@ void Glow_CreateWindow(struct Glow_Window *window, | ||
132 | 132 | window->ctx = NULL; |
133 | 133 | |
134 | 134 | 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; | |
137 | 137 | } |
138 | 138 | |
139 | 139 | window->scr = DefaultScreenOfDisplay(window->dpy); |
@@ -145,10 +145,10 @@ void Glow_CreateWindow(struct Glow_Window *window, | ||
145 | 145 | GLXFBConfig *const config = glXChooseFBConfig(window->dpy, |
146 | 146 | window->scr_id, glow_attribs, &num); |
147 | 147 | 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); */ | |
149 | 149 | XCloseDisplay(window->dpy); |
150 | 150 | window->dpy = NULL; |
151 | - return; | |
151 | + return -1; | |
152 | 152 | } |
153 | 153 | for(i = 0; i < num; i++){ |
154 | 154 | XVisualInfo *const info = |
@@ -179,16 +179,16 @@ void Glow_CreateWindow(struct Glow_Window *window, | ||
179 | 179 | /* Get a glX visual info for the fbconfig */ |
180 | 180 | window->vis = glXGetVisualFromFBConfig(window->dpy, window->fbconfig); |
181 | 181 | if(window->vis == NULL){ |
182 | - fputs("Could not create a glX visual\n", stderr); | |
182 | + /* fputs("Could not create a glX visual\n", stderr); */ | |
183 | 183 | XCloseDisplay(window->dpy); |
184 | 184 | window->dpy = NULL; |
185 | - return; | |
185 | + return -1; | |
186 | 186 | } |
187 | 187 | 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); */ | |
189 | 189 | XCloseDisplay(window->dpy); |
190 | 190 | window->dpy = NULL; |
191 | - return; | |
191 | + return -1; | |
192 | 192 | } |
193 | 193 | |
194 | 194 | /* Open the window. */ |
@@ -212,6 +212,7 @@ void Glow_CreateWindow(struct Glow_Window *window, | ||
212 | 212 | XSelectInput(window->dpy, window->wnd, GLOW_X_EVENT_MASK); |
213 | 213 | |
214 | 214 | XSync(window->dpy, False); |
215 | + return 0; | |
215 | 216 | } |
216 | 217 | |
217 | 218 | /******************************************************************************/ |