Console/OpenGL.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Console.pm ↑ Summary
1  
2 # Games-Console-OpenGL - a 2D quake-style console (rendered in OpenGL)
3  
4 package Games::Console::OpenGL;
5  
6 # (C) by Tels <http://bloodgate.com/>
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Games::Console;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use vars qw/@ISA $VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 @ISA = qw/Games::Console/;
13  
14 0 ▶use SDL::OpenGL;
Subroutine BEGIN: called CC=1 SCAR=2.6
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__
« Console.pm ↑ Summary