1 /*
2 Copyright (C) 2007, 2010 - Bit-Blot
3
4 This file is part of Aquaria.
5
6 Aquaria is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 #include "Gradient.h"
22 #include "Core.h"
23
Gradient()24 Gradient::Gradient() : RenderObject()
25 {
26 autoWidth = autoHeight = 0;
27 }
28
onUpdate(float dt)29 void Gradient::onUpdate(float dt)
30 {
31 RenderObject::onUpdate(dt);
32
33 if (autoWidth == AUTO_VIRTUALWIDTH)
34 {
35 scale.x = core->getVirtualWidth();
36 }
37
38 if (autoHeight == AUTO_VIRTUALHEIGHT)
39 {
40 scale.y = core->getVirtualWidth();
41 }
42 }
43
makeVertical(Vector c1,Vector c2)44 void Gradient::makeVertical(Vector c1, Vector c2)
45 {
46 ulc0 = c1;
47 ulc1 = c1;
48 ulc2 = c2;
49 ulc3 = c2;
50 }
51
makeHorizontal(Vector c1,Vector c2)52 void Gradient::makeHorizontal(Vector c1, Vector c2)
53 {
54 ulc0 = c1;
55 ulc1 = c2;
56 ulc2 = c2;
57 ulc3 = c1;
58 }
59
onRender()60 void Gradient::onRender()
61 {
62 #ifdef BBGE_BUILD_DIRECTX
63 core->blitD3DGradient
64 ( ulc0.getD3DColor(alpha.x),
65 ulc1.getD3DColor(alpha.x),
66 ulc2.getD3DColor(alpha.x),
67 ulc3.getD3DColor(alpha.x));
68 #endif
69 #ifdef BBGE_BUILD_OPENGL
70 //glNormal3f(0, 0, 1);
71
72 glBegin(GL_QUADS);
73 //glNormal3f(0, 0, 1);
74
75 glColor4f(ulc2.x*color.x, ulc2.y*color.y, ulc2.z*color.z, alpha.x);
76 glVertex3f(-0.5, 0.5, 0.0f);
77
78 // 2
79 glColor4f(ulc3.x*color.x, ulc3.y*color.y, ulc3.z*color.z, alpha.x);
80 glVertex3f( 0.5, 0.5, 0.0f);
81
82 // 3
83 glColor4f(ulc0.x*color.x, ulc0.y*color.y, ulc0.z*color.z, alpha.x);
84 glVertex3f( 0.5, -0.5, 0.0f);
85
86 // 4
87 glColor4f(ulc1.x*color.x, ulc1.y*color.y, ulc1.z*color.z, alpha.x);
88 glVertex3f(-0.5, -0.5, 0.0f);
89 /*
90 glColor3f(ulc0.x, ulc0.y, ulc0.z);
91 glVertex3f(-0.5, -0.5, 0);
92
93 glColor3f(ulc1.x, ulc1.y, ulc1.z);
94 glVertex3f(0.5, -0.5, 0);
95
96 glColor3f(ulc2.x, ulc2.y, ulc2.z);
97 glVertex3f(0.5, 0.5, 0);
98
99 glColor3f(ulc3.x, ulc3.y, ulc3.z);
100 glVertex3f(-0.5, 0.5, 0);
101 */
102 glEnd();
103 #endif
104 }
105
106