Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualdatahead8888

Posted 12 June 2013 - 04:11 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++;


#4datahead8888

Posted 12 June 2013 - 03:50 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 I can't use freeglut for this.

 

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++;


#3datahead8888

Posted 12 June 2013 - 03:41 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 I can't use freeglut for this.

 

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, "images\\ImplicitMethods%d.tga", frameNumber);
        tga_result result = tga_write_rgb(imageFileName, screenBuffer, windowWidth, windowHeight, 32);

 

        frameNumber++;


#2datahead8888

Posted 12 June 2013 - 03:40 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 such as VirtualDub.  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 I can't use freeglut for this.

 

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, "images\\ImplicitMethods%d.tga", frameNumber);
        tga_result result = tga_write_rgb(imageFileName, screenBuffer, windowWidth, windowHeight, 32);

 

        frameNumber++;


#1datahead8888

Posted 12 June 2013 - 03:36 PM

I've been working on an OpenGL physics simulation 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 such as VirtualDub.  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 I can't use freeglut for this.

 

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, "images\\ImplicitMethods%d.tga", frameNumber);
        tga_result result = tga_write_rgb(imageFileName, screenBuffer, windowWidth, windowHeight, 32);

 

        frameNumber++;

 

 


PARTNERS