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.4 by root, Sun Oct 10 20:22:33 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 cgGLEnableTextureParameter(g_Texture); 33 cgGLEnableTextureParameter (g_Texture);
24} 34}
35
36void
25void osama_material::end () 37osama_material::end ()
26{ 38{
27 cgGLDisableTextureParameter(g_Texture); 39 cgGLDisableTextureParameter (g_Texture);
28 // cgGLUnbindProgram (vsh_profile); 40 // cgGLUnbindProgram (vsh_profile);
29 // cgGLUnbindProgram (fsh_profile); 41 // cgGLUnbindProgram (fsh_profile);
30 cgGLDisableProfile (vsh_profile); 42 cgGLDisableProfile (vsh_profile);
31 cgGLDisableProfile (fsh_profile); 43 cgGLDisableProfile (fsh_profile);
32} 44}
33 45
34 46GLuint
35GLuint texture::load_texture (SDL_Surface *surface, GLfloat *texcoord) 47texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord)
36{ 48{
37 GLuint textur; 49 GLuint textur;
38 int w, h; 50 int w, h;
39 SDL_Surface *image; 51 SDL_Surface *image;
40 SDL_Rect area; 52 SDL_Rect area;
44 /* Use the surface width and height expanded to powers of 2 */ 56 /* Use the surface width and height expanded to powers of 2 */
45 //w = power_of_two (surface->w); 57 //w = power_of_two (surface->w);
46 //h = power_of_two (surface->h); 58 //h = power_of_two (surface->h);
47 w = power_of_two (surface->w); 59 w = power_of_two (surface->w);
48 h = power_of_two (surface->h); 60 h = power_of_two (surface->h);
49 texcoord[0] = 0.0f; /* Min X */ 61 tex2oord[0] = 0.0f; /* Min X */
50 texcoord[1] = 0.0f; /* Min Y */ 62 tex2oord[1] = 0.0f; /* Min Y */
51 texcoord[2] = (GLfloat) surface->w / w; /* Max X */ 63 tex2oord[2] = (GLfloat) surface->w / w; /* Max X */
52 texcoord[3] = (GLfloat) surface->h / h; /* Max Y */ 64 tex2oord[3] = (GLfloat) surface->h / h; /* Max Y */
53 65
54 image = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32, 66 image = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32,
55#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 67#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
56 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 68 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
57#else 69#else
58 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF 70 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
59#endif 71#endif
60 ); 72 );
73
61 if (image == NULL) 74 if (image == NULL)
62 {
63 return 0; 75 return 0;
64 }
65 76
66 /* Save the alpha blending attributes */ 77 /* Save the alpha blending attributes */
67 saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); 78 saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
68 saved_alpha = surface->format->alpha; 79 saved_alpha = surface->format->alpha;
69 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) 80 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
70 {
71 SDL_SetAlpha (surface, 0, 0); 81 SDL_SetAlpha (surface, 0, 0);
72 }
73 82
74 /* Copy the surface into the GL texture image */ 83 /* Copy the surface into the GL texture image */
75 area.x = 0; 84 area.x = 0;
76 area.y = 0; 85 area.y = 0;
77 area.w = surface->w; 86 area.w = surface->w;
78 area.h = surface->h; 87 area.h = surface->h;
79 SDL_BlitSurface (surface, &area, image, &area); 88 SDL_BlitSurface (surface, &area, image, &area);
80 89
81 /* Restore the alpha blending attributes */ 90 /* Restore the alpha blending attributes */
82 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) 91 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
83 {
84 SDL_SetAlpha (surface, saved_flags, saved_alpha); 92 SDL_SetAlpha (surface, saved_flags, saved_alpha);
85 }
86 93
87 /* Create an OpenGL texture for the image */ 94 /* Create an OpenGL texture for the image */
88 glGenTextures (1, &textur); 95 glGenTextures (1, &textur);
89 glBindTexture (GL_TEXTURE_2D, textur); 96 glBindTexture (GL_TEXTURE_2D, textur);
90 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 97 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
91 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
92 glTexImage2D (GL_TEXTURE_2D, 100 glTexImage2D (GL_TEXTURE_2D,
93 0, 101 0,
94 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);
95 SDL_FreeSurface (image); /* No longer needed */ 103 SDL_FreeSurface (image); /* No longer needed */
96 104
97 return textur; 105 return textur;
98} 106}
99 107
108CGcontext cgc;
100 109
101CGcontext cgc; 110void
102void init_shaders () { 111init_shaders ()
112{
103 cgc = cgCreateContext (); 113 cgc = cgCreateContext ();
104} 114}
115

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines