Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

glt/buffer.cpp

Go to the documentation of this file.
00001 #include "buffer.h"
00002 
00015 #include <cassert>
00016 #include <cstring>
00017 #include <cstdio>
00018 using namespace std;
00019 
00020 GltFrameBuffer::GltFrameBuffer()
00021 : _viewport(true)
00022 {
00023 }
00024 
00025 GltFrameBuffer::GltFrameBuffer(const GltViewport &viewport)
00026 : _viewport(viewport)
00027 {
00028 }
00029 
00030 GltFrameBuffer::~GltFrameBuffer()
00031 {
00032 }
00033 
00034 GLuint GltFrameBuffer::x() const        { return _viewport.x(); }
00035 GLuint GltFrameBuffer::y() const        { return _viewport.y(); }
00036 GLuint GltFrameBuffer::width() const    { return _viewport.width();  }
00037 GLuint GltFrameBuffer::height() const   { return _viewport.height(); }
00038 GLuint GltFrameBuffer::size() const     { return _viewport.pixels(); }
00039 
00041 
00042 GltFrameBufferRGB::GltFrameBufferRGB()
00043 : GltFrameBuffer()
00044 {
00045     _image.resize(size()*3);
00046     read();
00047 }
00048 
00049 /*
00050 GltFrameBufferRGB::GltFrameBufferRGB(GLubyte *pixels)
00051 : GltFrameBuffer() 
00052 {
00053 }
00054 */
00055 
00056 GltFrameBufferRGB::GltFrameBufferRGB(const GltFrameBufferRGB &a,const GltFrameBufferRGB &b,const GLdouble alpha)
00057 {
00058     if (a.width()!=b.width())
00059         return;
00060 
00061     if (a.height()!=b.height())
00062         return;
00063 
00064     _viewport = a._viewport;
00065     _image.resize(size()*3);
00066 
00067     for (GLuint i=0; i<size()*3; i++)
00068         _image[i] = GLubyte((1.0-alpha)*a._image[i] + alpha*b._image[i]);
00069 }
00070 
00071 GltFrameBufferRGB::~GltFrameBufferRGB()
00072 {
00073 }
00074 
00075 void
00076 GltFrameBufferRGB::read()
00077 {
00078     //
00079     // Check that viewport has not changed since
00080     // construction.
00081     //
00082 
00083     GltViewport viewport(true);
00084     if (_viewport!=viewport || !_image.size())
00085     {
00086         _viewport = viewport;
00087         _image.resize(size()*3);
00088     }
00089 
00090     //
00091     // Read the depth buffer
00092     //
00093 
00094     glPixelStorei(GL_PACK_ALIGNMENT,sizeof(GLubyte));
00095     glReadPixels(x(),y(),width(),height(),GL_RGB,GL_UNSIGNED_BYTE,(GLvoid *) _image.data());
00096 }
00097 
00098 void 
00099 GltFrameBufferRGB::write() const
00100 {
00101     glPixelStorei(GL_UNPACK_ALIGNMENT,sizeof(GLubyte));
00102     
00103     glMatrixMode(GL_PROJECTION);
00104     glPushMatrix();
00105     glLoadIdentity();
00106     glOrtho(-1.0,1.0,-1.0,1.0,0.0,100.0);
00107 
00108     glMatrixMode(GL_MODELVIEW);
00109     glPushMatrix();
00110     glLoadIdentity();
00111     glRasterPos2f(-1.0F,-1.0F);
00112     glDrawPixels(width(),height(),GL_RGB,GL_UNSIGNED_BYTE, (GLvoid *) _image.data());
00113     glPopMatrix();
00114 
00115     glMatrixMode(GL_PROJECTION);
00116     glPopMatrix();
00117     
00118     glMatrixMode(GL_MODELVIEW);
00119 }
00120 
00121 void 
00122 GltFrameBufferRGB::writePPM(ostream &os) const
00123 {
00124     string data;
00125     if (encodePPM(data,width(),height(),_image))
00126         writeStream(os,data);
00127 }
00128 
00129 void 
00130 GltFrameBufferRGB::writeTGA(ostream &os) const
00131 {
00132     string data;
00133     if (encodeTGA(data,width(),height(),_image))
00134         writeStream(os,data);
00135 }
00136 
00137 #ifdef GLT_PNG
00138 void 
00139 GltFrameBufferRGB::writePNG(ostream &os) const
00140 {
00141     string data;
00142     if (encodePNG(data,width(),height(),_image))
00143         writeStream(os,data);
00144 }
00145 #endif
00146 

Generated on Tue Nov 5 11:11:03 2002 for GLT by doxygen1.2.18