line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# Games-Console-OpenGL - a 2D quake-style console (rendered in OpenGL) |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Games::Console::OpenGL; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# (C) by Tels |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
19853
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
368
|
use Games::Console; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw/@ISA $VERSION/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
12
|
|
|
|
|
|
|
@ISA = qw/Games::Console/; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
427
|
use SDL::OpenGL; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = '0.01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _render |
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
# prepare the output, render the background and the text |
21
|
|
|
|
|
|
|
my ($self,$x,$y,$w,$h,$time) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# select our background texture |
24
|
|
|
|
|
|
|
# glBindTexture( GL_TEXTURE_2D, $self->{texture} ); |
25
|
|
|
|
|
|
|
glDisable( GL_TEXTURE_2D ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Disable/Enable flags, unless they are already in the right state |
28
|
|
|
|
|
|
|
glDisable( GL_DEPTH_TEST ); |
29
|
|
|
|
|
|
|
glDepthMask(GL_FALSE); # disable writing to depth buffer |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
glEnable( GL_BLEND ); |
32
|
|
|
|
|
|
|
# select type of blending |
33
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Select The Projection Matrix |
36
|
|
|
|
|
|
|
glMatrixMode( GL_PROJECTION ); |
37
|
|
|
|
|
|
|
# Store The Projection Matrix |
38
|
|
|
|
|
|
|
glPushMatrix(); |
39
|
|
|
|
|
|
|
# Reset The Projection Matrix |
40
|
|
|
|
|
|
|
glLoadIdentity(); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Set Up An Ortho Screen |
43
|
|
|
|
|
|
|
# left, right, bottom, top, near, far |
44
|
|
|
|
|
|
|
glOrtho( 0, $self->{screen_width}, 0, $self->{screen_height}, -1, 1 ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Select The Modelview Matrix |
47
|
|
|
|
|
|
|
glMatrixMode( GL_MODELVIEW ); |
48
|
|
|
|
|
|
|
# Store the Modelview Matrix |
49
|
|
|
|
|
|
|
glPushMatrix(); |
50
|
|
|
|
|
|
|
# Reset The Modelview Matrix |
51
|
|
|
|
|
|
|
glLoadIdentity(); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
############################################################################ |
54
|
|
|
|
|
|
|
# draw background |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
glColor (@{$self->{background_color}}, $self->{background_alpha}); |
57
|
|
|
|
|
|
|
glBegin( GL_QUADS ); |
58
|
|
|
|
|
|
|
glVertex( $x, $y-$h ); |
59
|
|
|
|
|
|
|
glVertex( $x+$w, $y-$h ); |
60
|
|
|
|
|
|
|
glVertex( $x+$w, $y ); |
61
|
|
|
|
|
|
|
glVertex( $x, $y ); |
62
|
|
|
|
|
|
|
glEnd; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# draw messages |
65
|
|
|
|
|
|
|
my $font = $self->{font}; |
66
|
|
|
|
|
|
|
$font->pre_output(); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $line_height = $self->{font}->char_height() + $self->{spacing_y}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $output_y = ($y - $h + $self->{border_y}); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$font->color( $self->{text_color} ); |
73
|
|
|
|
|
|
|
$font->alpha( $self->{text_alpha} ); |
74
|
|
|
|
|
|
|
if ($output_y > -$line_height) |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
# do we need to draw the cursor? (50% of the time draw it, 50% not) |
77
|
|
|
|
|
|
|
my $cursor = ''; |
78
|
|
|
|
|
|
|
if ($time - $self->{last_cursor} > $self->{cursor_time}) |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
$cursor = $self->{cursor}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
if ($time - $self->{last_cursor} > 2 * $self->{cursor_time}) |
83
|
|
|
|
|
|
|
{ |
84
|
|
|
|
|
|
|
# This isn't necc. correct, but nobody will notice... |
85
|
|
|
|
|
|
|
$self->{last_cursor} = $time; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
$font->output ($x + $self->{border_x}, $output_y, |
88
|
|
|
|
|
|
|
$self->{prompt} . $self->{current_input} . $cursor); |
89
|
|
|
|
|
|
|
$output_y += $line_height; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
foreach my $msg (reverse @{$self->{messages}}) |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
last if $output_y < -$line_height; |
94
|
|
|
|
|
|
|
# draw the messages from the bottom to the top |
95
|
|
|
|
|
|
|
$font->output ($x + $self->{border_x}, $output_y, $msg->[0] ); |
96
|
|
|
|
|
|
|
$output_y += $line_height; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$font->post_output(); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
############################################################################ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Select The Projection Matrix |
104
|
|
|
|
|
|
|
glMatrixMode( GL_PROJECTION ); |
105
|
|
|
|
|
|
|
# Restore The Old Projection Matrix |
106
|
|
|
|
|
|
|
glPopMatrix(); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Select the Modelview Matrix |
109
|
|
|
|
|
|
|
glMatrixMode( GL_MODELVIEW ); |
110
|
|
|
|
|
|
|
# Restore the Old Projection Matrix |
111
|
|
|
|
|
|
|
glPopMatrix(); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |