home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 August / GSSH0804.iso / Action / Parsec47 / Parsec47.exe / p47 / src / abagames / util / sdl / Texture.d < prev   
Text File  |  2003-11-29  |  1KB  |  50 lines

  1. /*
  2.  * $Id: Texture.d,v 1.1.1.1 2003/11/28 17:26:30 kenta Exp $
  3.  *
  4.  * Copyright 2003 Kenta Cho. All rights reserved.
  5.  */
  6. module abagames.util.sdl.Texture;
  7.  
  8. import std.string;
  9. import opengl;
  10. import SDL;
  11. import abagames.util.sdl.SDLInitFailedException;
  12.  
  13. /**
  14.  * Manage OpenGL textures;
  15.  */
  16. public class Texture {
  17.  public:
  18.   static char[] imagesDir = "images/";
  19.  
  20.  private:
  21.   GLuint num;
  22.  
  23.   public this(char[] name) {
  24.     char[] fileName = imagesDir ~ name;
  25.     SDL_Surface *surface;    
  26.     surface = SDL_LoadBMP(std.string.toStringz(fileName));
  27.     if (!surface) {
  28.       throw new SDLInitFailedException("Unable to load: " ~ fileName);
  29.     }
  30.     glGenTextures(1, &num);
  31.     glBindTexture(GL_TEXTURE_2D, num);
  32.     glTexImage2D(GL_TEXTURE_2D, 0, 3, surface.w, surface.h, 0,
  33.          GL_RGB, GL_UNSIGNED_BYTE, surface.pixels);
  34.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  35.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  36.     /*gluBuild2DMipmaps(GL_TEXTURE_2D, 3, surface.w, surface.h, 
  37.       GL_RGB, GL_UNSIGNED_BYTE, surface.pixels);
  38.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
  39.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*/
  40.   }
  41.  
  42.   public void deleteTexture() {
  43.     glDeleteTextures(1, &num);
  44.   }
  45.  
  46.   public void bind() {
  47.     glBindTexture(GL_TEXTURE_2D, num);
  48.   }
  49. }
  50.