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

Comparing libgender/util.C (file contents):
Revision 1.27 by root, Sun Oct 10 14:15:15 2004 UTC vs.
Revision 1.28 by root, Sun Oct 10 19:50:37 2004 UTC

221 struct timeval tv; 221 struct timeval tv;
222 gettimeofday (&tv, 0); 222 gettimeofday (&tv, 0);
223 base = tv.tv_sec + tv.tv_usec / 1.e6; 223 base = tv.tv_sec + tv.tv_usec / 1.e6;
224} 224}
225 225
226GLuint SDL_GL_LoadTexture (SDL_Surface * surface, GLfloat * texcoord)
227{
228 GLuint texture;
229 int w, h;
230 SDL_Surface *image;
231 SDL_Rect area;
232 Uint32 saved_flags;
233 Uint8 saved_alpha;
234
235 /* Use the surface width and height expanded to powers of 2 */
236 //w = power_of_two (surface->w);
237 //h = power_of_two (surface->h);
238 w = power_of_two (surface->w);
239 h = power_of_two (surface->h);
240 texcoord[0] = 0.0f; /* Min X */
241 texcoord[1] = 0.0f; /* Min Y */
242 texcoord[2] = (GLfloat) surface->w / w; /* Max X */
243 texcoord[3] = (GLfloat) surface->h / h; /* Max Y */
244
245 image = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32,
246#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
247 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
248#else
249 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
250#endif
251 );
252 if (image == NULL)
253 {
254 return 0;
255 }
256
257 /* Save the alpha blending attributes */
258 saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
259 saved_alpha = surface->format->alpha;
260 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
261 {
262 SDL_SetAlpha (surface, 0, 0);
263 }
264
265 /* Copy the surface into the GL texture image */
266 area.x = 0;
267 area.y = 0;
268 area.w = surface->w;
269 area.h = surface->h;
270 SDL_BlitSurface (surface, &area, image, &area);
271
272 /* Restore the alpha blending attributes */
273 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
274 {
275 SDL_SetAlpha (surface, saved_flags, saved_alpha);
276 }
277
278 /* Create an OpenGL texture for the image */
279 glGenTextures (1, &texture);
280 glBindTexture (GL_TEXTURE_2D, texture);
281 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
282 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
283 glTexImage2D (GL_TEXTURE_2D,
284 0,
285 GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
286 SDL_FreeSurface (image); /* No longer needed */
287
288 return texture;
289}
290
291void render_text (GLint x, GLint y, const char *str) 226void render_text (GLint x, GLint y, const char *str)
292{ 227{
293 glRasterPos2i (x, y); 228 glRasterPos2i (x, y);
294 229
295 while (!*str) 230 while (!*str)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines