ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/material.C
(Generate patch)

Comparing libgender/material.C (file contents):
Revision 1.17 by root, Fri Oct 29 16:05:21 2004 UTC vs.
Revision 1.18 by root, Fri Oct 29 17:21:54 2004 UTC

3 3
4#include <algorithm> 4#include <algorithm>
5 5
6#include "opengl.h" 6#include "opengl.h"
7#include "material.h" 7#include "material.h"
8#include "view.h"
8#include "util.h" 9#include "util.h"
9 10
10material::~material () 11material::~material ()
11{ 12{
12} 13}
13 14
14void 15void
15simple_material::enable () 16simple_material::enable (view &ctx)
16{ 17{
17 glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *) & diffuse); 18 glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *) & diffuse);
18 glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *) & specular); 19 glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *) & specular);
19 glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *) & emission); 20 glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *) & emission);
20 glMaterialf (GL_FRONT, GL_SHININESS, shininess); 21 glMaterialf (GL_FRONT, GL_SHININESS, shininess);
21} 22}
22 23
23void 24void
24simple_material::disable () 25simple_material::disable (view &ctx)
25{ 26{
26} 27}
27 28
28GLuint 29GLuint
29texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) 30texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord)
92{ 93{
93 using namespace shader; 94 using namespace shader;
94 95
95 p.vsh->start (); 96 p.vsh->start ();
96 97
97 temp_4f lightpos;
98 temp_4f wpos; 98 temp_4f wpos;
99
100 wpos = shader::gl.model_view_projection_matrix * vin.vertex;
99 101
100 //lightpos = shader::vec4 (0, 10, 0, 1); 102 vout.position = wpos;
101 vout.position = shader::gl.model_view_projection_matrix * vin.vertex;
102 vout.tex_coord[0] = vin.tex_coord[0]; 103 vout.tex_coord[0] = vin.tex_coord[0];
103 //vout.tex_coord[1] = normalize (lightpos - wpos); 104 vout.tex_coord[1] = shader::gl.model_view_matrix * shader::vec4 (x (vin.normal), y(vin.normal), z(vin.normal), 0);
104 //vout.tex_coord[2] = normalize (wpos);
105 //vout.tex_coord[3] = normalize (xyz (gl.model_view_matrix_inverse_transpose) * vin.normal);
106 //vout.tex_coord[4] = normalize (xyz (gl.projection_matrix_inverse_transpose) - wpos);
107 105
108 p.vsh->end (); 106 p.vsh->end ();
109 p.vsh->compile (); 107 p.vsh->compile ();
110 108
111 fragment_shader fsh;
112
113 p.fsh->start (); 109 p.fsh->start ();
114 110
111 temp_1f fac;
112
113 fac = max (dot (fin.tex_coord[1], lightpos), 0.0);
114 fac = pow (fac, 3);
115 xyz(fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]); 115 xyz(fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]) * (fac + 0.3);
116 116
117 p.fsh->end (); 117 p.fsh->end ();
118 p.fsh->compile (); 118 p.fsh->compile ();
119 p.link (); 119 p.link ();
120} 120}
121 121
122void test_material::enable () 122void test_material::enable (view &ctx)
123{ 123{
124 p.enable (); 124 p.enable ();
125 lightpos->set (-ctx.d);
125 texvar->enable (); 126 texvar->enable ();
126} 127}
127 128
128void test_material::disable () 129void test_material::disable (view &ctx)
129{ 130{
130 texvar->disable (); 131 texvar->disable ();
131 p.disable (); 132 p.disable ();
132} 133}
133 134

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines