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

  • SEARCH
  • Home
  • 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 9240293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:09:50+00:00 2026-06-18T08:09:50+00:00

I’m using Fltk to render openGL graphs. currently I’m debugging a global array which

  • 0

I’m using Fltk to render openGL graphs. currently I’m debugging a global array which is sorted by a heapsort function. My purpose is to see after each swap of elements in the heapsort function a graphical swap of elements. but I don’t want to catch an event from FLTK event_handle for every time i need to redraw after I swapped and waiting at breakpoint. (the heapsort function and the opengl render part are running in 2 different threads (if that doesn’t has to go without saying)).
So the first try I had was to use:

Fl::add_timeout(1.0, MyRedrawCallback, (void *)&myWindow);

Fl::run();

void MyRedrawCallback(void *myWindow)

{

    MyWindow *pMyWindow;

    pMyWindow = (MyWindow *) myWindow;
    pMyWindow->redraw();
    Fl::repeat_timeout(1.0, MyRedrawCallback, (void *)&pMyWindow);
}

But every Time the callback is called the 2nd time i get an “Access violation reading”

I’m suggesting that FL::run starts a different thread so maybe the first time is still in same thread so the address of redraw is still usable but after that I’m in a different thread and the function at address is not that what I’m expecting?!

But I already took a different way because I wasn’t sure i cant even use the timeout on this way.
So i was looking for a way to get an event that’s eq to “set amount of time passed” or “nothing is happening for…” but there isn’t such a handle I’m right?

Finally is there a way to let FLTK execute commands even outside the eventloop? or is there another way to solve my problem?

  • 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-18T08:09:51+00:00Added an answer on June 18, 2026 at 8:09 am

    Please take a look at the following example, taken from here: http://seriss.com/people/erco/fltk/#OpenGlInterp

    #include <FL/Fl.H>
    #include <FL/Fl_Gl_Window.H>
    #include <FL/gl.h>
    #include <math.h>
    
    //
    // Demonstrate interpolating shapes
    // erco 06/10/05
    //
    
    class Playback : public Fl_Gl_Window {
        int frame;
        // Linear interpolation between two values based on 'frac' (0.0=a, 1.0=b)
        float Linterp(float frac, float a, float b) {
            return( a + ( frac * (b - a) ));
        }
        // Sinusoidal easein/easeout interpolation between two values based on 'frac' (0.0=a, 1.0=b)
        float SinInterp(float frac, float a, float b) {
            float pi = 3.14159;
            frac = (sin(pi/2 + frac*pi ) + 1.0 ) / 2.0;     // 0 ~ 1 -> 0 ~ 1
            return(Linterp(frac,a,b));
        }
        // DRAW SIMPLE SHAPE INTERPOLATION
        //     Interpolation is based on the current frame number
        //
        void DrawShape(int frame) {
            // Calculate a fraction that represents the frame# being shown
            float frac = ( frame % 48 ) / 48.0 * 2;
            if ( frac > 1.0 ) frac = 2.0-frac;      // saw tooth wave:  "/\/\/\"
    
            static float a_xy[9][2] = {
                { -.5, -1. }, { 0.0, -.5 }, { -.5, -1. }, { 0.0, -.5 },
                { 0.0, 0.0 },
                { 0.0, -.5 }, { +.5, -1. }, { 0.0, -.5 }, { +.5, -1. },
            };
            static float b_xy[9][2] = {
                { -.25, -1. }, { -.50, -.75 }, { -.75, -1.0 }, { -.50, -.75 },
                { 0.0, 0.0 },
                { +.50, -.75 }, { +.75, -1.0 }, { +.50, -.75 }, { +.25, -1.0 }
            };
            // Linterp a and b to form new shape c
            float c_xy[9][2];
            for ( int i=0; i<9; i++ )
                for ( int xy=0; xy<2; xy++ )
                    c_xy[i][xy] = SinInterp(frac, a_xy[i][xy], b_xy[i][xy]);
            // Draw shape
            glColor3f(1.0, 1.0, 1.0);
            glBegin(GL_LINE_STRIP);
            for ( int i=0; i<9; i++ )
                glVertex2f(c_xy[i][0], c_xy[i][1]);
            glEnd();
        }
        // DRAW THE WIDGET
        //    Each time we're called, assume
        //
        void draw() {
            if (!valid()) {
                valid(1);
                glLoadIdentity();
                glViewport(0,0,w(),h());
            }
            glClear(GL_COLOR_BUFFER_BIT);
            // Draw shape 4x, rotated at 90 degree positions
            glPushMatrix();
                DrawShape(frame); glRotatef(90.0, 0, 0, 1);
                DrawShape(frame); glRotatef(90.0, 0, 0, 1);
                DrawShape(frame); glRotatef(90.0, 0, 0, 1);
                DrawShape(frame);
            glPopMatrix();
            // Advance frame counter
            ++frame;
        }
        // 24 FPS TIMER CALLBACK
        //     Called 24x per second to redraw the widget
        //
        static void Timer_CB(void *userdata) {
            Playback *pb = (Playback*)userdata;
            pb->redraw();
            Fl::repeat_timeout(1.0/24.0, Timer_CB, userdata);
        }
    public:
        // Constructor
        Playback(int X,int Y,int W,int H,const char*L=0) : Fl_Gl_Window(X,Y,W,H,L) {
            frame = 0;
            Fl::add_timeout(1.0/24.0, Timer_CB, (void*)this);       // 24fps timer
            end();
        }
    };
    
    int main() {
         Fl_Window win(500, 500);
         Playback  playback(10, 10, win.w()-20, win.h()-20);
         win.resizable(&playback);
         win.show();
         return(Fl::run());
    }
    

    This example more/less does exactly what you want. Greg Ercolano has more FLTK examples on his web-site. I recommend taking a look at http://seriss.com/people/erco/fltk/ .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which has BIG numbers and small numbers in it. I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am confused How to use looping for Json response Array in another Array.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.