1 /***************************************************************************
2 * Copyright (C) 2005 by Dimitris Saougos & Filippos Papadopoulos *
3 * <psybases@gmail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 2 of the *
8 * 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. *
15 * You should have received a copy of the GNU Library General Public *
16 * License 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 ***************************************************************************/
28 void Sprite::glEnter2DMode()
30 glPushAttrib(GL_ALL_ATTRIB_BITS);
32 glDisable(GL_LIGHTING);
33 glDisable(GL_CULL_FACE);
34 glEnable(GL_DEPTH_TEST);
36 glEnable(GL_TEXTURE_2D);
39 /* This allows alpha blending of 2D textures with the scene */
41 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
42 // glBlendFunc(GL_SRC_ALPHA, GL_ONE);
44 glViewport(0, 0, this->g->getWidth(), this->g->getHeight());
46 glMatrixMode(GL_PROJECTION);
50 glOrtho(0.0, (GLdouble)this->g->getWidth(), (GLdouble)this->g->getHeight(), 0.0, 0.0, -2.0);
51 // gluOrtho2D(0.0, (GLdouble)this->g->getWidth(), (GLdouble)this->g->getHeight(), 0.0);
53 glMatrixMode(GL_MODELVIEW);
56 // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
61 void Sprite::glLeave2DMode()
63 glMatrixMode(GL_MODELVIEW);
66 glMatrixMode(GL_PROJECTION);
73 Sprite::Sprite( char * filename, colour key, int tw, int th, Graphics *g)
79 glAlphaFunc(GL_NOTEQUAL, 0);
80 glEnable(GL_ALPHA_TEST);
81 tex = new Texture(filename, key, g);
83 texW = tex->getWidth();
84 texH = tex->getHeight();
85 texWFactor = (tileWidth / (float) texW);
86 texHFactor = (tileHeight / (float) texH);
99 void Sprite::blit(int x, int y, float scalex, float scaley, int dx, int dy, colour col)
103 // glColor4ub((colour & 0x00FF0000) >> 16, (colour & 0x0000FF00) >> 8,
104 // (colour & 0x000000FF), (colour & 0xFF000000) >> 24);
105 glColor4f(col.r, col.g, col.b, col.a);
107 glBindTexture(GL_TEXTURE_2D, tex->gl_Tex);
109 glTranslatef(x,y, 0);
111 glScalef(scalex, scaley, 1);
113 glTexCoord2f(dx*texWFactor, 1 - dy*texHFactor);
114 glVertex3f(0,0, z_order);
116 glTexCoord2f(dx*texWFactor, 1 - (dy + 1)*texHFactor);
117 glVertex3f(0, tileHeight, z_order);
119 glTexCoord2f((dx + 1)*texWFactor, 1 - (dy + 1)*texHFactor);
120 glVertex3f( tileWidth, tileHeight, z_order);
122 glTexCoord2f((dx + 1)*texWFactor, 1 - dy*texHFactor);
123 glVertex3f( tileWidth, 0, z_order);