More texture fixes, including a flag to build power of 2 textures
[ne.git] / src / backend / texture.h
blob9c2a20f46fb9c007cc79faba5c1cb4c8c167d369
1 /************************************************************************
2 This file is part of NE.
4 NE is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 NE is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with NE. If not, see <http://www.gnu.org/licenses/>.
16 ************************************************************************/
18 #ifndef TEXTURE_H_
19 #define TEXTURE_H_
21 #include <GL/gl.h>
23 #ifdef __cplusplus
24 #include <string>
25 extern "C" {
26 #endif
28 void t_init();
30 struct texture
32 int ready;
33 int width, height;
34 GLfloat u, v;
35 GLuint gl_handle;
38 struct texture *t_create();
40 void t_destroy(struct texture *t);
42 int t_ready(struct texture *t);
44 void t_load(struct texture *t, const char *filename);
46 void t_unload(struct texture *t);
48 void t_apply(struct texture *t);
50 void t_clear();
52 void t_set(struct texture *t, GLuint name, GLuint value);
54 struct texture *t_screenshot();
56 /* C++ Texture */
57 #ifdef __cplusplus
60 class Texture
62 public:
63 Texture(const char *file = 0, bool mipmap=true)
65 t_init();
66 m_tex = t_create();
68 if (file)
69 load(file);
71 Texture(GLuint texid)
73 t_init();
74 m_tex = t_create();
75 m_tex->gl_handle = texid;
76 m_tex->ready = 1;
78 ~Texture()
80 t_destroy(m_tex);
83 static Texture *Screenshot()
85 Texture *t = new Texture();
86 t->m_tex = t_screenshot();
87 return t;
90 inline int getWidth()
92 return m_tex->width;
95 inline int getHeight()
97 return m_tex->height;
100 inline float getU()
102 return m_tex->u;
105 inline float getV()
107 return m_tex->v;
110 inline GLuint getHandle()
112 return m_tex->gl_handle;
115 inline bool isReady()
117 return (m_tex && t_ready(m_tex));
120 inline void set(GLuint name, GLuint value)
122 t_set(m_tex,name,value);
125 inline void load(const char *file, bool mipmap=true)
127 t_load(m_tex,file);
130 inline void unload()
132 t_unload(m_tex);
135 inline void apply()
137 t_apply(m_tex);
140 inline void clear()
142 t_clear();
145 private:
146 struct texture *m_tex;
149 #endif
151 #endif /*TEXTURE_H_*/