|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Global storage for textures; manages and draws them 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #include <cassert> 00031 #include <iostream> 00032 #include <fx.h> 00033 #include <fx3d.h> 00034 #include "GUITexturesHelper.h" 00035 #include <utils/gui/globjects/GUIGlObject.h> 00036 00037 #ifdef _WIN32 00038 #include <windows.h> 00039 #endif 00040 00041 #include <GL/gl.h> 00042 00043 #ifdef CHECK_MEMORY_LEAKS 00044 #include <foreign/nvwa/debug_new.h> 00045 #endif // CHECK_MEMORY_LEAKS 00046 00047 00048 // =========================================================================== 00049 // definition of static variables 00050 // =========================================================================== 00051 bool gAllowTextures; 00052 00053 00054 // =========================================================================== 00055 // method definitions 00056 // =========================================================================== 00057 GUIGlID 00058 GUITexturesHelper::add(FXImage* i) { 00059 GUIGlID id; 00060 glGenTextures(1, &id); 00061 glBindTexture(GL_TEXTURE_2D, id); 00062 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 00063 i->getWidth(), i->getHeight(), 0, 00064 GL_RGBA, GL_UNSIGNED_BYTE, i->getData()); 00065 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00066 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00067 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 00068 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 00069 glBindTexture(GL_TEXTURE_2D, 0); 00070 return id; 00071 } 00072 00073 00074 void 00075 GUITexturesHelper::drawTexturedBox(unsigned int which, SUMOReal size) { 00076 drawTexturedBox(which, size, size, -size, -size); 00077 } 00078 00079 00080 void 00081 GUITexturesHelper::drawTexturedBox(unsigned int which, 00082 SUMOReal sizeX1, SUMOReal sizeY1, 00083 SUMOReal sizeX2, SUMOReal sizeY2) { 00084 if (!gAllowTextures) { 00085 return; 00086 } 00087 glEnable(GL_TEXTURE_2D); 00088 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00089 glDisable(GL_CULL_FACE); 00090 glDisable(GL_DEPTH_TEST); 00091 glDisable(GL_LIGHTING); 00092 glDisable(GL_COLOR_MATERIAL); 00093 glDisable(GL_TEXTURE_GEN_S); 00094 glDisable(GL_TEXTURE_GEN_T); 00095 glDisable(GL_ALPHA_TEST); 00096 glEnable(GL_BLEND); 00097 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00098 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 00099 glBindTexture(GL_TEXTURE_2D, which); 00100 glBegin(GL_TRIANGLE_STRIP); 00101 glTexCoord2f(0, 1); 00102 glVertex2d(sizeX1, sizeY1); 00103 glTexCoord2f(0, 0); 00104 glVertex2d(sizeX1, sizeY2); 00105 glTexCoord2f(1, 1); 00106 glVertex2d(sizeX2, sizeY1); 00107 glTexCoord2f(1, 0); 00108 glVertex2d(sizeX2, sizeY2); 00109 glEnd(); 00110 glBindTexture(GL_TEXTURE_2D, 0); 00111 glEnable(GL_DEPTH_TEST); 00112 } 00113 00114 00115 /****************************************************************************/