//////////////////////////////////////////////////////////////////////////////// // Scorched3D (c) 2000-2003 // // This file is part of Scorched3D. // // Scorched3D is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // Scorched3D is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Scorched3D; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include GLBitmap::GLBitmap() : width_(0), height_(0), alpha_(false), newbits_(0) { } GLBitmap::GLBitmap(int startWidth, int startHeight, bool alpha, unsigned char fill) : width_(startWidth), height_(startHeight), alpha_(alpha), newbits_(0) { createBlank(startWidth, startHeight, alpha, fill); } GLBitmap::GLBitmap(const char * filename, bool alpha) : newbits_(0), width_(0), height_(0), alpha_(alpha) { if (filename) { loadFromFile(filename, alpha); } } GLBitmap::GLBitmap(const char * filename, const char *alphafilename, bool invert) : newbits_(0), width_(0), height_(0), alpha_(false) { GLBitmap bitmap(filename, false); GLBitmap alpha(alphafilename, false); if (bitmap.getBits() && alpha.getBits() && bitmap.getWidth() == alpha.getWidth() && bitmap.getHeight() == alpha.getHeight()) { createBlank(bitmap.getWidth(), bitmap.getHeight(), true); GLubyte *bbits = bitmap.getBits(); GLubyte *abits = alpha.getBits(); GLubyte *bits = getBits(); for (int y=0; yformat->BitsPerPixel != 24) { dialogExit("GLBitmap", formatString("ERROR: Bitmap \"%s\" is not encoded as a 24bit bitmap", filename)); } // Create the internal byte array createBlank(image->w, image->h, alpha); // Convert the returned bits from BGR to RGB // and flip the verticle scan lines GLubyte *from = (GLubyte *) image->pixels; for (int i=0; ipixels, brgbits, width_ * height_ * 3); if (!image) return false; SDL_SaveBMP(image, filename); SDL_FreeSurface (image); delete [] brgbits; return true; } void GLBitmap::grabScreen() { GLint viewport[4]; /* Current viewport */ glGetIntegerv(GL_VIEWPORT, viewport); createBlank(viewport[2], viewport[3], false); glFinish(); /* Finish all OpenGL commands */ glPixelStorei(GL_PACK_ALIGNMENT, 4); /* Force 4-byte alignment */ glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_SKIP_ROWS, 0); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); glReadPixels(0, 0, width_, height_, GL_RGB, GL_UNSIGNED_BYTE, newbits_); }