Render a frame on demand












1















I'm currently creating a NTSC signal decoder/simulator, and basically, I'd like to be able to prepare a frame before rendering it, such as, read an array, process data, draw some pixels accordingly, and then render the frame. I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop:



for(;;) { 
glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Whatever I might have to do goes somewhere in here
glFlush();
}


This, however, doesn't work, glClearColor and glClear, probably also glFlush get executed, but just one time, after that, the program just hangs, what can I do to avoid this?










share|improve this question


















  • 2





    There's usually some sort of SwapBuffers function you have to call after rendering a frame. It's platform specific though, not part of GL itself.

    – immibis
    Oct 24 '18 at 3:10






  • 2





    What function is it hanging on? You've got an infinite loop and you've removed the main event loop, so it's probably not getting update events.

    – user1118321
    Oct 24 '18 at 4:23











  • I can not tell if you are using Legacy OpenGL such as OpenGL 1 which in todays time is considered deprecated or if you are using modern OpenGL at least version 3.3+ up to current 4.6. Regardless of which version you are using; this webpage from this online tutorial for OpenGL gives a very good description of Frame Buffers in OpenGL! learnopengl.com/Advanced-OpenGL/Framebuffers

    – Francis Cugler
    Oct 24 '18 at 5:29


















1















I'm currently creating a NTSC signal decoder/simulator, and basically, I'd like to be able to prepare a frame before rendering it, such as, read an array, process data, draw some pixels accordingly, and then render the frame. I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop:



for(;;) { 
glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Whatever I might have to do goes somewhere in here
glFlush();
}


This, however, doesn't work, glClearColor and glClear, probably also glFlush get executed, but just one time, after that, the program just hangs, what can I do to avoid this?










share|improve this question


















  • 2





    There's usually some sort of SwapBuffers function you have to call after rendering a frame. It's platform specific though, not part of GL itself.

    – immibis
    Oct 24 '18 at 3:10






  • 2





    What function is it hanging on? You've got an infinite loop and you've removed the main event loop, so it's probably not getting update events.

    – user1118321
    Oct 24 '18 at 4:23











  • I can not tell if you are using Legacy OpenGL such as OpenGL 1 which in todays time is considered deprecated or if you are using modern OpenGL at least version 3.3+ up to current 4.6. Regardless of which version you are using; this webpage from this online tutorial for OpenGL gives a very good description of Frame Buffers in OpenGL! learnopengl.com/Advanced-OpenGL/Framebuffers

    – Francis Cugler
    Oct 24 '18 at 5:29
















1












1








1








I'm currently creating a NTSC signal decoder/simulator, and basically, I'd like to be able to prepare a frame before rendering it, such as, read an array, process data, draw some pixels accordingly, and then render the frame. I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop:



for(;;) { 
glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Whatever I might have to do goes somewhere in here
glFlush();
}


This, however, doesn't work, glClearColor and glClear, probably also glFlush get executed, but just one time, after that, the program just hangs, what can I do to avoid this?










share|improve this question














I'm currently creating a NTSC signal decoder/simulator, and basically, I'd like to be able to prepare a frame before rendering it, such as, read an array, process data, draw some pixels accordingly, and then render the frame. I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop:



for(;;) { 
glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Whatever I might have to do goes somewhere in here
glFlush();
}


This, however, doesn't work, glClearColor and glClear, probably also glFlush get executed, but just one time, after that, the program just hangs, what can I do to avoid this?







c++ opengl glut






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 24 '18 at 1:55









AurealAureal

345




345








  • 2





    There's usually some sort of SwapBuffers function you have to call after rendering a frame. It's platform specific though, not part of GL itself.

    – immibis
    Oct 24 '18 at 3:10






  • 2





    What function is it hanging on? You've got an infinite loop and you've removed the main event loop, so it's probably not getting update events.

    – user1118321
    Oct 24 '18 at 4:23











  • I can not tell if you are using Legacy OpenGL such as OpenGL 1 which in todays time is considered deprecated or if you are using modern OpenGL at least version 3.3+ up to current 4.6. Regardless of which version you are using; this webpage from this online tutorial for OpenGL gives a very good description of Frame Buffers in OpenGL! learnopengl.com/Advanced-OpenGL/Framebuffers

    – Francis Cugler
    Oct 24 '18 at 5:29
















  • 2





    There's usually some sort of SwapBuffers function you have to call after rendering a frame. It's platform specific though, not part of GL itself.

    – immibis
    Oct 24 '18 at 3:10






  • 2





    What function is it hanging on? You've got an infinite loop and you've removed the main event loop, so it's probably not getting update events.

    – user1118321
    Oct 24 '18 at 4:23











  • I can not tell if you are using Legacy OpenGL such as OpenGL 1 which in todays time is considered deprecated or if you are using modern OpenGL at least version 3.3+ up to current 4.6. Regardless of which version you are using; this webpage from this online tutorial for OpenGL gives a very good description of Frame Buffers in OpenGL! learnopengl.com/Advanced-OpenGL/Framebuffers

    – Francis Cugler
    Oct 24 '18 at 5:29










2




2





There's usually some sort of SwapBuffers function you have to call after rendering a frame. It's platform specific though, not part of GL itself.

– immibis
Oct 24 '18 at 3:10





There's usually some sort of SwapBuffers function you have to call after rendering a frame. It's platform specific though, not part of GL itself.

– immibis
Oct 24 '18 at 3:10




2




2





What function is it hanging on? You've got an infinite loop and you've removed the main event loop, so it's probably not getting update events.

– user1118321
Oct 24 '18 at 4:23





What function is it hanging on? You've got an infinite loop and you've removed the main event loop, so it's probably not getting update events.

– user1118321
Oct 24 '18 at 4:23













I can not tell if you are using Legacy OpenGL such as OpenGL 1 which in todays time is considered deprecated or if you are using modern OpenGL at least version 3.3+ up to current 4.6. Regardless of which version you are using; this webpage from this online tutorial for OpenGL gives a very good description of Frame Buffers in OpenGL! learnopengl.com/Advanced-OpenGL/Framebuffers

– Francis Cugler
Oct 24 '18 at 5:29







I can not tell if you are using Legacy OpenGL such as OpenGL 1 which in todays time is considered deprecated or if you are using modern OpenGL at least version 3.3+ up to current 4.6. Regardless of which version you are using; this webpage from this online tutorial for OpenGL gives a very good description of Frame Buffers in OpenGL! learnopengl.com/Advanced-OpenGL/Framebuffers

– Francis Cugler
Oct 24 '18 at 5:29














1 Answer
1






active

oldest

votes


















1















I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop

... after that, the program just hangs ...




This is a bad idea, because in general the only way to get a event handling when using GLUT is glutMainLoop().



See glutMainLoop:




glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.




Note, glutMainLoop() doesn't only call the call back function which you have set by glutDisplayFunc, it also receives and processes the IO events like mouse and keyboard events. If you don't use the glutMainLoop(), then you have no event handling and of course no IO event handling. This causes that the program seems to hang and doesn't react on any input.

Either you have to use glutMainLoop() or you have to switch a other window API like GLFW, where you can explicitly activate the event processing by glfwPollEvents()



Newer implementations of GLUT, like freeglut provide some additional functionality. glutMainLoopEvent() does the same as glutMainLoop(), but it does it only once. It does a single iteration of the event loop and gives control back immediately. So you can implement your own loop handles your application.



e.g.



void display( void )
{
glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Whatever I might have to do goes somewhere in here
glFlush();
}

int main()
{
.....

glutDisplayFunc(display);

.....

for(;;)
{
glutMainLoopEvent(); // handle the main loop once
glutPostRedisplay(); // cause `display` to be called in `glutMainLoopEvent`
}

.....
}


It is even possible to set a dummy display function, which does nothing, and do the drawing in the loop:



e.g.



void dummyDisplay( void )
{
// does nothing
}

int main()
{
.....

glutDisplayFunc(dummyDisplay);

.....

for(;;)
{
glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Whatever I might have to do goes somewhere in here
glFlush();

glutMainLoopEvent(); // does the event handling once
}

.....
}





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52960066%2frender-a-frame-on-demand%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1















    I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop

    ... after that, the program just hangs ...




    This is a bad idea, because in general the only way to get a event handling when using GLUT is glutMainLoop().



    See glutMainLoop:




    glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.




    Note, glutMainLoop() doesn't only call the call back function which you have set by glutDisplayFunc, it also receives and processes the IO events like mouse and keyboard events. If you don't use the glutMainLoop(), then you have no event handling and of course no IO event handling. This causes that the program seems to hang and doesn't react on any input.

    Either you have to use glutMainLoop() or you have to switch a other window API like GLFW, where you can explicitly activate the event processing by glfwPollEvents()



    Newer implementations of GLUT, like freeglut provide some additional functionality. glutMainLoopEvent() does the same as glutMainLoop(), but it does it only once. It does a single iteration of the event loop and gives control back immediately. So you can implement your own loop handles your application.



    e.g.



    void display( void )
    {
    glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    // Whatever I might have to do goes somewhere in here
    glFlush();
    }

    int main()
    {
    .....

    glutDisplayFunc(display);

    .....

    for(;;)
    {
    glutMainLoopEvent(); // handle the main loop once
    glutPostRedisplay(); // cause `display` to be called in `glutMainLoopEvent`
    }

    .....
    }


    It is even possible to set a dummy display function, which does nothing, and do the drawing in the loop:



    e.g.



    void dummyDisplay( void )
    {
    // does nothing
    }

    int main()
    {
    .....

    glutDisplayFunc(dummyDisplay);

    .....

    for(;;)
    {
    glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    // Whatever I might have to do goes somewhere in here
    glFlush();

    glutMainLoopEvent(); // does the event handling once
    }

    .....
    }





    share|improve this answer






























      1















      I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop

      ... after that, the program just hangs ...




      This is a bad idea, because in general the only way to get a event handling when using GLUT is glutMainLoop().



      See glutMainLoop:




      glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.




      Note, glutMainLoop() doesn't only call the call back function which you have set by glutDisplayFunc, it also receives and processes the IO events like mouse and keyboard events. If you don't use the glutMainLoop(), then you have no event handling and of course no IO event handling. This causes that the program seems to hang and doesn't react on any input.

      Either you have to use glutMainLoop() or you have to switch a other window API like GLFW, where you can explicitly activate the event processing by glfwPollEvents()



      Newer implementations of GLUT, like freeglut provide some additional functionality. glutMainLoopEvent() does the same as glutMainLoop(), but it does it only once. It does a single iteration of the event loop and gives control back immediately. So you can implement your own loop handles your application.



      e.g.



      void display( void )
      {
      glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
      glClear(GL_COLOR_BUFFER_BIT);
      // Whatever I might have to do goes somewhere in here
      glFlush();
      }

      int main()
      {
      .....

      glutDisplayFunc(display);

      .....

      for(;;)
      {
      glutMainLoopEvent(); // handle the main loop once
      glutPostRedisplay(); // cause `display` to be called in `glutMainLoopEvent`
      }

      .....
      }


      It is even possible to set a dummy display function, which does nothing, and do the drawing in the loop:



      e.g.



      void dummyDisplay( void )
      {
      // does nothing
      }

      int main()
      {
      .....

      glutDisplayFunc(dummyDisplay);

      .....

      for(;;)
      {
      glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
      glClear(GL_COLOR_BUFFER_BIT);
      // Whatever I might have to do goes somewhere in here
      glFlush();

      glutMainLoopEvent(); // does the event handling once
      }

      .....
      }





      share|improve this answer




























        1












        1








        1








        I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop

        ... after that, the program just hangs ...




        This is a bad idea, because in general the only way to get a event handling when using GLUT is glutMainLoop().



        See glutMainLoop:




        glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.




        Note, glutMainLoop() doesn't only call the call back function which you have set by glutDisplayFunc, it also receives and processes the IO events like mouse and keyboard events. If you don't use the glutMainLoop(), then you have no event handling and of course no IO event handling. This causes that the program seems to hang and doesn't react on any input.

        Either you have to use glutMainLoop() or you have to switch a other window API like GLFW, where you can explicitly activate the event processing by glfwPollEvents()



        Newer implementations of GLUT, like freeglut provide some additional functionality. glutMainLoopEvent() does the same as glutMainLoop(), but it does it only once. It does a single iteration of the event loop and gives control back immediately. So you can implement your own loop handles your application.



        e.g.



        void display( void )
        {
        glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        // Whatever I might have to do goes somewhere in here
        glFlush();
        }

        int main()
        {
        .....

        glutDisplayFunc(display);

        .....

        for(;;)
        {
        glutMainLoopEvent(); // handle the main loop once
        glutPostRedisplay(); // cause `display` to be called in `glutMainLoopEvent`
        }

        .....
        }


        It is even possible to set a dummy display function, which does nothing, and do the drawing in the loop:



        e.g.



        void dummyDisplay( void )
        {
        // does nothing
        }

        int main()
        {
        .....

        glutDisplayFunc(dummyDisplay);

        .....

        for(;;)
        {
        glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        // Whatever I might have to do goes somewhere in here
        glFlush();

        glutMainLoopEvent(); // does the event handling once
        }

        .....
        }





        share|improve this answer
















        I've tried getting rid of the glutMainLoop(); thing, and just using a handmade loop

        ... after that, the program just hangs ...




        This is a bad idea, because in general the only way to get a event handling when using GLUT is glutMainLoop().



        See glutMainLoop:




        glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.




        Note, glutMainLoop() doesn't only call the call back function which you have set by glutDisplayFunc, it also receives and processes the IO events like mouse and keyboard events. If you don't use the glutMainLoop(), then you have no event handling and of course no IO event handling. This causes that the program seems to hang and doesn't react on any input.

        Either you have to use glutMainLoop() or you have to switch a other window API like GLFW, where you can explicitly activate the event processing by glfwPollEvents()



        Newer implementations of GLUT, like freeglut provide some additional functionality. glutMainLoopEvent() does the same as glutMainLoop(), but it does it only once. It does a single iteration of the event loop and gives control back immediately. So you can implement your own loop handles your application.



        e.g.



        void display( void )
        {
        glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        // Whatever I might have to do goes somewhere in here
        glFlush();
        }

        int main()
        {
        .....

        glutDisplayFunc(display);

        .....

        for(;;)
        {
        glutMainLoopEvent(); // handle the main loop once
        glutPostRedisplay(); // cause `display` to be called in `glutMainLoopEvent`
        }

        .....
        }


        It is even possible to set a dummy display function, which does nothing, and do the drawing in the loop:



        e.g.



        void dummyDisplay( void )
        {
        // does nothing
        }

        int main()
        {
        .....

        glutDisplayFunc(dummyDisplay);

        .....

        for(;;)
        {
        glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        // Whatever I might have to do goes somewhere in here
        glFlush();

        glutMainLoopEvent(); // does the event handling once
        }

        .....
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered Oct 24 '18 at 18:52









        Rabbid76Rabbid76

        34.9k113146




        34.9k113146






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52960066%2frender-a-frame-on-demand%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks