IShaders.cpp (2860B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 //----------------------------------------------------------------------------- 23 // 24 // $LogFile$ 25 // $Revision: 1.1.2.2 $ 26 // $Author: ttimo $ 27 // $Date: 2000/02/24 22:24:45 $ 28 // $Log: IShaders.cpp,v $ 29 // Revision 1.1.2.2 2000/02/24 22:24:45 ttimo 30 // RC2 31 // 32 // Revision 1.1.2.1 2000/02/11 03:52:30 ttimo 33 // working on the IShader interface 34 // 35 // 36 // DESCRIPTION: 37 // implementation of the shaders / textures interface 38 // 39 40 #include "stdafx.h" 41 42 //++timo NOTE: this whole part is evolving on a seperate branch on SourceForge 43 // will eventually turn into a major rewrite of the shader / texture code 44 45 // this is a modified version of Texture_ForName 46 qtexture_t* WINAPI QERApp_TryTextureForName(const char* name) 47 { 48 qtexture_t *q; 49 char filename[1024]; 50 for (q=g_qeglobals.d_qtextures ; q ; q=q->next) 51 { 52 if (!strcmp(name, q->filename)) 53 return q; 54 } 55 // try loading from file .. this is a copy of the worst part of Texture_ForName 56 char cWork[1024]; 57 sprintf (filename, "%s/%s.tga", ValueForKey (g_qeglobals.d_project_entity, "texturepath"), name); 58 QE_ConvertDOSToUnixName( cWork, filename ); 59 strcpy(filename, cWork); 60 unsigned char* pPixels = NULL; 61 int nWidth; 62 int nHeight; 63 LoadImage(filename, &pPixels, &nWidth, &nHeight); 64 if (pPixels == NULL) 65 { 66 // try jpg 67 // blatant assumption of .tga should be fine since we sprintf'd it above 68 int nLen = strlen(filename); 69 filename[nLen-3] = 'j'; 70 filename[nLen-2] = 'p'; 71 filename[nLen-1] = 'g'; 72 LoadImage(filename, &pPixels, &nWidth, &nHeight); 73 } 74 if (pPixels) 75 { 76 q = Texture_LoadTGATexture(pPixels, nWidth, nHeight, NULL, 0, 0, 0); 77 //++timo storing the filename .. will be removed by shader code cleanup 78 // this is dirty, and we sure miss some places were we should fill the filename info 79 strcpy( q->filename, name ); 80 SetNameShaderInfo(q, filename, name); 81 Sys_Printf ("done.\n", name); 82 free(pPixels); 83 return q; 84 } 85 return NULL; 86 }