1 /*
2  * Image.cpp
3  * Copyright (C) 2007 by Bryan Duff <duff0097@gmail.com>
4  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20 #include "Image.h"
21 #include "Config.h"
22 
23 extern Config config;
24 
Image()25 Image::Image()
26 {
27   index = 0;
28   color = Color(1.0, 1.0, 1.0, 1.0);
29 }
30 
setDim(GLfloat _xpos,GLfloat _ypos,GLfloat _xwidth,GLfloat _yheight)31 void Image::setDim(GLfloat _xpos, GLfloat _ypos, GLfloat _xwidth,
32                    GLfloat _yheight)
33 {
34   xpos = _xpos;
35   ypos = _ypos;
36   xwidth = _xwidth;
37   yheight = _yheight;
38 }
39 
setImage(GLuint _texture,unsigned int index)40 void Image::setImage(GLuint _texture, unsigned int index)
41 {
42   if(index < NUM_TEXTURES) {
43     texture[index] = _texture;
44   }
45 }
46 
setActive(unsigned int _index)47 void Image::setActive(unsigned int _index)
48 {
49   if(_index < NUM_TEXTURES) {
50     index = _index;
51   }
52 }
53 
setColor(Color _color)54 void Image::setColor(Color _color)
55 {
56   color = _color;
57 }
58 
update(float _sinefluct,float _sinefluctprog)59 void Image::update(float _sinefluct, float _sinefluctprog)
60 {
61   sinefluct = _sinefluct;
62   sinefluctprog = _sinefluctprog;
63 }
64 
draw()65 void Image::draw()              // Where The Printing Happens
66 {
67   float width = config.screenwidth;
68   float height = config.screenheight;
69 
70   GLint x = (int)(xpos * width);
71   GLint y = (int)(ypos * height);
72   GLint xw = (int)(xwidth * width);
73   GLint yh = (int)(yheight * height);
74 
75   glDisable(GL_TEXTURE_2D);
76   glDisable(GL_DEPTH_TEST);     // Disables Depth Testing
77   glDisable(GL_CULL_FACE);
78   glDisable(GL_LIGHTING);
79 
80   glBlendFunc(GL_SRC_ALPHA, GL_ONE);
81 
82   glDepthMask(0);
83 
84   glMatrixMode(GL_PROJECTION);  // Select The Projection Matrix
85 
86   glPushMatrix();               // Store The Projection Matrix
87 
88   glLoadIdentity();             // Reset The Projection Matrix
89 
90   glOrtho(0, width, 0, height, -100, 100);      // Set Up An Ortho Screen
91 
92   glMatrixMode(GL_MODELVIEW);   // Select The Modelview Matrix
93 
94   //Draw smoke
95   glPushMatrix();               // Store The Modelview Matrix
96   glLoadIdentity();             // Reset The Modelview Matrix
97 
98   glTranslatef(x + sinefluct * 40, y - sinefluct * 9, 0);
99   //glTranslatef(x - sinefluct * 40, y + sinefluct * 9, 0);
100   glScalef(xw - sinefluct * 80, yh + sinefluct * 18, 1);
101   //glScalef(xw + sinefluct * 80, yh - sinefluct * 18, 1);
102 
103   glTranslatef(.5, .5, 0);
104   glScalef(.5, .5, 1);
105 
106   glRotatef(sinefluctprog * 50, 0, 0, 1);
107 
108   glEnable(GL_TEXTURE_2D);
109 
110   glBindTexture(GL_TEXTURE_2D, texture[index]);
111 
112   glEnable(GL_BLEND);
113 
114   glColor4f(color.r, color.g, color.b, .4 + sinefluct / 8);
115   //flame images (for "New" and "Quit")
116   //glColor4f(color.r, color.g, color.b, .5 +/- sinefluct / 6);
117 
118   glBegin(GL_TRIANGLES);
119   glTexCoord2f(1.0f, 1.0f);
120   glVertex3f(1, 1, 0.0f);
121   glTexCoord2f(0.0f, 1.0f);
122   glVertex3f(-1, 1, 0.0f);
123   glTexCoord2f(1.0f, 0.0f);
124   glVertex3f(1, -1, 0.0f);
125   glTexCoord2f(0.0f, 0.0f);
126   glVertex3f(-1, -1, 0.0f);
127   glTexCoord2f(1.0f, 0.0f);
128   glVertex3f(1, -1, 0.0f);
129   glTexCoord2f(0.0f, 1.0f);
130   glVertex3f(-1, 1, 0.0f);
131   glEnd();
132 
133   glMatrixMode(GL_MODELVIEW);   // Select The Modelview Matrix
134 
135   glPopMatrix();
136 
137   glMatrixMode(GL_PROJECTION);  // Select The Projection Matrix
138 
139   glPopMatrix();                // Restore The Old Projection Matrix
140 
141   glDepthMask(1);
142 }
143