home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 August / GSSH0804.iso / Action / TumikiFighters / tf0_2.exe / tf / src / abagames / util / sdl / texture.d < prev   
Text File  |  2004-05-15  |  1KB  |  50 lines

  1. /*
  2.  * $Id: texture.d,v 1.2 2004/05/14 14:35:39 kenta Exp $
  3.  *
  4.  * Copyright 2003 Kenta Cho. All rights reserved.
  5.  */
  6. module abagames.util.sdl.texture;
  7.  
  8. private import std.string;
  9. private import opengl;
  10. private import SDL;
  11. private import abagames.util.sdl.sdlexception;
  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.