Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Issue with outputting rendered images to files after window is closed


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 datahead8888   Members   -  Reputation: 162

Like
0Likes
Like

Posted 12 June 2013 - 03:36 PM

I've been working on an OpenGL program and wanted to create a "video generation mode" where it outputs to a series of numbered targa files that can later be collated with a video editing tool.  I'm using glut with OpenGL (without shaders) and Visual C++ express on Windows.

 

What I've found is that it works fine when the window is open -- each output targa image is correct.

 

The moment I close the window, I found that the rendering code keeps running -- if I have cout's they keep printing to the console.  If does not render correctly to the targa images at that point - every other frame it is upside down and swaps red and blue.

If I could detect window close events, I could terminate the application on a window close so that it stops outputting targa images, but this version of glut does not have that callback and freeglut is not an option.

 

The relevant code is below...

 

        //The following section is after the openGL rendering code

       

        glReadBuffer(GL_BACK); //Tried with and without this line
        glFlush();  //Tried with and without this line
       

        //This does the buffer read

        glReadPixels(0, 0, windowWidth, windowHeight, GL_RGBA, GL_UNSIGNED_BYTE, screenBuffer);

 

        //Vertically flip the image in memory - it flips two rows from the screen in memory at a time

        //The images will be upside down without this
        for (int i = 0; i < windowHeight / 2; i++)
        {
            if (i != windowHeight - i)
            {
                memcpy(temp,(uint8_t *)&screenBuffer[i * windowWidth * 4], windowWidth * 4 * sizeof(uint8_t));
                memcpy((uint8_t *)&screenBuffer[i * windowWidth * 4], (uint8_t *)&screenBuffer[(windowHeight - i) * windowWidth * 4], windowWidth * 4 * sizeof(uint8_t));
                memcpy((uint8_t *)&screenBuffer[(windowHeight - i) * windowWidth * 4], temp, windowWidth * 4 * sizeof(uint8_t));
           

            }
        }

 

        //I used the C targa library at -- http://dmr.ath.cx/gfx/targa/

        sprintf(imageFileName, "videoFile%d.tga", frameNumber);
        tga_result result = tga_write_rgb(imageFileName, screenBuffer, windowWidth, windowHeight, 32);

 

        frameNumber++;


Edited by datahead8888, 12 June 2013 - 04:11 PM.


Sponsor:

#2 dpadam450   Members   -  Reputation: 949

Like
0Likes
Like

Posted 17 June 2013 - 03:41 PM

Depending on what you are really doing, why not use screen capture like camtasia?
Saving files like that is going to eat your harddrive because they will eat up clusters quick.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS