… | |
… | |
3 | |
3 | |
4 | material::~material () |
4 | material::~material () |
5 | { |
5 | { |
6 | } |
6 | } |
7 | |
7 | |
|
|
8 | void |
8 | void simple_material::begin () |
9 | simple_material::begin () |
9 | { |
10 | { |
10 | glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *)&diffuse); |
11 | glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *) & diffuse); |
11 | glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *)&specular); |
12 | glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *) & specular); |
12 | glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *)&emission); |
13 | glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *) & emission); |
13 | glMaterialf (GL_FRONT, GL_SHININESS, shininess); |
14 | glMaterialf (GL_FRONT, GL_SHININESS, shininess); |
14 | } |
15 | } |
15 | |
16 | |
|
|
17 | void |
16 | void simple_material::end () |
18 | simple_material::end () |
17 | { |
19 | { |
18 | } |
20 | } |
|
|
21 | |
|
|
22 | void |
19 | void osama_material::begin () |
23 | osama_material::begin () |
20 | { |
24 | { |
21 | cgGLEnableProfile (vsh_profile); |
25 | cgGLEnableProfile (vsh_profile); |
22 | cgGLEnableProfile (fsh_profile); |
26 | cgGLEnableProfile (fsh_profile); |
23 | cgGLEnableTextureParameter(g_Texture); |
27 | cgGLEnableTextureParameter (g_Texture); |
24 | } |
28 | } |
|
|
29 | |
|
|
30 | void |
25 | void osama_material::end () |
31 | osama_material::end () |
26 | { |
32 | { |
27 | cgGLDisableTextureParameter(g_Texture); |
33 | cgGLDisableTextureParameter (g_Texture); |
28 | // cgGLUnbindProgram (vsh_profile); |
34 | // cgGLUnbindProgram (vsh_profile); |
29 | // cgGLUnbindProgram (fsh_profile); |
35 | // cgGLUnbindProgram (fsh_profile); |
30 | cgGLDisableProfile (vsh_profile); |
36 | cgGLDisableProfile (vsh_profile); |
31 | cgGLDisableProfile (fsh_profile); |
37 | cgGLDisableProfile (fsh_profile); |
32 | } |
38 | } |
33 | |
39 | |
34 | |
40 | GLuint |
35 | GLuint texture::load_texture (SDL_Surface *surface, GLfloat *tex2oord) |
41 | texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) |
36 | { |
42 | { |
37 | GLuint textur; |
43 | GLuint textur; |
38 | int w, h; |
44 | int w, h; |
39 | SDL_Surface *image; |
45 | SDL_Surface *image; |
40 | SDL_Rect area; |
46 | SDL_Rect area; |
… | |
… | |
56 | 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 |
62 | 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 |
57 | #else |
63 | #else |
58 | 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF |
64 | 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF |
59 | #endif |
65 | #endif |
60 | ); |
66 | ); |
|
|
67 | |
61 | if (image == NULL) |
68 | if (image == NULL) |
62 | { |
|
|
63 | return 0; |
69 | return 0; |
64 | } |
|
|
65 | |
70 | |
66 | /* Save the alpha blending attributes */ |
71 | /* Save the alpha blending attributes */ |
67 | saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); |
72 | saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); |
68 | saved_alpha = surface->format->alpha; |
73 | saved_alpha = surface->format->alpha; |
69 | if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
74 | if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
70 | { |
|
|
71 | SDL_SetAlpha (surface, 0, 0); |
75 | SDL_SetAlpha (surface, 0, 0); |
72 | } |
|
|
73 | |
76 | |
74 | /* Copy the surface into the GL texture image */ |
77 | /* Copy the surface into the GL texture image */ |
75 | area.x = 0; |
78 | area.x = 0; |
76 | area.y = 0; |
79 | area.y = 0; |
77 | area.w = surface->w; |
80 | area.w = surface->w; |
78 | area.h = surface->h; |
81 | area.h = surface->h; |
79 | SDL_BlitSurface (surface, &area, image, &area); |
82 | SDL_BlitSurface (surface, &area, image, &area); |
80 | |
83 | |
81 | /* Restore the alpha blending attributes */ |
84 | /* Restore the alpha blending attributes */ |
82 | if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
85 | if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
83 | { |
|
|
84 | SDL_SetAlpha (surface, saved_flags, saved_alpha); |
86 | SDL_SetAlpha (surface, saved_flags, saved_alpha); |
85 | } |
|
|
86 | |
87 | |
87 | /* Create an OpenGL texture for the image */ |
88 | /* Create an OpenGL texture for the image */ |
88 | glGenTextures (1, &textur); |
89 | glGenTextures (1, &textur); |
89 | glBindTexture (GL_TEXTURE_2D, textur); |
90 | glBindTexture (GL_TEXTURE_2D, textur); |
90 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
91 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
91 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
92 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
|
|
93 | glTexParameteri (GL_TEXTURE_2D, 0x8191, GL_TRUE); // GENERATE_MIPMAP_SGIS |
92 | glTexImage2D (GL_TEXTURE_2D, |
94 | glTexImage2D (GL_TEXTURE_2D, |
93 | 0, |
95 | 0, |
94 | GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); |
96 | GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); |
95 | SDL_FreeSurface (image); /* No longer needed */ |
97 | SDL_FreeSurface (image); /* No longer needed */ |
96 | |
98 | |
97 | return textur; |
99 | return textur; |
98 | } |
100 | } |
99 | |
101 | |
|
|
102 | CGcontext cgc; |
100 | |
103 | |
101 | CGcontext cgc; |
104 | void |
102 | void init_shaders () { |
105 | init_shaders () |
|
|
106 | { |
103 | cgc = cgCreateContext (); |
107 | cgc = cgCreateContext (); |
104 | } |
108 | } |