1
/***************************************************************************
2
* Copyright (C) 2006 by Frederic MARTIN *
3
* martin-frederic@users.sourceforge.net *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (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. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
22
#include <SDL/SDL_image.h>
26
CBasicTexture::CBasicTexture()
31
CBasicTexture::~CBasicTexture()
38
// Formats : BMP, PNM, XPM, LBM, PCX, GIF, JPEG, PNG, TGA.
39
bool CBasicTexture::load(const char *file, bool mipmap )
44
surface = IMG_Load(file);
48
pixel=surface->format->BitsPerPixel;
53
glGenTextures(1, &id);
54
glBindTexture(GL_TEXTURE_2D, id);
60
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
62
gluBuild2DMipmaps(GL_TEXTURE_2D,4,width, height, GL_RGBA,GL_UNSIGNED_BYTE,surface->pixels);
64
SetTexParameter(GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
65
SetTexParameter(GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
70
glTexImage2D(GL_TEXTURE_2D,0,3,width, height,0, GL_RGB,GL_UNSIGNED_BYTE,surface->pixels);
72
glTexImage2D(GL_TEXTURE_2D,0,4,width, height,0, GL_RGBA,GL_UNSIGNED_BYTE,surface->pixels);
74
SetTexParameter(GL_TEXTURE_MIN_FILTER,GL_LINEAR);
75
SetTexParameter(GL_TEXTURE_MAG_FILTER,GL_LINEAR);
78
SDL_FreeSurface(surface);
86
void CBasicTexture::bind()
88
glBindTexture ( GL_TEXTURE_2D, id);
91
void CBasicTexture::SetTexParameter (GLenum type, GLint mode)
95
glTexParameteri(GL_TEXTURE_2D,
101
void CBasicTexture::Set_Blending (GLint mode, GLfloat *env_color)
104
if (mode == GL_BLEND)
106
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, (GLfloat) mode);
107
glTexEnvfv(GL_TEXTURE_ENV,GL_TEXTURE_ENV_COLOR,(GLfloat*)env_color);
111
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, (GLfloat) mode);
115
void CBasicTexture::Set_Blending (GLint mode)
118
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, (GLfloat) mode);
121
void CBasicTexture::unload()
123
glDeleteTextures(1,&id);