ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/material.C
Revision: 1.7
Committed: Mon Oct 18 14:55:16 2004 UTC (21 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.6: +1 -1 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.6 void
9     simple_material::begin ()
10 root 1.1 {
11 root 1.6 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 root 1.1 }
16    
17 root 1.6 void
18     simple_material::end ()
19 root 1.1 {
20     }
21 root 1.6
22     void
23     osama_material::begin ()
24 root 1.3 {
25     cgGLEnableProfile (vsh_profile);
26     cgGLEnableProfile (fsh_profile);
27 root 1.6 cgGLEnableTextureParameter (g_Texture);
28 root 1.3 }
29 root 1.6
30     void
31     osama_material::end ()
32 root 1.3 {
33 root 1.6 cgGLDisableTextureParameter (g_Texture);
34     // cgGLUnbindProgram (vsh_profile);
35     // cgGLUnbindProgram (fsh_profile);
36 root 1.3 cgGLDisableProfile (vsh_profile);
37     cgGLDisableProfile (fsh_profile);
38     }
39 root 1.1
40 root 1.6 GLuint
41     texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord)
42 root 1.3 {
43 root 1.4 GLuint textur;
44 root 1.3 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 root 1.5 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 root 1.3
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 root 1.6
68 root 1.3 if (image == NULL)
69 root 1.6 return 0;
70 root 1.3
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 root 1.6 SDL_SetAlpha (surface, 0, 0);
76 root 1.3
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 root 1.6 SDL_SetAlpha (surface, saved_flags, saved_alpha);
87 root 1.3
88     /* Create an OpenGL texture for the image */
89 root 1.4 glGenTextures (1, &textur);
90     glBindTexture (GL_TEXTURE_2D, textur);
91 root 1.6 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
92     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
93 root 1.7 glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); // GENERATE_MIPMAP_SGIS
94 root 1.3 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 root 1.4 return textur;
100 root 1.3 }
101    
102 root 1.6 CGcontext cgc;
103 root 1.3
104 root 1.6 void
105     init_shaders ()
106     {
107 root 1.3 cgc = cgCreateContext ();
108     }