c - OpenGL: Save framebuffer to image, file -
i wrote lines of code draw spinning rectangle:
#include "glut.h" static glfloat spin = 0.0; /* current angle */ void init(void) { glclearcolor (0.0, 0.0, 0.0, 0.0); glshademodel (gl_flat); } void display(void) { glclear(gl_color_buffer_bit); glpushmatrix(); glrotatef(spin, 0.0, 0.0, 1.0); /* rotate oxyz (oz) */ glcolor3f(1.0, 1.0, 1.0); /* bgr-color: white; */ glrectf(-25.0, -25.0, 25.0, 25.0); /* rectangle */ glpopmatrix(); glutswapbuffers(); /* swap 2 buffer */ } void spindisplay(void) { spin = spin + 2.0; /* add 2 degrees every loop action */ if (spin > 360.0) spin = spin - 360.0; glutpostredisplay(); /* alert: redraw */ } /* change window mode */ void reshape(int w, int h) { glviewport (0, 0, (glsizei) w, (glsizei) h); /* change viewport */ glmatrixmode(gl_projection); glloadidentity(); glortho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); glmatrixmode(gl_modelview); glloadidentity(); } /* mouse interaction */ void mouse(int button, int state, int x, int y) { switch (button) { case glut_left_button: /* left mouse */ if (state == glut_down) glutidlefunc(spindisplay); /* idle mode switch spindisplay */ break; //case glut_middle_button: /* middle mouse button */ //if (state == glut_down) //glutidlefunc(null); //break; default: break; } } /* main */ int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode (glut_double | glut_rgb); /* double buffer */ glutinitwindowsize (500, 500); glutinitwindowposition (100, 100); glutcreatewindow ("spinning rectangle"); init (); glutdisplayfunc(display); glutreshapefunc(reshape); /* reshape func (redraw) when window size changed */ glutmousefunc(mouse); /* mouse func */ glutmainloop(); return 0; }
and wanna save framebuffer image (jpeg, bmp, tiff) or file. tell me how? need use lib jpeglib, libtiff?
Comments
Post a Comment