ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/material.C
(Generate patch)

Comparing cvsroot/libgender/material.C (file contents):
Revision 1.3 by root, Sun Oct 10 19:50:37 2004 UTC vs.
Revision 1.14 by root, Sat Oct 23 21:43:27 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines