1 |
root |
1.1 |
#ifndef MATERIAL_H |
2 |
|
|
#define MATERIAL_H |
3 |
|
|
|
4 |
root |
1.5 |
#include <vector> |
5 |
|
|
#include <string> |
6 |
|
|
#include <sstream> |
7 |
|
|
|
8 |
root |
1.11 |
using namespace std; |
9 |
root |
1.5 |
|
10 |
root |
1.1 |
#include "util.h" |
11 |
root |
1.12 |
#include "shader.h" |
12 |
root |
1.3 |
|
13 |
|
|
struct texture_execption |
14 |
|
|
{ |
15 |
|
|
texture_execption (string s) : msg(s) { } |
16 |
|
|
string msg; |
17 |
|
|
}; |
18 |
|
|
|
19 |
root |
1.1 |
struct material |
20 |
|
|
{ |
21 |
root |
1.13 |
virtual void enable (view &ctx) = 0; |
22 |
|
|
virtual void disable (view &ctx) = 0; |
23 |
root |
1.1 |
virtual ~material (); |
24 |
|
|
}; |
25 |
|
|
|
26 |
|
|
struct simple_material : material |
27 |
|
|
{ |
28 |
|
|
colour diffuse, specular, emission; |
29 |
|
|
GLfloat shininess; |
30 |
|
|
|
31 |
root |
1.13 |
void enable (view &ctx); |
32 |
|
|
void disable (view &ctx); |
33 |
root |
1.1 |
|
34 |
|
|
simple_material () |
35 |
|
|
: diffuse(1, 0, 1, 1) |
36 |
|
|
, specular(1, 0, 1, 1) |
37 |
|
|
, emission(1, 0, 1, 1) |
38 |
|
|
, shininess(1.) |
39 |
|
|
{ |
40 |
|
|
} |
41 |
|
|
}; |
42 |
|
|
|
43 |
root |
1.3 |
struct texture |
44 |
|
|
{ |
45 |
|
|
SDL_Surface *image; |
46 |
root |
1.12 |
GLuint name; |
47 |
root |
1.3 |
GLfloat texcoord[4]; |
48 |
|
|
|
49 |
|
|
GLuint load_texture (SDL_Surface *surface, GLfloat *texcoord); |
50 |
|
|
|
51 |
|
|
texture(const char *f) |
52 |
|
|
{ |
53 |
|
|
image = IMG_Load (f); |
54 |
|
|
|
55 |
|
|
if (!image) |
56 |
|
|
throw (texture_execption ("Couldn't load " + (string) f + ": " + (string) IMG_GetError ())); |
57 |
|
|
|
58 |
root |
1.12 |
name = load_texture (image, (GLfloat*)&texcoord); |
59 |
|
|
if (name == 0) |
60 |
root |
1.3 |
throw (texture_execption ("Couldn't make GL Texture, failed to create new RGB SWSurface")); |
61 |
|
|
} |
62 |
|
|
}; |
63 |
|
|
|
64 |
root |
1.12 |
struct test_material |
65 |
root |
1.3 |
{ |
66 |
root |
1.12 |
shader::program_object p; |
67 |
|
|
texture tex; |
68 |
|
|
shader::sampler_2d texvar; |
69 |
root |
1.13 |
shader::uniform_4f lightpos; |
70 |
root |
1.12 |
|
71 |
|
|
test_material (); |
72 |
root |
1.13 |
void enable (view &ctx); |
73 |
|
|
void disable (view &ctx); |
74 |
root |
1.3 |
}; |
75 |
|
|
|
76 |
root |
1.1 |
#endif |
77 |
|
|
|
78 |
|
|
|