ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/material.h
Revision: 1.18
Committed: Sun Nov 7 03:31:07 2004 UTC (21 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.17: +8 -1 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 root 1.18 inline void std_vsh ()
14     {
15     using namespace shader::compile;
16    
17     vout.position = ftransform ();
18     }
19    
20     inline void std_vsh (const shader::gluvar &vertex)
21 root 1.16 {
22     using namespace shader::compile;
23    
24     vout.position = model_view_projection_matrix * vertex;
25     }
26 root 1.3
27 root 1.1 struct material
28     {
29 root 1.16
30     // the vertex shader fragment. it should check ctx.pass_data->light and
31     // only generate varying data when light is non-null. it should also use
32     // std_vsh () whenever possible.
33    
34     virtual void vsh (view &ctx) = 0;
35    
36     // the fragment shader fragment :). it should check ctx.pass_data->light
37     // and, if null, best do nothing. if non-null, it should call
38     // light->value to get the per-pixel light colour and apply it to the
39     // surface as neccessary.
40    
41     virtual void fsh (view &ctx) = 0;
42    
43     virtual void enable (view &ctx);
44     virtual void disable (view &ctx);
45    
46 root 1.1 virtual ~material ();
47     };
48    
49 root 1.16 struct texture_execption
50     {
51     texture_execption (string s) : msg(s) { }
52     string msg;
53 root 1.1 };
54    
55 root 1.3 struct texture
56     {
57     SDL_Surface *image;
58 root 1.12 GLuint name;
59 root 1.3 GLfloat texcoord[4];
60    
61     GLuint load_texture (SDL_Surface *surface, GLfloat *texcoord);
62    
63 root 1.16 texture (const char *f)
64 root 1.3 {
65     image = IMG_Load (f);
66    
67     if (!image)
68     throw (texture_execption ("Couldn't load " + (string) f + ": " + (string) IMG_GetError ()));
69    
70 root 1.12 name = load_texture (image, (GLfloat*)&texcoord);
71     if (name == 0)
72 root 1.3 throw (texture_execption ("Couldn't make GL Texture, failed to create new RGB SWSurface"));
73     }
74     };
75    
76 root 1.16 struct test_material : material
77 root 1.3 {
78 root 1.15 texture tex, norm;
79     shader::sampler_2d texvar, normvar;
80 root 1.12
81 root 1.16 void vsh (view &ctx);
82     void fsh (view &ctx);
83    
84 root 1.13 void enable (view &ctx);
85     void disable (view &ctx);
86 root 1.16
87     test_material ();
88 root 1.3 };
89 root 1.16
90 root 1.17 extern test_material *testmat;
91 root 1.3
92 root 1.1 #endif
93    
94