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 ***************************************************************************/
29 void Sprite::glEnter2DMode()
31 glPushAttrib(GL_ALL_ATTRIB_BITS);
33 glDisable(GL_LIGHTING);
34 glDisable(GL_CULL_FACE);
35 glEnable(GL_DEPTH_TEST);
37 glEnable(GL_TEXTURE_2D);
40 /* This allows alpha blending of 2D textures with the scene */
42 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
43 // glBlendFunc(GL_SRC_ALPHA, GL_ONE);
45 glViewport(0, 0, gr->getWidth(), gr->getHeight());
47 glMatrixMode(GL_PROJECTION);
51 glOrtho(0.0, (GLdouble)gr->getWidth(), (GLdouble)gr->getHeight(), 0.0, 0.0, -2.0);
52 // gluOrtho2D(0.0, (GLdouble)gr->getWidth(), (GLdouble)gr->getHeight(), 0.0);
54 glMatrixMode(GL_MODELVIEW);
57 // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
62 void Sprite::glLeave2DMode()
64 glMatrixMode(GL_MODELVIEW);
67 glMatrixMode(GL_PROJECTION);
74 Sprite::Sprite( char * filename, colour key, int tw, int th, Graphics *g)
80 glAlphaFunc(GL_NOTEQUAL, 0);
81 glEnable(GL_ALPHA_TEST);
82 tex = new Texture(filename, key, g);
84 texW = tex->getWidth();
85 texH = tex->getHeight();
86 texWFactor = (tileWidth / (float) texW);
87 texHFactor = (tileHeight / (float) texH);
100 void Sprite::blit(int x, int y, float scalex, float scaley, int dx, int dy, colour col)
104 // glColor4ub((colour & 0x00FF0000) >> 16, (colour & 0x0000FF00) >> 8,
105 // (colour & 0x000000FF), (colour & 0xFF000000) >> 24);
106 glColor4f(col.r, col.g, col.b, col.a);
108 glBindTexture(GL_TEXTURE_2D, tex->gl_Tex);
110 glTranslatef(x,y, 0);
112 glScalef(scalex, scaley, 1);
114 glTexCoord2f(dx*texWFactor, 1 - dy*texHFactor);
115 glVertex3f(0,0, z_order);
117 glTexCoord2f(dx*texWFactor, 1 - (dy + 1)*texHFactor);
118 glVertex3f(0, tileHeight, z_order);
120 glTexCoord2f((dx + 1)*texWFactor, 1 - (dy + 1)*texHFactor);
121 glVertex3f( tileWidth, tileHeight, z_order);
123 glTexCoord2f((dx + 1)*texWFactor, 1 - dy*texHFactor);
124 glVertex3f( tileWidth, 0, z_order);