00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00036 #ifndef DISPLAY2D_H
00037 #define DISPLAY2D_H
00038
00039
00040 #include <error.h>
00041
00042
00043 namespace Display
00044 {
00074 class Image
00075 {
00076 public:
00077 Image();
00078 ~Image();
00079
00081 template <typename DataType>
00082 void update(const DataType* image, unsigned int width, unsigned int height);
00083
00086 void display() const;
00087
00088 private:
00089 GLuint m_textureName;
00090
00091 private:
00093 template <typename DataType>
00094 struct OpenGLArgs { static GLenum format, type; };
00095 };
00096
00097 }
00098
00099
00101
00103
00104 namespace Display
00105 {
00106 template <typename DataType>
00107 void Image::update(const DataType* image, unsigned int width, unsigned int height)
00108 {
00109
00110 if(!glIsTexture(m_textureName)) glGenTextures(1, &m_textureName);
00111
00112
00113 glBindTexture(GL_TEXTURE_2D, m_textureName); glCheckError();
00114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00117 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00118 glTexImage2D(GL_TEXTURE_2D,
00119 0,
00120 GL_RGBA,
00121 width,
00122 height,
00123 0,
00124 OpenGLArgs<DataType>::format,
00125 OpenGLArgs<DataType>::type,
00126 image);
00127 glCheckError();
00128 }
00129
00130
00131
00132 template <typename T> GLenum Image::OpenGLArgs<T> ::format = GL_LUMINANCE;
00133
00134
00135 #ifdef COLOR_H
00136
00137 #ifndef GL_BGR
00138 #define GL_BGR GL_BGR_EXT
00139 #endif
00140
00141
00142 template <typename T> struct Image::OpenGLArgs<color<T> > { static GLenum format, type; };
00143 template <typename T> GLenum Image::OpenGLArgs<color<T> >::type = OpenGLArgs<T>::type;
00144 template <typename T> GLenum Image::OpenGLArgs<color<T> >::format = GL_BGR;
00145
00146 #endif
00147
00148
00149 }
00150
00151
00152 #endif