I have two problems, the first is, that I’am a beginner in OpenGL and I have to learn it for my diploma thesis as physicist!
My tasks are to improve a programm, written in C++ and OpenGL, that reads measured data and simulate a watersurface of this data. The program also use the glut-library to create a window.
The problem is, that I have to implement a possibility to write each frame of the animation in an bmp- or tiff-… file, so one can build a avi or something else of this images with a suitable other program!
My question is: is there anybody who can tell me a way to solve this problem or can give me information that can be useful for me, to write each rendered image of my glutwindow into an bitmap-file for example.
//here the wave is drawn in strips along the x axis
for (int i = 0; i < yRes - 1; ++i)
{
glBegin(GL_TRIANGLE_STRIP);
for (int j = 0; j < xRes; ++j)
{
//draw two points at (x,y) = (j,i) and (x,y) = (j+1,i)
//std::cout << height[i*xRes+j] << std::endl;
setColor(i * xRes + j);
//normal vector for the given slope values
//will be normalized automatically
glNormal3f( - slopeX[i * xRes + j],
- slopeY[i * xRes + j],
1.0);
//point at (x,y) = (j,i)
glVertex3f(j, i, height[i * xRes + j]);
setColor((i+1) * xRes + j);
glNormal3f( - slopeX[(i+1) * xRes + j],
- slopeY[(i+1) * xRes + j],
1.0);
//point at (x,y) = (j+1,i)
glVertex3f(j, (i+1), height[(i+1) * xRes + j]); }
glEnd();
}
and after that I call:
glFlush();
glutSwapBuffers();
Now I have to put your code snippet before I call glFlush(); and glutSwapBuffers(); ? If that is correct, can you tell me again what I have to do after that? I don’t understand what you meant with scanline order and what is to do in preallocating?
After the glReadPixels call, the image is stored at the imageData location.
Use whatever image library to write this raw binary data to a file on disk, as said Dark Photon : “like libtiff, libpng, libgif, libjpeg, etc”
… or simply store it directly as .raw format if you have tools able to read it with a manually specified size and format.
Just depends on where in the frame you want to eat the readback time from.
You can read FRONT after drawing before SwapBuffers and eat it from the end of the current frame, or read BACK after SwapBuffers before clear/draw for the next frame and eat it from the beginnning of the next.
When using AA, a pro for the latter is you pay for the downsample only once.