00001 #include "tiled.h"
00002
00007 #include <glt/viewport.h>
00008 #include <glt/texture.h>
00009 #include <glt/error.h>
00010 #include <glt/rgb.h>
00011
00012 GltTextureViewport::GltTextureViewport(const GltTexture &texture,const bool tile,const bool blend)
00013 : _texture(texture), _tile(tile), _blend(blend)
00014 {
00015 color() = white;
00016 }
00017
00018 GltTextureViewport::~GltTextureViewport()
00019 {
00020 }
00021
00022 void
00023 GltTextureViewport::draw() const
00024 {
00025
00026 if (_texture.id()==0)
00027 return;
00028
00029
00030 GltViewport viewport(true);
00031
00032
00033 if (viewport.width()==0 || viewport.height()==0)
00034 return;
00035
00036 GLERROR
00037
00038 glPushAttrib(GL_ENABLE_BIT);
00039
00040 glDisable(GL_DEPTH_TEST);
00041 glDisable(GL_LIGHTING);
00042 glEnable(GL_TEXTURE_2D);
00043
00044 if (_blend)
00045 {
00046 glEnable(GL_BLEND);
00047 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00048 }
00049
00050 glColor();
00051
00052 _texture.set();
00053
00054 glMatrixMode(GL_PROJECTION);
00055 glPushMatrix();
00056 glLoadIdentity();
00057 glOrtho(0,viewport.width(),0,viewport.height(),-1,1);
00058
00059 glMatrixMode(GL_MODELVIEW);
00060 glPushMatrix();
00061 glLoadIdentity();
00062
00063 if (_tile)
00064 {
00065 const GLdouble iw = GLdouble(viewport.width()) /GLdouble(_texture.width());
00066 const GLdouble ih = GLdouble(viewport.height())/GLdouble(_texture.height());
00067
00068 glBegin(GL_POLYGON);
00069 glTexCoord2d( 0, 0); glVertex2i(0, 0);
00070 glTexCoord2d(iw, 0); glVertex2i(viewport.width(),0);
00071 glTexCoord2d(iw,ih); glVertex2i(viewport.width(),viewport.height());
00072 glTexCoord2d( 0,ih); glVertex2i(0, viewport.height());
00073 glEnd();
00074 }
00075 else
00076 {
00077 glBegin(GL_POLYGON);
00078 glTexCoord2i(0,0); glVertex2i(0, 0);
00079 glTexCoord2i(1,0); glVertex2i(_texture.width(),0);
00080 glTexCoord2i(1,1); glVertex2i(_texture.width(),_texture.height());
00081 glTexCoord2i(0,1); glVertex2i(0, _texture.height());
00082 glEnd();
00083 }
00084
00085 glPopMatrix();
00086 glMatrixMode(GL_PROJECTION);
00087 glPopMatrix();
00088 glMatrixMode(GL_MODELVIEW);
00089
00090 glPopAttrib();
00091
00092 GLERROR;
00093 }