SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUITexturesHelper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Global storage for textures; manages and draws them
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <cassert>
33 #include <iostream>
34 #include <fx.h>
35 #include <fx3d.h>
36 #include "GUITexturesHelper.h"
38 
39 #ifdef _WIN32
40 #include <windows.h>
41 #endif
42 
43 #include <GL/gl.h>
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // definition of static variables
52 // ===========================================================================
54 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 GUIGlID
61  GUIGlID id;
62  glGenTextures(1, &id);
63  glBindTexture(GL_TEXTURE_2D, id);
64  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
65  i->getWidth(), i->getHeight(), 0,
66  GL_RGBA, GL_UNSIGNED_BYTE, i->getData());
67  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
68  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
69  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
70  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
71  glBindTexture(GL_TEXTURE_2D, 0);
72  return id;
73 }
74 
75 
76 void
77 GUITexturesHelper::drawTexturedBox(unsigned int which, SUMOReal size) {
78  drawTexturedBox(which, size, size, -size, -size);
79 }
80 
81 
82 void
84  SUMOReal sizeX1, SUMOReal sizeY1,
85  SUMOReal sizeX2, SUMOReal sizeY2) {
86  if (!gAllowTextures) {
87  return;
88  }
89  glEnable(GL_TEXTURE_2D);
90  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
91  glDisable(GL_CULL_FACE);
92  glDisable(GL_DEPTH_TEST);
93  glDisable(GL_LIGHTING);
94  glDisable(GL_COLOR_MATERIAL);
95  glDisable(GL_TEXTURE_GEN_S);
96  glDisable(GL_TEXTURE_GEN_T);
97  glDisable(GL_ALPHA_TEST);
98  glEnable(GL_BLEND);
99  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
100  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
101  glBindTexture(GL_TEXTURE_2D, which);
102  glBegin(GL_TRIANGLE_STRIP);
103  glTexCoord2f(0, 1);
104  glVertex2d(sizeX1, sizeY1);
105  glTexCoord2f(0, 0);
106  glVertex2d(sizeX1, sizeY2);
107  glTexCoord2f(1, 1);
108  glVertex2d(sizeX2, sizeY1);
109  glTexCoord2f(1, 0);
110  glVertex2d(sizeX2, sizeY2);
111  glEnd();
112  glBindTexture(GL_TEXTURE_2D, 0);
113  glEnable(GL_DEPTH_TEST);
114 }
115 
116 
117 /****************************************************************************/