~ubuntu-branches/ubuntu/edgy/pouetchess/edgy-updates

« back to all changes in this revision

Viewing changes to src/utils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc (mr_pouit)
  • Date: 2006-07-15 15:45:57 UTC
  • Revision ID: james.westby@ubuntu.com-20060715154557-3paxq02hx4od0wm4
Tags: upstream-0.2.0
ImportĀ upstreamĀ versionĀ 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2006 by Frederic MARTIN                                 *
 
3
 *   martin-frederic@users.sourceforge.net                                 *
 
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                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "utils.h"
 
22
 
 
23
/**************************************************************************************/
 
24
void go_2D()
 
25
{
 
26
        glMatrixMode(GL_PROJECTION);
 
27
        glPushMatrix();
 
28
        glLoadIdentity();
 
29
        glOrtho( 0.0f, 1024.0f, 768.0f, 0.0f, 0.0f, 1.0f );
 
30
        glMatrixMode(GL_MODELVIEW);
 
31
        glPushMatrix();
 
32
        glLoadIdentity();
 
33
        glDisable(GL_LIGHTING);
 
34
}
 
35
 
 
36
 
 
37
/**************************************************************************************/
 
38
void exit_2D()
 
39
{
 
40
        glMatrixMode(GL_PROJECTION);
 
41
        glPopMatrix();
 
42
        glMatrixMode(GL_MODELVIEW);
 
43
        glPopMatrix();
 
44
        glEnable(GL_LIGHTING);
 
45
}
 
46
 
 
47
 
 
48
/**************************************************************************************/
 
49
void draw_rectangle(int X, int Y,int width,int height)
 
50
{
 
51
        glBegin(GL_LINE_LOOP);
 
52
                glVertex2i(X, Y);
 
53
                glVertex2i(X, Y+height);
 
54
                glVertex2i(X+width,Y+height);
 
55
                glVertex2i(X+width,Y);
 
56
                glVertex2i(X, Y);
 
57
        glEnd();
 
58
}
 
59
 
 
60
/**************************************************************************************/
 
61
void draw_rectangle_2(int x1, int y1,int x2,int y2)
 
62
{
 
63
        glBegin(GL_LINE_LOOP);
 
64
                glVertex2i(x1, y1);
 
65
                glVertex2i(x1, y2);
 
66
                glVertex2i(x2, y2);
 
67
                glVertex2i(x2, y1);
 
68
                glVertex2i(x1, y1);
 
69
        glEnd();
 
70
}
 
71
 
 
72
/**************************************************************************************/
 
73
void draw_filled_rectangle(int x1, int y1,int x2,int y2)
 
74
{
 
75
        glBegin(GL_QUADS);
 
76
                glVertex2i(x1, y1);
 
77
                glVertex2i(x1, y2);
 
78
                glVertex2i(x2, y2);
 
79
                glVertex2i(x2, y1);
 
80
        glEnd();
 
81
}
 
82
 
 
83
 
 
84
/**************************************************************************************/
 
85
void draw_image(int X, int Y,int width,int height,CBasicTexture* image)
 
86
{
 
87
        glEnable(GL_TEXTURE_2D);
 
88
        image->bind();
 
89
        
 
90
        glBegin(GL_QUADS);
 
91
                glTexCoord2f(0.0f, 0.0f);               glVertex2i(X, Y);
 
92
                glTexCoord2f(0.0f, 1.0f);               glVertex2i(X, Y+height);
 
93
                glTexCoord2f(1.0f, 1.0f);               glVertex2i(X+width,Y+height);
 
94
                glTexCoord2f(1.0f, 0.0f);               glVertex2i(X+width,Y);
 
95
        glEnd();
 
96
        
 
97
        glDisable(GL_TEXTURE_2D);
 
98
}
 
99
 
 
100
 
 
101
 
 
102
/**************************************************************************************/
 
103
void clearScreen()
 
104
{
 
105
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
106
        SDL_GL_SwapBuffers();
 
107
}
 
108
 
 
109
 
 
110
 
 
111
/**************************************************************************************/
 
112
/**************************************************************************************/
 
113
GLfloat alpha_fade;
 
114
 
 
115
 
 
116
void init_fade_in()
 
117
{
 
118
        alpha_fade=0.0f;
 
119
}
 
120
 
 
121
void init_fade_out()
 
122
{
 
123
        alpha_fade=1.0f;
 
124
}
 
125
 
 
126
 
 
127
/**************************************************************************************/
 
128
bool gl_fade_in(GLfloat speed)
 
129
{
 
130
        if (alpha_fade<1.0f)
 
131
                alpha_fade+=speed;
 
132
        else
 
133
        {
 
134
                alpha_fade=0.0f;
 
135
                return false;
 
136
        }
 
137
        
 
138
        glColor4f(0.0f,0.0f,0.0f,alpha_fade);
 
139
        
 
140
        glBegin(GL_QUADS);
 
141
                glVertex2i(0, 0);
 
142
                glVertex2i(0, 768);
 
143
                glVertex2i(1024, 768);
 
144
                glVertex2i(1024, 0);
 
145
        glEnd();
 
146
        
 
147
        return true;
 
148
}
 
149
 
 
150
 
 
151
/**************************************************************************************/
 
152
bool gl_fade_out(GLfloat speed)
 
153
{
 
154
        if (alpha_fade>0.0f)
 
155
                alpha_fade-=speed;
 
156
        else
 
157
        {
 
158
                alpha_fade=0.0f;
 
159
                return false;
 
160
        }
 
161
        
 
162
        glColor4f(0.0f,0.0f,0.0f,alpha_fade);
 
163
        
 
164
        glBegin(GL_QUADS);
 
165
                glVertex2i(0, 0);
 
166
                glVertex2i(0, 768);
 
167
                glVertex2i(1024, 768);
 
168
                glVertex2i(1024, 0);
 
169
        glEnd();
 
170
        
 
171
        return true;    
 
172
}
 
173
 
 
174
/**************************************************************************************/
 
175
/**************************************************************************************/
 
176