GUITexturesHelper Class Reference

#include <GUITexturesHelper.h>


Detailed Description

Global storage for textures; manages and draws them.

Definition at line 49 of file GUITexturesHelper.h.


Static Public Member Functions

static unsigned int add (FXImage *i)
 Adds a texture to use.
static void close ()
 Removes all allocated textures.
static void drawDirectionArrow (unsigned int which, SUMOReal sizeX1, SUMOReal sizeY1, SUMOReal sizeX2, SUMOReal sizeY2)
 Draws the given link arrow as a rectangle with the given sizes.
static void drawDirectionArrow (GUITexture which, SUMOReal size)
 Draws the given link arrow as a box of the given size.
static void drawTexturedBox (unsigned int which, SUMOReal sizeX1, SUMOReal sizeY1, SUMOReal sizeX2, SUMOReal sizeY2)
 Draws a named texture as a rectangle with the given sizes.
static void drawTexturedBox (unsigned int which, SUMOReal size)
 Draws a named texture as a box with the given size.
static void init (FXApp *a)
 Initialises the textures-subsystem by setting the application.

Static Private Member Functions

static void assignTextures ()
 Builds previously added textures if not already done.

Static Private Attributes

static FXApp * myApp = 0
 The application to use for building textures.
static GLuint myTextureIDs [TEXTURE_MAX]
 Storage for texture ids (!!! as a fixed-size container?).
static FXImage * myTextures [TEXTURE_MAX]
 Storage for textures (!!! as a fixed-size container?).
static bool myWasInitialised = false
 Information whether the textures have been build.

Member Function Documentation

unsigned int GUITexturesHelper::add ( FXImage *  i  )  [static]

Adds a texture to use.

Definition at line 107 of file GUITexturesHelper.cpp.

Referenced by GUISUMOAbstractView::drawDecals().

00107                                  {
00108     GLuint id;
00109     glGenTextures(1, &id);
00110     glBindTexture(GL_TEXTURE_2D, id);
00111     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
00112                  i->getWidth(), i->getHeight(), 0,
00113                  GL_RGBA, GL_UNSIGNED_BYTE, i->getData());
00114     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00115     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00116     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00117     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00118     glBindTexture(GL_TEXTURE_2D, 0);
00119     return id;
00120 }

void GUITexturesHelper::assignTextures (  )  [static, private]

Builds previously added textures if not already done.

Definition at line 75 of file GUITexturesHelper.cpp.

References gAllowTextures, MSLink::LINKDIR_LEFT, MSLink::LINKDIR_PARTLEFT, MSLink::LINKDIR_PARTRIGHT, MSLink::LINKDIR_RIGHT, MSLink::LINKDIR_STRAIGHT, MSLink::LINKDIR_TURN, myApp, myTextureIDs, myTextures, myWasInitialised, and TEXTURE_MAX.

Referenced by drawTexturedBox().

00075                                   {
00076     if (myWasInitialised) {
00077         return;
00078     }
00079     // check whether other textures shall be used
00080     myWasInitialised = true;
00081     if (!gAllowTextures) {
00082         return;
00083     }
00084     // build texture images
00085     glGenTextures(6, myTextureIDs);
00086     myTextures[MSLink::LINKDIR_STRAIGHT] = new FXXPMImage(myApp, p_xpm, IMAGE_KEEP);
00087     myTextures[MSLink::LINKDIR_TURN] = new FXXPMImage(myApp, pl_3_xpm, IMAGE_KEEP);
00088     myTextures[MSLink::LINKDIR_LEFT] = new FXXPMImage(myApp, pl_2_xpm, IMAGE_KEEP);
00089     myTextures[MSLink::LINKDIR_RIGHT] = new FXXPMImage(myApp, pr_2_xpm, IMAGE_KEEP);
00090     myTextures[MSLink::LINKDIR_PARTLEFT] = new FXXPMImage(myApp, pl_1_xpm, IMAGE_KEEP);
00091     myTextures[MSLink::LINKDIR_PARTRIGHT] = new FXXPMImage(myApp, pr_1_xpm, IMAGE_KEEP);
00092     // allocate in gl (bind)
00093     for (size_t i=0; i<TEXTURE_MAX; i++) {
00094         glBindTexture(GL_TEXTURE_2D,myTextureIDs[i]);
00095         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
00096                      myTextures[i]->getWidth(), myTextures[i]->getHeight(), 0,
00097                      GL_RGBA, GL_UNSIGNED_BYTE, myTextures[i]->getData());
00098         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00099         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00100         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00101         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00102         glBindTexture(GL_TEXTURE_2D, 0);
00103     }
00104 }

void GUITexturesHelper::close (  )  [static]

Removes all allocated textures.

Definition at line 181 of file GUITexturesHelper.cpp.

References myTextures, myWasInitialised, and TEXTURE_MAX.

Referenced by GUIApplicationWindow::~GUIApplicationWindow().

00181                          {
00182     if (!myWasInitialised) {
00183         // nothing to do
00184         return;
00185     }
00186     for (size_t i=0; i<TEXTURE_MAX; i++) {
00187         delete myTextures[i];
00188     }
00189 
00190 }

void GUITexturesHelper::drawDirectionArrow ( unsigned int  which,
SUMOReal  sizeX1,
SUMOReal  sizeY1,
SUMOReal  sizeX2,
SUMOReal  sizeY2 
) [static]

Draws the given link arrow as a rectangle with the given sizes.

Definition at line 130 of file GUITexturesHelper.cpp.

References drawTexturedBox(), and myTextureIDs.

00132                                                                         {
00133     drawTexturedBox(myTextureIDs[which], sizeX1, sizeY1, sizeX2, sizeY2);
00134 }

void GUITexturesHelper::drawDirectionArrow ( GUITexture  which,
SUMOReal  size 
) [static]

Draws the given link arrow as a box of the given size.

Definition at line 124 of file GUITexturesHelper.cpp.

References drawTexturedBox(), and myTextureIDs.

Referenced by GUIE3Collector::MyWrapper::drawSingleCrossing(), and ROWdrawAction_drawArrows().

00124                                                                      {
00125     drawTexturedBox(myTextureIDs[which], size, size, -size, -size);
00126 }

void GUITexturesHelper::drawTexturedBox ( unsigned int  which,
SUMOReal  sizeX1,
SUMOReal  sizeY1,
SUMOReal  sizeX2,
SUMOReal  sizeY2 
) [static]

Draws a named texture as a rectangle with the given sizes.

Definition at line 143 of file GUITexturesHelper.cpp.

References assignTextures(), gAllowTextures, and myWasInitialised.

00145                                                                      {
00146     if (!gAllowTextures) {
00147         return;
00148     }
00149     if (!myWasInitialised) {
00150         assignTextures();
00151     }
00152     glEnable(GL_TEXTURE_2D);
00153     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00154     glDisable(GL_CULL_FACE);
00155     glDisable(GL_DEPTH_TEST);
00156     glDisable(GL_LIGHTING);
00157     glDisable(GL_COLOR_MATERIAL);
00158     glDisable(GL_TEXTURE_GEN_S);
00159     glDisable(GL_TEXTURE_GEN_T);
00160     glDisable(GL_ALPHA_TEST);
00161     glEnable(GL_BLEND);
00162     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00163     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
00164     glBindTexture(GL_TEXTURE_2D, which);
00165     glBegin(GL_TRIANGLE_STRIP);
00166     glTexCoord2f(0, 1);
00167     glVertex2d(sizeX1, sizeY1);
00168     glTexCoord2f(0, 0);
00169     glVertex2d(sizeX1, sizeY2);
00170     glTexCoord2f(1, 1);
00171     glVertex2d(sizeX2, sizeY1);
00172     glTexCoord2f(1, 0);
00173     glVertex2d(sizeX2, sizeY2);
00174     glEnd();
00175     glBindTexture(GL_TEXTURE_2D, 0);
00176     glEnable(GL_DEPTH_TEST);
00177 }

void GUITexturesHelper::drawTexturedBox ( unsigned int  which,
SUMOReal  size 
) [static]

Draws a named texture as a box with the given size.

Definition at line 137 of file GUITexturesHelper.cpp.

Referenced by GUISUMOAbstractView::drawDecals(), and drawDirectionArrow().

00137                                                                     {
00138     drawTexturedBox(which, size, size, -size, -size);
00139 }

void GUITexturesHelper::init ( FXApp *  a  )  [static]

Initialises the textures-subsystem by setting the application.

Definition at line 68 of file GUITexturesHelper.cpp.

References myApp, and myWasInitialised.

Referenced by GUIApplicationWindow::dependentBuild(), and GUIApplicationWindow::handleEvent_SimulationLoaded().

00068                                 {
00069     myApp = a;
00070     myWasInitialised = false;
00071 }


Field Documentation

FXApp * GUITexturesHelper::myApp = 0 [static, private]

The application to use for building textures.

Definition at line 83 of file GUITexturesHelper.h.

Referenced by assignTextures(), and init().

GLuint GUITexturesHelper::myTextureIDs [static, private]

Storage for texture ids (!!! as a fixed-size container?).

Definition at line 86 of file GUITexturesHelper.h.

Referenced by assignTextures(), and drawDirectionArrow().

FXImage * GUITexturesHelper::myTextures [static, private]

Storage for textures (!!! as a fixed-size container?).

Definition at line 89 of file GUITexturesHelper.h.

Referenced by assignTextures(), and close().

bool GUITexturesHelper::myWasInitialised = false [static, private]

Information whether the textures have been build.

Definition at line 80 of file GUITexturesHelper.h.

Referenced by assignTextures(), close(), drawTexturedBox(), and init().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:45 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6