head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.35; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.49; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.53.58; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.21.54; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# GLBitmaps.cxx

    00001 #ifdef HAVE_CONFIG_H
    00002 #  include <simgear_config.h>
    00003 #endif
    00004
    00005 #ifdef HAVE_WINDOWS_H
    00006 #  include <windows.h>
    00007 #endif
    00008
    00009 #include <stdio.h>
    00010 #include <stdlib.h>
    00011 #include <limits.h>
    00012 #include <string.h>             // memcpy()
    00013
    00014 #include <GL/glut.h>
    00015 #include <simgear/xgl/xgl.h>
    00016
    00017 #include "GLBitmaps.h"
    00018
    00019 GlBitmap::GlBitmap( GLenum mode, GLint width, GLint height, GLubyte *bitmap )
    00020 : m_bytesPerPixel(mode==GL_RGB?3:4), m_width(width), m_height(height), m_bitmap(NULL)
    00021 {
    00022         m_bitmapSize = m_bytesPerPixel*m_width*m_height;
    00023         if ( !m_bitmapSize )
    00024         {
    00025                 GLint vp[4];
    00026                 glGetIntegerv( GL_VIEWPORT, vp );
    00027                 m_width = vp[2];
    00028                 m_height = vp[3];
    00029                 m_bitmapSize = m_bytesPerPixel*m_width*m_height;
    00030         }
    00031         m_bitmap = (GLubyte *)malloc( m_bitmapSize );
    00032         if ( bitmap ) memcpy( m_bitmap, bitmap, m_bitmapSize );
    00033         else glReadPixels( 0,0, m_width,m_height, mode, GL_UNSIGNED_BYTE, m_bitmap );
    00034 }
    00035
    00036 GlBitmap::~GlBitmap( )
    00037 {
    00038         if ( m_bitmap ) free( m_bitmap );
    00039 }
    00040
    00041 GLubyte *GlBitmap::getBitmap()
    00042 {
    00043         return m_bitmap;
    00044 }
    00045
    00046 void GlBitmap::copyBitmap( GlBitmap *from, GLint at_x, GLint at_y )
    00047 {
    00048         GLint newWidth = at_x + from->m_width;
    00049         GLint newHeight = at_y + from->m_height;
    00050         if ( newWidth < m_width ) newWidth = m_width;
    00051         if ( newHeight < m_height ) newHeight = m_height;
    00052         m_bitmapSize = m_bytesPerPixel*newWidth*newHeight;
    00053         GLubyte *newBitmap = (GLubyte *)malloc( m_bitmapSize );
    00054         GLint x,y;
    00055         for ( y=0; y<m_height; y++ )
    00056         {
    00057                 GLubyte *s = m_bitmap + m_bytesPerPixel * (y * m_width);
    00058                 GLubyte *d = newBitmap + m_bytesPerPixel * (y * newWidth);
    00059                 memcpy( d, s, m_bytesPerPixel * m_width );
    00060         }
    00061         m_width = newWidth;
    00062         m_height = newHeight;
    00063         free( m_bitmap );
    00064         m_bitmap = newBitmap;
    00065         for ( y=0; y<from->m_height; y++ )
    00066         {
    00067                 GLubyte *s = from->m_bitmap + from->m_bytesPerPixel * (y * from->m_width);
    00068                 GLubyte *d = m_bitmap + m_bytesPerPixel * ((at_y+y) * m_width + at_x);
    00069                 for ( x=0; x<from->m_width; x++ )
    00070                 {
    00071                         d[0] = s[0];
    00072                         d[1] = s[1];
    00073                         d[2] = s[2];
    00074                         if ( m_bytesPerPixel == 4 )
    00075                         {
    00076                                 d[3] = (from->m_bytesPerPixel == 4) ? s[3] : 0;
    00077                         }
    00078                         s += from->m_bytesPerPixel;
    00079                         d += m_bytesPerPixel;
    00080                 }
    00081         }
    00082 }
    00083

@ 1.3 log @Oops, try again. @ text @d92 1 a92 1