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