-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLUtil.cpp
164 lines (142 loc) · 3.97 KB
/
LUtil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*This piece of code was originally from Lazy Foo' Productions
(http://lazyfoo.net/)
I edited someparts
*/
#include "LUtil.h"
#include <math.h>
#include <iostream>
using namespace std;
//The current color rendering mode
int gColorMode = 1;
//The projection scale
GLfloat gProjectionScale = 1.f;
GLfloat angle=0;
bool initGL()
{
//Initialize Projection Matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0, 1.0, -1.0 );
//Initialize Modelview Matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//Initialize clear color
glClearColor( 0.f, 0.f, 0.f, 1.f );
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Check for error
GLenum error = glGetError();
if( error != GL_NO_ERROR )
{
printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
return false;
}
return true;
}
void update()
{
}
void render()
{
//Clear color buffer
glClear( GL_COLOR_BUFFER_BIT );
//Reset modelview matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//Move to center of the screen
glTranslatef( SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 0.f );
//Render quad
if( COLOR_MODE_CYAN )
{
//Solid Cyan
glBegin( GL_QUADS );
glColor3f( 0.f, 1.f, 1.f );
glVertex2f( -50.f, -50.f );
glVertex2f( 50.f, -50.f );
glVertex2f( 50.f, 50.f );
glVertex2f( -50.f, 50.f );
glEnd();
}
else
{
//RYGB Mix
//angle+=M_PI*0.015;
angle=M_PI/4;
GLfloat s = angle;
GLfloat size=50;
int blur=50;
glBegin( GL_QUADS );
//cout<<sin(s) * -50.f<<" "<<cos(s) * 50.f<<endl;
for(int i=blur;i>0;i--){
s = angle;
//glColor4f( 1.f, 1.f, 1.f,0.5f /blur );
GLfloat z=1.f/blur;
glColor4f( 1.f, 0.f, 0.f,z );
glVertex2f( sin(s)*(size+i), cos(s)*(size+i) );
s+=M_PI/2;
glColor4f( 1.f, 1.f, 0.f ,z);
glVertex2f( sin(s)*(size+i), cos(s) *(size+i));
s+=M_PI/2;
glColor4f( 0.f, 1.f, 0.f,z );
glVertex2f( sin(s) *(size+i), cos(s)*(size+i));
s+=M_PI/2;
glColor4f( 0.f, 0.f, 1.f ,z );
glVertex2f( sin(s) *(size+i),cos(s) *(size+i) );
}
s = angle;
//glColor4f( 0.f, 0.f, 0.f,1.f );
glColor3f( 1.f, 0.f, 0.f );
glVertex2f( sin(s)*size, cos(s)*size );
s+=M_PI/2;
glColor3f( 1.f, 1.f, 0.f );
glVertex2f( sin(s) * size, cos(s) *size);
s+=M_PI/2;
glColor3f( 0.f, 1.f, 0.f );
glVertex2f( sin(s) * size, cos(s)* size);
s+=M_PI/2;
glColor3f( 0.f, 0.f, 1.f );
glVertex2f( sin(s) * size,cos(s) * size );
glEnd();
}
//Update screen
glutSwapBuffers();
}
void handleKeys( unsigned char key, int x, int y )
{
//If the user presses q
if( key == 'q' )
{
//Toggle color mode
if( gColorMode == COLOR_MODE_CYAN )
{
gColorMode = COLOR_MODE_MULTI;
}
else
{
gColorMode = COLOR_MODE_CYAN;
}
}
else if( key == 'e' )
{
//Cycle through projection scales
if( gProjectionScale == 1.f )
{
//Zoom out
gProjectionScale = 2.f;
}
else if( gProjectionScale == 2.f )
{
//Zoom in
gProjectionScale = 0.5f;
}
else if( gProjectionScale == 0.5f )
{
//Regular zoom
gProjectionScale = 1.f;
}
//Update projection matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, SCREEN_WIDTH * gProjectionScale, SCREEN_HEIGHT * gProjectionScale, 0.0, 1.0, -1.0 );
}
}