… | |
… | |
10 | material::~material () |
10 | material::~material () |
11 | { |
11 | { |
12 | } |
12 | } |
13 | |
13 | |
14 | void |
14 | void |
15 | simple_material::begin () |
15 | simple_material::enable () |
16 | { |
16 | { |
17 | glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *) & diffuse); |
17 | glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *) & diffuse); |
18 | glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *) & specular); |
18 | glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *) & specular); |
19 | glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *) & emission); |
19 | glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *) & emission); |
20 | glMaterialf (GL_FRONT, GL_SHININESS, shininess); |
20 | glMaterialf (GL_FRONT, GL_SHININESS, shininess); |
21 | } |
21 | } |
22 | |
22 | |
23 | void |
23 | void |
24 | simple_material::end () |
24 | simple_material::disable () |
25 | { |
25 | { |
26 | } |
|
|
27 | |
|
|
28 | void |
|
|
29 | osama_material::begin () |
|
|
30 | { |
|
|
31 | cgGLEnableProfile (vsh_profile); |
|
|
32 | cgGLEnableProfile (fsh_profile); |
|
|
33 | cgGLEnableTextureParameter (g_Texture); |
|
|
34 | } |
|
|
35 | |
|
|
36 | void |
|
|
37 | osama_material::end () |
|
|
38 | { |
|
|
39 | cgGLDisableTextureParameter (g_Texture); |
|
|
40 | // cgGLUnbindProgram (vsh_profile); |
|
|
41 | // cgGLUnbindProgram (fsh_profile); |
|
|
42 | cgGLDisableProfile (vsh_profile); |
|
|
43 | cgGLDisableProfile (fsh_profile); |
|
|
44 | } |
26 | } |
45 | |
27 | |
46 | GLuint |
28 | GLuint |
47 | texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) |
29 | texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) |
48 | { |
30 | { |
49 | GLuint textur; |
31 | GLuint name; |
50 | int w, h; |
32 | int w, h; |
51 | SDL_Surface *image; |
33 | SDL_Surface *image; |
52 | SDL_Rect area; |
34 | SDL_Rect area; |
53 | Uint32 saved_flags; |
35 | Uint32 saved_flags; |
54 | Uint8 saved_alpha; |
36 | Uint8 saved_alpha; |
… | |
… | |
90 | /* Restore the alpha blending attributes */ |
72 | /* Restore the alpha blending attributes */ |
91 | if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
73 | if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
92 | SDL_SetAlpha (surface, saved_flags, saved_alpha); |
74 | SDL_SetAlpha (surface, saved_flags, saved_alpha); |
93 | |
75 | |
94 | /* Create an OpenGL texture for the image */ |
76 | /* Create an OpenGL texture for the image */ |
95 | glGenTextures (1, &textur); |
77 | glGenTextures (1, &name); |
96 | glBindTexture (GL_TEXTURE_2D, textur); |
78 | glBindTexture (GL_TEXTURE_2D, name); |
97 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
79 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
98 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
80 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
99 | glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); // GENERATE_MIPMAP_SGIS |
81 | glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); |
100 | glTexImage2D (GL_TEXTURE_2D, |
82 | glTexImage2D (GL_TEXTURE_2D, |
101 | 0, |
83 | 0, |
102 | GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); |
84 | GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); |
103 | SDL_FreeSurface (image); /* No longer needed */ |
85 | SDL_FreeSurface (image); /* No longer needed */ |
104 | |
86 | |
105 | return textur; |
87 | return name; |
106 | } |
88 | } |
107 | |
89 | |
108 | CGcontext cgc; |
90 | test_material::test_material () |
|
|
91 | : tex ("textures/osama.jpg"), texvar (tex.name) |
|
|
92 | { |
|
|
93 | using namespace shader; |
109 | |
94 | |
110 | void |
95 | p.vsh->start (); |
111 | init_shaders () |
96 | |
112 | { |
97 | temp_4f lightpos; |
113 | cgc = cgCreateContext (); |
98 | temp_4f wpos; |
|
|
99 | |
|
|
100 | //lightpos = shader::vec4 (0, 10, 0, 1); |
|
|
101 | vout.position = shader::gl.model_view_projection_matrix * vin.vertex; |
|
|
102 | vout.tex_coord[0] = vin.tex_coord[0]; |
|
|
103 | //vout.tex_coord[1] = normalize (lightpos - wpos); |
|
|
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 | |
|
|
108 | p.vsh->end (); |
|
|
109 | p.vsh->compile (); |
|
|
110 | |
|
|
111 | fragment_shader fsh; |
|
|
112 | |
|
|
113 | p.fsh->start (); |
|
|
114 | |
|
|
115 | xyz(fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]); |
|
|
116 | |
|
|
117 | p.fsh->end (); |
|
|
118 | p.fsh->compile (); |
|
|
119 | p.link (); |
114 | } |
120 | } |
115 | |
121 | |
|
|
122 | void test_material::enable () |
|
|
123 | { |
|
|
124 | p.enable (); |
|
|
125 | texvar->enable (); |
|
|
126 | } |
|
|
127 | |
|
|
128 | void test_material::disable () |
|
|
129 | { |
|
|
130 | texvar->disable (); |
|
|
131 | p.disable (); |
|
|
132 | } |
|
|
133 | |