IShaders.cpp 2.8 KB

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