14 #include <simgear/xgl.h>
16 #include "GLBitmaps.h"
18 GlBitmap::GlBitmap( GLenum mode, GLint width, GLint height, GLubyte *bitmap )
19 : m_bytesPerPixel(mode==GL_RGB?3:4), m_width(width), m_height(height), m_bitmap(NULL)
21 m_bitmapSize = m_bytesPerPixel*m_width*m_height;
25 glGetIntegerv( GL_VIEWPORT, vp );
28 m_bitmapSize = m_bytesPerPixel*m_width*m_height;
30 m_bitmap = (GLubyte *)malloc( m_bitmapSize );
31 if ( bitmap ) memcpy( m_bitmap, bitmap, m_bitmapSize );
32 else glReadPixels( 0,0, m_width,m_height, mode, GL_UNSIGNED_BYTE, m_bitmap );
35 GlBitmap::~GlBitmap( )
37 if ( m_bitmap ) free( m_bitmap );
40 GLubyte *GlBitmap::getBitmap()
45 void GlBitmap::copyBitmap( GlBitmap *from, GLint at_x, GLint at_y )
47 GLint newWidth = at_x + from->m_width;
48 GLint newHeight = at_y + from->m_height;
49 if ( newWidth < m_width ) newWidth = m_width;
50 if ( newHeight < m_height ) newHeight = m_height;
51 m_bitmapSize = m_bytesPerPixel*newWidth*newHeight;
52 GLubyte *newBitmap = (GLubyte *)malloc( m_bitmapSize );
54 for ( y=0; y<m_height; y++ )
56 GLubyte *s = m_bitmap + m_bytesPerPixel * (y * m_width);
57 GLubyte *d = newBitmap + m_bytesPerPixel * (y * newWidth);
58 memcpy( d, s, m_bytesPerPixel * m_width );
64 for ( y=0; y<from->m_height; y++ )
66 GLubyte *s = from->m_bitmap + from->m_bytesPerPixel * (y * from->m_width);
67 GLubyte *d = m_bitmap + m_bytesPerPixel * ((at_y+y) * m_width + at_x);
68 for ( x=0; x<from->m_width; x++ )
73 if ( m_bytesPerPixel == 4 )
75 d[3] = (from->m_bytesPerPixel == 4) ? s[3] : 0;
77 s += from->m_bytesPerPixel;