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

105
x11_egl.c
View File

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