ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/material.C
Revision: 1.4
Committed: Sun Oct 10 20:22:33 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.3: +6 -8 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include "opengl.h"
2     #include "material.h"
3    
4     material::~material ()
5     {
6     }
7    
8 root 1.2 void simple_material::begin ()
9 root 1.1 {
10     glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *)&diffuse);
11     glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *)&specular);
12     glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *)&emission);
13     glMaterialf (GL_FRONT, GL_SHININESS, shininess);
14     }
15    
16 root 1.2 void simple_material::end ()
17 root 1.1 {
18     }
19 root 1.3 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 root 1.4 // cgGLUnbindProgram (vsh_profile);
29     // cgGLUnbindProgram (fsh_profile);
30 root 1.3 cgGLDisableProfile (vsh_profile);
31     cgGLDisableProfile (fsh_profile);
32     }
33 root 1.1
34    
35 root 1.3 GLuint texture::load_texture (SDL_Surface *surface, GLfloat *texcoord)
36     {
37 root 1.4 GLuint textur;
38 root 1.3 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     texcoord[0] = 0.0f; /* Min X */
50     texcoord[1] = 0.0f; /* Min Y */
51     texcoord[2] = (GLfloat) surface->w / w; /* Max X */
52     texcoord[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 root 1.4 glGenTextures (1, &textur);
89     glBindTexture (GL_TEXTURE_2D, textur);
90 root 1.3 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 root 1.4 return textur;
98 root 1.3 }
99    
100    
101     CGcontext cgc;
102     void init_shaders () {
103     cgc = cgCreateContext ();
104     }