1 | #ifndef UTIL_H |
1 | #ifndef UTIL_H |
2 | #define UTIL_H |
2 | #define UTIL_H |
3 | |
3 | |
|
|
4 | #include <SDL/SDL.h> |
|
|
5 | #include <SDL/SDL_image.h> |
4 | #include <cmath> |
6 | #include <cmath> |
5 | #include <vector> |
7 | #include <vector> |
|
|
8 | #include <string> |
6 | |
9 | |
7 | #include <Cg/cg.h> |
10 | #include <Cg/cg.h> |
8 | #include <Cg/cgGL.h> |
11 | #include <Cg/cgGL.h> |
9 | |
12 | |
10 | using namespace std; |
13 | using namespace std; |
… | |
… | |
221 | }; |
224 | }; |
222 | |
225 | |
223 | extern skedjuhlar main_scheduler; |
226 | extern skedjuhlar main_scheduler; |
224 | */ |
227 | */ |
225 | |
228 | |
|
|
229 | GLuint SDL_GL_LoadTexture (SDL_Surface * surface, GLfloat * texcoord); |
|
|
230 | inline int power_of_two (int input) |
|
|
231 | { |
|
|
232 | int value = 1; |
|
|
233 | |
|
|
234 | while (value < input) |
|
|
235 | { |
|
|
236 | value <<= 1; |
|
|
237 | } |
|
|
238 | return value; |
|
|
239 | } |
|
|
240 | |
|
|
241 | |
|
|
242 | |
|
|
243 | struct TextureExecption { |
|
|
244 | TextureExecption(string s) : msg(s) {} |
|
|
245 | string msg; |
|
|
246 | }; |
|
|
247 | struct Texture { |
|
|
248 | SDL_Surface *image; |
|
|
249 | GLuint texture; |
|
|
250 | GLfloat texcoord[4]; |
|
|
251 | |
|
|
252 | public: |
|
|
253 | void new_from_file (const char *f) { |
|
|
254 | image = IMG_Load(f); |
|
|
255 | if(!image) |
|
|
256 | throw (TextureExecption("Couldn't load " + (string) f + ": " + (string) IMG_GetError ())); |
|
|
257 | texture = SDL_GL_LoadTexture (image, (GLfloat*)&texcoord); |
|
|
258 | if (texture == 0) |
|
|
259 | throw (TextureExecption("Couldn't make GL Texture, failed to create new RGB SWSurface")); |
|
|
260 | } |
|
|
261 | }; |
|
|
262 | |
226 | #endif |
263 | #endif |
227 | |
264 | |