3 Copyright (C) 2001-2003 Paolo Martella
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
18 Texture::Texture() {tID
=0;}
19 Texture::~Texture(){Kill();}
20 bool Texture::Create(char* FileName
)
23 glGenTextures(1, &tID
);
24 tID
++; // Use an offset of +1 to differentiate from non-initialized state.
25 glBindTexture(GL_TEXTURE_2D
, tID
-1);
26 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_WRAP_S
, GL_REPEAT
);
27 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_WRAP_T
, GL_REPEAT
);
28 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
29 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
38 glDeleteTextures(1, &tID
);
42 GLuint
pow2(GLuint exp
)
45 if (!exp
) return result
;
46 for (GLuint a
=0; a
<exp
; a
++)
54 glBindTexture(GL_TEXTURE_2D
,tID
-1);
56 bool Texture::Load(char* Opaque
)
58 if(Opaque
==0) return false;
59 if (!Create(Opaque
)) return false;
63 fhandle
=fopen(Opaque
,"rb");
64 if (!fhandle
) return false;
66 fread(&ww
,sizeof(char),1,fhandle
);
68 fread(&hh
,sizeof(char),1,fhandle
);
71 rgbdata
=new char[size
];
72 GLuint read
=fread(rgbdata
,sizeof(char),size
,fhandle
);
73 if (read
!=size
) return false;
75 gluBuild2DMipmaps(GL_TEXTURE_2D
,3,w
,h
,GL_RGB
,GL_UNSIGNED_BYTE
,rgbdata
);