home *** CD-ROM | disk | FTP | other *** search
/ ring.yamanashi.ac.jp/pub/pc/freem/action/ / action.zip / a7xpg0_11.zip / a7xpg / src / abagames / util / sdl / Texture.d < prev   
Text File  |  2003-09-20  |  1KB  |  50 lines

  1. /*
  2.  * $Id: Texture.d,v 1.1.1.1 2003/09/19 14:55:49 kenta Exp $
  3.  *
  4.  * Copyright 2003 Kenta Cho. All rights reserved.
  5.  */
  6. module abagames.util.sdl.Texture;
  7.  
  8. import 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(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.