GLWBitmap.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <GLW/GLWBitmap.h>
00022 #include <GLEXT/GLState.h>
00023 #include <common/Defines.h>
00024 
00025 REGISTER_CLASS_SOURCE(GLWBitmap);
00026 
00027 GLWBitmap::GLWBitmap(float x, float y, float w, float h, Image *bitmap) : 
00028         GLWidget(x, y, w, h),
00029         bitmap_(bitmap)
00030 {
00031 }
00032 
00033 GLWBitmap::~GLWBitmap()
00034 {
00035 }
00036 
00037 void GLWBitmap::draw()
00038 {
00039         if (bitmap_)
00040         {
00041                 GLState state(GLState::TEXTURE_OFF | GLState::BLEND_OFF);
00042 
00043                 int width = MIN(bitmap_->getWidth(), (int) w_);
00044                 int height = MIN(bitmap_->getHeight(), (int) h_);
00045 
00046                 glPixelStorei(GL_PACK_ALIGNMENT, 4);    /* Force 4-byte alignment */
00047                 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
00048                 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
00049                 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
00050 
00051                 glRasterPos2f(x_, y_);
00052                 glDrawPixels(
00053                         width, 
00054                         height,
00055                         GL_RGB, 
00056                         GL_UNSIGNED_BYTE, 
00057                         bitmap_->getBits());
00058 
00059                 glPixelStorei(GL_PACK_ALIGNMENT, 4);    /* Force 4-byte alignment */
00060                 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
00061                 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
00062                 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
00063         }
00064 
00065         GLWidget::draw();
00066 }
00067 
00068 bool GLWBitmap::initFromXML(XMLNode *node)
00069 {
00070         if (!GLWidget::initFromXML(node)) return false;
00071         return true;
00072 }
00073 

Generated on Mon Feb 16 15:14:45 2009 for Scorched3D by  doxygen 1.5.3