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