2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /**> HEADER FILES <**/
24 #include "TGALoader.h"
26 extern float texdetail;
27 extern TGAImageRec texture;
30 extern bool visibleloading;
32 extern bool LoadImage(const char * fname, TGAImageRec & tex);
33 /********************> LoadTGA() <*****/
34 bool upload_image(const unsigned char* filePath, bool hasalpha)
37 Game::LoadingScreen();
41 // for Windows, just use TGA loader for now
43 CopyPascalStringToC( filePath, fileName);
45 // change extension to .TGA
46 int len = strlen( fileName);
49 fileName[ len - 3] = 't';
50 fileName[ len - 2] = 'g';
51 fileName[ len - 1] = 'a';
54 //return (LoadTGA( fileName) != NULL);
55 return (LoadImage(fileName, texture));
64 err = FSPathMakeRef((const UInt8*)filePath, &fsref, &isdir);
68 err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsspec, NULL);
74 //err = FSMakeFSSpec (0, 0, (const unsigned char*)filePath, &fsspec);
75 err = FSMakeFSSpec (0, 0, filePath, &fsspec);
76 //err=FSPathMakeFSSpec((const UInt8*)filePath,&fsspec,&isdir);*/
80 GraphicsImportComponent gi;
81 err = GetGraphicsImporterForFile(&fsspec, &gi);
86 cr = GraphicsImportGetNaturalBounds(gi, &natbounds);
88 //~ size_t buffersize = 4 * natbounds.bottom * natbounds.right;
89 //void* buf = malloc(buffersize);
90 texture.sizeX = natbounds.right;
91 texture.sizeY = natbounds.bottom;
94 //if(!hasalpha)texture.bpp = 24;
97 err = QTNewGWorldFromPtr(&gw, k32ARGBPixelFormat, &natbounds, NULL, NULL,
98 0, texture.data, 4 * natbounds.right);
102 cr = GraphicsImportSetGWorld(gi, gw, NULL);
104 natbounds.top = natbounds.bottom;
105 natbounds.bottom = 0;
107 cr = GraphicsImportSetBoundsRect(gi, &natbounds);
109 cr = GraphicsImportDraw(gi);
111 err = CloseComponent(gi);
115 /*glTexImage2D(textureTarget, 0, GL_RGBA, natbounds.right, natbounds.top, 0,
116 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buf);
122 // Loop Through The Image Data
123 GLuint imageSize; // Used To Store The Image Size When Setting Aside Ram
124 GLuint temp; // Temporary Variable
125 GLuint bytesPerPixel; // Temporary Variable
126 bytesPerPixel = texture.bpp / 8;
127 imageSize = texture.sizeX * texture.sizeY * bytesPerPixel;
130 for ( GLuint i = 0; i < int( imageSize ); i += 4 ) {
131 // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue)
132 temp = texture.data[i]; // Temporarily Store The Value At Image Data 'i'
133 texture.data[i] = texture.data[i + 1]; // Set The 1st Byte To The Value Of The 3rd Byte
134 texture.data[i + 1] = texture.data[i + 2]; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value)
135 texture.data[i + 2] = texture.data[i + 3];
136 texture.data[i + 3] = temp;
142 for ( GLuint i = 0; i < int( imageSize ); i += 4 ) {
143 texture.data[i + 3] = 255;
144 /*texture.data[tempplace] = texture.data[i]; // Set The 1st Byte To The Value Of The 3rd Byte
145 texture.data[tempplace + 1] = texture.data[i + 1]; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value)
146 texture.data[tempplace + 2] = texture.data[i + 2];
155 for ( GLuint k = 0; k < int( imageSize); k += bytesPerPixel * texture.sizeX * texdetail ) {
156 for ( GLuint i = 0; i < int( imageSize / texture.sizeY ); i += bytesPerPixel * texdetail ) {
157 for ( GLuint b = 0; b < bytesPerPixel ; b ++ ) {
160 for ( GLuint l = 0; l < texdetail * texture.sizeX ; l += texture.sizeX ) {
161 for ( GLuint j = 0; j < texdetail ; j ++ ) {
162 temp += (int)texture.data[k + i + j * bytesPerPixel + l * bytesPerPixel + b]; // Set The 1st Byte To The Value Of The 3rd Byte
166 texture.data[which + b] = GLubyte(temp / howmany);
168 which += bytesPerPixel;
171 texture.sizeX /= texdetail;
172 texture.sizeY /= texdetail;