/
intro.c
149 lines (119 loc) · 3.15 KB
/
intro.c
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
//intro.c
/******************************************************************************
* INTRO SCREEN
******************************************************************************/
#include <SDL/SDL_opengl.h>
#include "intro.h"
#include "main.h"
#include "hud.h"
#include "gl_helpers.h"
#include "ui.h"
#define ROTATION_DURATION (1000000 * 10)
#define RADIUS 100.0
#define RADIUS_OFFSET 0.1
#define CAMERA_ANGLE -75.0
#define CAMERA_DISTANCE 15.0
#define CAMERA_OFFSET 13.0 // Positivie values move image up
#define FOG_DENSITY 0.02
void draw_grid( program_state_t* PS )
{
int w = PS->window_width;
int h = PS->window_height;
microtime_t T = PS->current_time_us;
GLfloat x, y, z;
GLfloat a, r;
GLfloat camera_distance = CAMERA_DISTANCE;
GLfloat camera_rotation
= (T % ROTATION_DURATION)
/ (GLfloat)ROTATION_DURATION
* 360.0
;
GLfloat aspect = (GLfloat)w / (GLfloat)h;
glViewport( 0, 0, w, h );
glClearColor( 0.0f, 0.0f, 0.1f, 1.0f ); // Background dark blue, opaque
glClearDepth( 1.0f ); // Background depth to farthest
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// Draw the 3D scene
glMatrixMode( GL_PROJECTION ); // Setup perspective mode
glLoadIdentity();
gluPerspective(
75.0f, // fovy Field of View, y-Axis
aspect, // Aspect ratio of the screen
0.1f, // zNear
3000.0 // zFar
);
glMatrixMode( GL_MODELVIEW );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LESS );
#ifdef INTRO_USES_FOG
GLfloat fog_color[4] = { 0,0,0, 0 }; // Fog of depth
glEnable( GL_FOG );
glFogi( GL_FOG_MODE, GL_EXP2 );
glFogfv( GL_FOG_COLOR, fog_color );
glFogf( GL_FOG_DENSITY, FOG_DENSITY );
glHint( GL_FOG_HINT, GL_NICEST );
#endif
glLoadIdentity(); // Reset
glTranslatef( 0, CAMERA_OFFSET, -camera_distance );
glRotatef( CAMERA_ANGLE, 1,0,0 );
glRotatef( camera_rotation, 0,0,1 );
GLfloat start_radius = (T % 100000) / -100000.0 + 0.01;
glBegin( GL_POINTS );
glPointSize( 1 );
glColor3f( 1.0, 1.0, 1.0 );
for( a = 0.0 ; a < 360.0*DEG_TO_RAD ; a += 5.0*DEG_TO_RAD ) {
for( r = start_radius ; r < RADIUS ; r += RADIUS/100.0) {
x = cos(a) * r;
y = sin(a) * r;
z = -RADIUS / sqrt(r + RADIUS_OFFSET);
glVertex3f( x, y, z );
}
}
glEnd();
glPointSize( 1 );
#ifdef INTRO_USES_FOG
glDisable( GL_FOG );
#endif
}
void draw_overlay( program_state_t* PS )
{
int w = PS->window_width;
int h = PS->window_height;
microtime_t T = PS->current_time_us;
GLfloat R, G, B;
glViewport( 0, 0, w, h ); // Using screen coordinates
glMatrixMode( GL_PROJECTION ); // Setup 2D mode
glLoadIdentity();
gluOrtho2D( 0, w, 0, h );
glMatrixMode( GL_MODELVIEW );
glDisable( GL_DEPTH_TEST );
glLoadIdentity();
color_from_hue( (T % 6000000) / 6000000.0, &R, &G, &B );
glColor3f( R, G, B );
glLineWidth( 2 );
glBegin( GL_LINES );
glVertex2i( 0, 2*h/3 );
glVertex2i( w, 2*h/3 );
glEnd();
glLineWidth( 1 );
hud_printf( PS,
w/2,
2*h/3 + PS->line_height/2,
ALIGN_CENTER,
0xFFFFFF,
PROGRAM_NAME
);
hud_printf( PS,
w/2,
2*h/3 - 3*PS->line_height/2,
ALIGN_CENTER,
0x888888,
PROGRAM_VERSION
);
}
void draw_intro_frame( program_state_t* PS )
{
draw_grid( PS );
draw_overlay( PS );
}
//EOF