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.2 by root, Sun Oct 10 14:18:58 2004 UTC vs.
Revision 1.5 by root, Sat Oct 16 23:23:21 2004 UTC

14} 14}
15 15
16void simple_material::end () 16void simple_material::end ()
17{ 17{
18} 18}
19void osama_material::begin ()
20{
21 cgGLEnableProfile (vsh_profile);
22 cgGLEnableProfile (fsh_profile);
23 cgGLEnableTextureParameter(g_Texture);
24}
25void osama_material::end ()
26{
27 cgGLDisableTextureParameter(g_Texture);
28 // cgGLUnbindProgram (vsh_profile);
29 // cgGLUnbindProgram (fsh_profile);
30 cgGLDisableProfile (vsh_profile);
31 cgGLDisableProfile (fsh_profile);
32}
19 33
20 34
35GLuint texture::load_texture (SDL_Surface *surface, GLfloat *tex2oord)
36{
37 GLuint textur;
38 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 tex2oord[0] = 0.0f; /* Min X */
50 tex2oord[1] = 0.0f; /* Min Y */
51 tex2oord[2] = (GLfloat) surface->w / w; /* Max X */
52 tex2oord[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 glGenTextures (1, &textur);
89 glBindTexture (GL_TEXTURE_2D, textur);
90 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 return textur;
98}
99
100
101CGcontext cgc;
102void init_shaders () {
103 cgc = cgCreateContext ();
104}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines