only enter main loop if initialization is successful

main
Allen Webster 2026-02-25 16:44:08 -08:00
parent 60166e6861
commit 8e7ab3b49b
2 changed files with 85 additions and 84 deletions

View File

@ -514,33 +514,35 @@ int main(){
} }
/*~ NOTE: Main loop */ /*~ NOTE: Main loop */
int exit_loop = 0; if (make_current_success2){
for (;!exit_loop;){ int exit_loop = 0;
/* (1) Appendix B: wl_display_dispatch_pending for (;!exit_loop;){
** " This function dispatches events on the main event queue. /* (1) Appendix B: wl_display_dispatch_pending
** ... it doesn't block." ** " This function dispatches events on the main event queue.
*/ ** ... it doesn't block."
wl_display_dispatch_pending(ctx.wl_display); */
wl_display_dispatch_pending(ctx.wl_display);
if (ctx.close_signal){ if (ctx.close_signal){
exit_loop = 1; exit_loop = 1;
} }
/*~ NOTE: render */ /*~ NOTE: render */
{ {
glDrawBuffer(GL_BACK); glDrawBuffer(GL_BACK);
glViewport(0, 0, 640, 480); glViewport(0, 0, 640, 480);
glClearColor(0.40f, 0.90f, 0.15f, 1.f); glClearColor(0.40f, 0.90f, 0.15f, 1.f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
/* (egl) eglSwapBuffers /* (egl) eglSwapBuffers
** " back-buffered window surface, then the color buffer is copied ** " back-buffered window surface, then the color buffer is copied
** (posted) to the native window associated with that surface " ** (posted) to the native window associated with that surface "
*/ */
EGLBoolean swap_success = eglSwapBuffers(ctx.egl_display, ctx.egl_surface); EGLBoolean swap_success = eglSwapBuffers(ctx.egl_display, ctx.egl_surface);
if (!swap_success){ if (!swap_success){
printf("eglSwapBuffers failed\n"); printf("eglSwapBuffers failed\n");
}
} }
} }

105
x11_egl.c
View File

@ -246,65 +246,64 @@ int main(int argc, char **argv){
} }
/*~ NOTE: Main loop */ /*~ NOTE: Main loop */
int exit_loop = 0; if (swap_interval_success){
if (!swap_interval_success){ int exit_loop = 0;
exit_loop = 1; for (;!exit_loop;){
}
for (;!exit_loop;){
/* (1) /event-handling/XPending.html /* (1) /event-handling/XPending.html
** " returns the number of events that have been received from the X ** " returns the number of events that have been received from the X
** server but have not been removed from the event queue " ** server but have not been removed from the event queue "
**~ NOTE: The docs say this returns the number of events, but it's **~ NOTE: The docs say this returns the number of events, but it's
** easier, and possibly more reliable to just use it to check if ** easier, and possibly more reliable to just use it to check if
** there is at lesat one input. ** there is at lesat one input.
*/ */
for (;XPending(display) > 0;){ for (;XPending(display) > 0;){
/* (1) /event-handling/manipulating-event-queue/XNextEvent.html /* (1) /event-handling/manipulating-event-queue/XNextEvent.html
** " copies the first event from the event queue into the specified ** " copies the first event from the event queue into the specified
** XEvent structure and then removes it from the queue " ** XEvent structure and then removes it from the queue "
*/ */
XEvent event; XEvent event;
XNextEvent(display, &event); XNextEvent(display, &event);
/* (1) /events/structures.html /* (1) /events/structures.html
** " The XEvent structure is a union of the individual structures ** " The XEvent structure is a union of the individual structures
** declared for each event type. Depending on the type, you should ** declared for each event type. Depending on the type, you should
** access members of each event by using the XEvent union. " ** access members of each event by using the XEvent union. "
*/ */
switch (event.type){ switch (event.type){
case ClientMessage: { case ClientMessage: {
Atom atom = event.xclient.data.l[0]; Atom atom = event.xclient.data.l[0];
if (atom == atom__WM_DELETE_WINDOW){ if (atom == atom__WM_DELETE_WINDOW){
exit_loop = 1; exit_loop = 1;
} }
}break; }break;
}
} }
}
/* (1) /window-information/XGetWindowAttributes.html /* (1) /window-information/XGetWindowAttributes.html
** " returns the current attributes for the specified window " ** " returns the current attributes for the specified window "
*/ */
XWindowAttributes window_attr = {0}; XWindowAttributes window_attr = {0};
if (!XGetWindowAttributes(display, window, &window_attr)){ if (!XGetWindowAttributes(display, window, &window_attr)){
printf("XGetWindowAttributes failed\n"); printf("XGetWindowAttributes failed\n");
} }
/*~ NOTE: render */ /*~ NOTE: render */
if (window_attr.width > 0 && window_attr.height > 0){ if (window_attr.width > 0 && window_attr.height > 0){
glDrawBuffer(GL_BACK); glDrawBuffer(GL_BACK);
glViewport(0, 0, window_attr.width, window_attr.height); glViewport(0, 0, window_attr.width, window_attr.height);
glClearColor(0.90f, 0.15f, 0.40f, 1.f); glClearColor(0.90f, 0.15f, 0.40f, 1.f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
/* (2) eglSwapBuffers /* (2) eglSwapBuffers
** " back-buffered window surface, then the color buffer is copied ** " back-buffered window surface, then the color buffer is copied
** (posted) to the native window associated with that surface " ** (posted) to the native window associated with that surface "
*/ */
EGLBoolean swap_success = eglSwapBuffers(egl_display, surface); EGLBoolean swap_success = eglSwapBuffers(egl_display, surface);
if (!swap_success){ if (!swap_success){
printf("eglSwapBuffers failed\n"); printf("eglSwapBuffers failed\n");
}
} }
} }