ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/material.h
Revision: 1.12
Committed: Fri Oct 29 15:58:50 2004 UTC (21 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.11: +16 -69 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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     inline int power_of_two (int input)
20     {
21     int value = 1;
22    
23     while (value < input)
24     {
25     value <<= 1;
26     }
27     return value;
28     }
29    
30 root 1.1 struct material
31     {
32 root 1.12 virtual void enable () = 0;
33     virtual void disable () = 0;
34 root 1.1 virtual ~material ();
35     };
36    
37     struct simple_material : material
38     {
39     colour diffuse, specular, emission;
40     GLfloat shininess;
41    
42 root 1.12 void enable ();
43     void disable ();
44 root 1.1
45     simple_material ()
46     : diffuse(1, 0, 1, 1)
47     , specular(1, 0, 1, 1)
48     , emission(1, 0, 1, 1)
49     , shininess(1.)
50     {
51     }
52     };
53    
54 root 1.3 struct texture
55     {
56     SDL_Surface *image;
57 root 1.12 GLuint name;
58 root 1.3 GLfloat texcoord[4];
59    
60     GLuint load_texture (SDL_Surface *surface, GLfloat *texcoord);
61    
62     texture(const char *f)
63     {
64     image = IMG_Load (f);
65    
66     if (!image)
67     throw (texture_execption ("Couldn't load " + (string) f + ": " + (string) IMG_GetError ()));
68    
69 root 1.12 name = load_texture (image, (GLfloat*)&texcoord);
70     if (name == 0)
71 root 1.3 throw (texture_execption ("Couldn't make GL Texture, failed to create new RGB SWSurface"));
72     }
73     };
74    
75 root 1.12 struct test_material
76 root 1.3 {
77 root 1.12 shader::program_object p;
78     texture tex;
79     shader::sampler_2d texvar;
80    
81     test_material ();
82     void enable ();
83     void disable ();
84 root 1.3 };
85    
86 root 1.1 #endif
87    
88