Merge pull request #4314 from MartijnKaijser/beta1
[vuplus_xbmc] / xbmc / rendering / gl / GUIWindowTestPatternGL.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *      Test patterns designed by Ofer LaOr - hometheater.co.il
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "system.h"
24
25 #ifdef HAS_GL
26 #include "system_gl.h"
27 #include "GUIWindowTestPatternGL.h"
28
29 CGUIWindowTestPatternGL::CGUIWindowTestPatternGL(void) : CGUIWindowTestPattern()
30 {
31 }
32
33 CGUIWindowTestPatternGL::~CGUIWindowTestPatternGL(void)
34 {
35 }
36
37 void CGUIWindowTestPatternGL::DrawVerticalLines(int top, int left, int bottom, int right)
38 {
39   glBegin(GL_LINES);
40   glColor3f(m_white, m_white, m_white);
41   for (int i = left; i <= right; i += 2)
42   {
43     glVertex2d(i, top);
44     glVertex2d(i, bottom);
45   }
46   glEnd();
47 }
48
49 void CGUIWindowTestPatternGL::DrawHorizontalLines(int top, int left, int bottom, int right)
50 {
51   glBegin(GL_LINES);
52   glColor3f(m_white, m_white, m_white);
53   for (int i = top; i <= bottom; i += 2)
54   {
55     glVertex2d(left, i);
56     glVertex2d(right, i);
57   }
58   glEnd();
59 }
60
61 void CGUIWindowTestPatternGL::DrawCheckers(int top, int left, int bottom, int right)
62 {
63   glBegin(GL_POINTS);
64   glColor3f(m_white, m_white, m_white);
65   for (int y = top; y <= bottom; y++)
66   {
67     for (int x = left; x <= right; x += 2)
68     {
69       if (y % 2 == 0)
70         glVertex2d(x, y);
71       else
72         glVertex2d(x+1, y);
73     }
74   }
75   glEnd();
76 }
77
78 void CGUIWindowTestPatternGL::DrawBouncingRectangle(int top, int left, int bottom, int right)
79 {
80   m_bounceX += m_bounceDirectionX;
81   m_bounceY += m_bounceDirectionY;
82
83   if ((m_bounceDirectionX == 1 && m_bounceX + TEST_PATTERNS_BOUNCE_SQUARE_SIZE == right) || (m_bounceDirectionX == -1 && m_bounceX == left))
84     m_bounceDirectionX = -m_bounceDirectionX;
85
86   if ((m_bounceDirectionY == 1 && m_bounceY + TEST_PATTERNS_BOUNCE_SQUARE_SIZE == bottom) || (m_bounceDirectionY == -1 && m_bounceY == top))
87     m_bounceDirectionY = -m_bounceDirectionY;
88
89   glColor3f(m_white, m_white, m_white);
90   glRecti(m_bounceX, m_bounceY, m_bounceX + TEST_PATTERNS_BOUNCE_SQUARE_SIZE, m_bounceY + TEST_PATTERNS_BOUNCE_SQUARE_SIZE);
91 }
92
93 void CGUIWindowTestPatternGL::DrawContrastBrightnessPattern(int top, int left, int bottom, int right)
94 {
95   int x5p = (int) (left + (0.05f * (right - left)));
96   int y5p = (int) (top + (0.05f * (bottom - top)));
97   int x12p = (int) (left + (0.125f * (right - left)));
98   int y12p = (int) (top + (0.125f * (bottom - top)));
99   int x25p = (int) (left + (0.25f * (right - left)));
100   int y25p = (int) (top + (0.25f * (bottom - top)));
101   int x37p = (int) (left + (0.375f * (right - left)));
102   int y37p = (int) (top + (0.375f * (bottom - top)));
103   int x50p = left + (right - left) / 2;
104   int y50p = top + (bottom - top) / 2;
105   int x62p = (int) (left + (0.625f * (right - left)));
106   int y62p = (int) (top + (0.625f * (bottom - top)));
107   int x75p = (int) (left + (0.75f * (right - left)));
108   int y75p = (int) (top + (0.75f * (bottom - top)));
109   int x87p = (int) (left + (0.875f * (right - left)));
110   int y87p = (int) (top + (0.875f * (bottom - top)));
111   int x95p = (int) (left + (0.95f * (right - left)));
112   int y95p = (int) (top + (0.95f * (bottom - top)));
113
114   m_blinkFrame = (m_blinkFrame + 1) % TEST_PATTERNS_BLINK_CYCLE;
115
116   // draw main quadrants
117   glColor3f(m_white, m_white, m_white);
118   glRecti(x50p, top, right, y50p);
119   glRecti(left, y50p, x50p, bottom);
120
121   // draw border lines
122   glBegin(GL_LINES);
123     glColor3f(m_white, m_white, m_white);
124     glVertex2d(left, y5p);
125     glVertex2d(x50p, y5p);
126     glVertex2d(x5p, top);
127     glVertex2d(x5p, y50p);
128     glVertex2d(x50p, y95p);
129     glVertex2d(right, y95p);
130     glVertex2d(x95p, y50p);
131     glVertex2d(x95p, bottom);
132
133     glColor3f(m_black, m_black, m_black);
134     glVertex2d(x50p, y5p);
135     glVertex2d(right, y5p);
136     glVertex2d(x5p, y50p);
137     glVertex2d(x5p, bottom);
138     glVertex2d(left, y95p);
139     glVertex2d(x50p, y95p);
140     glVertex2d(x95p, top);
141     glVertex2d(x95p, y50p);
142   glEnd();
143
144   // draw inner rectangles
145   glColor3f(m_white, m_white, m_white);
146   glRecti(x12p, y12p, x37p, y37p);
147   glRecti(x62p, y62p, x87p, y87p);
148
149   glColor3f(m_black, m_black, m_black);
150   glRecti(x62p, y12p, x87p, y37p);
151   glRecti(x12p, y62p, x37p, y87p);
152
153   // draw inner circles
154   if (m_blinkFrame < TEST_PATTERNS_BLINK_CYCLE / 2)
155     glColor3f(m_black + 0.05f, m_black + 0.05f, m_black + 0.05f);
156   else
157     glColor3f(0.0f, 0.0f, 0.0f); //BTB
158   DrawCircle(x25p, y75p, (y37p - y12p) / 3);
159   DrawCircle(x75p, y25p, (y37p - y12p) / 3);
160
161   if (m_blinkFrame < TEST_PATTERNS_BLINK_CYCLE / 2)
162     glColor3f(m_white - 0.05f, m_white - 0.05f, m_white - 0.05f);
163   else
164     glColor3f(1.0f, 1.0f, 1.0f); //WTW
165   DrawCircle(x25p, y25p, (y37p - y12p) / 3);
166   DrawCircle(x75p, y75p, (y37p - y12p) / 3);
167 }
168
169 void CGUIWindowTestPatternGL::DrawCircle(int originX, int originY, int radius)
170 {
171   float angle;
172   int vectorX;
173   int vectorY;
174   int vectorY1 = originY;
175   int vectorX1 = originX;
176
177   glBegin(GL_TRIANGLES);
178   for (int i = 0; i <= 360; i++)
179   {
180     angle = (float)(((double)i)/57.29577957795135);
181     vectorX = (int) (originX + (radius*(float)sin((double)angle)));
182     vectorY = (int) (originY + (radius*(float)cos((double)angle)));
183     glVertex2d(originX, originY);
184     glVertex2d(vectorX1, vectorY1);
185     glVertex2d(vectorX, vectorY);
186     vectorY1 = vectorY;
187     vectorX1 = vectorX;
188   }
189   glEnd();
190 }
191
192 void CGUIWindowTestPatternGL::BeginRender()
193 {
194   glDisable(GL_TEXTURE_2D);
195   glDisable(GL_BLEND);
196   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
197 }
198
199 void CGUIWindowTestPatternGL::EndRender()
200 {
201   glEnable(GL_TEXTURE_2D);
202 }
203
204 #endif