ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/material.C
Revision: 1.6
Committed: Mon Oct 18 14:31:36 2004 UTC (19 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.5: +31 -27 lines
Log Message:
*** empty log message ***

File Contents

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