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