Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8574157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:24:40+00:00 2026-06-11T19:24:40+00:00

Following up on the answer to How to use GLUT with libdispatch? , I’m

  • 0

Following up on the answer to How to use GLUT with libdispatch?, I’m now using GLFW instead —

The following code sets up a window, sets up a timer to poll for events, and, over time, enqueues render updates:

#include <dispatch/dispatch.h>
#include <GL/glfw.h>

float t=0;

int main(void)
{
    dispatch_async(dispatch_get_main_queue(), ^{
        glfwInit();
        glfwDisable(GLFW_AUTO_POLL_EVENTS);
        glfwOpenWindow(320,200,8,8,8,8,8,0,GLFW_WINDOW);
    });

    // Periodically process window events --- this isn't working.
    dispatch_source_t windowEventTimer;
    windowEventTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
    uint64_t nanoseconds = 100 * NSEC_PER_MSEC;
    dispatch_source_set_timer(windowEventTimer, dispatch_time(DISPATCH_TIME_NOW, nanoseconds), nanoseconds, 0);
    dispatch_source_set_event_handler(windowEventTimer, ^{
        glfwPollEvents();
    });
    dispatch_resume(windowEventTimer);

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        for(int i=0;i<200;++i)
        {
            // Enqueue a rendering update.
            dispatch_async(dispatch_get_main_queue(), ^{
                glClearColor (0.2f, 0.2f, 0.4f, 1.0f);
                glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glColor3f (1.0, 0.7, 0.7); 
                glBegin( GL_LINES );
                    glVertex3f(0,0,0);
                    glVertex3f(t+=0.02,.1,0);
                glEnd();

                glfwSwapBuffers();
            });
            // Wait a bit, to simulate complex calculations.
            sleep(1);
        }
    });

    dispatch_main();
}

The animation updates as expected, but the window frame does not draw, and the window does not respond to events.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:24:42+00:00Added an answer on June 11, 2026 at 7:24 pm

    Digging through the GLFW source, I think I found the problem: the runloop of the Cocoa window created by GLFW needs to execute from Thread 0, but GLFW does not ensure that _glfwPlatformPollEvents() happens on Thread 0. (Identical symptoms were reported on this question about executing a Cocoa GUI on a thread other than 0.)

    A workaround is to use the same private interface CoreFoundation uses to process the main libdispatch queue from inside a CFRunLoop.

    If I replace the dispatch_main() call in the above code with this:

    while(1)
    {
        _dispatch_main_queue_callback_4CF(NULL);
        usleep(10000);
    }
    

    …it works as expected — the window frame draws, and the window processes events.


    Trying to improve this hacky situation, I:

    • filed a feature request to make this a public libdispatch API
    • requested that the GLFW documentation be updated to mention which thread is needed for Mac events.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: question now contains the final edited answer! I now use the following (final
I have the following code: using System; using NUnit.Framework; using Rhino.Mocks; public class A
I'm trying to use the HBase Java client to answer the following question as
I use the following code to validate an XML file against an XSD file.
The following question and answer addresses the use of an out parameter in a
I found the following answer to that question: A service opens before you even
FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
I tried following the answer here how to override a task making it depend
I have been following the answer of this question: How to update existing object
I tried following the answer to this question , but could not get xsd.exe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.