|
15 | 15 | glutMainLoopEvent();
|
16 | 16 | });
|
17 | 17 |
|
18 |
| -gl_context(sub { # create gl context and pass drawing callback sub |
| 18 | +gl_context($stash, sub { # create gl context and pass drawing callback sub |
19 | 19 | state $sh = shader();
|
20 | 20 | glEnable(GL_TEXTURE_2D);
|
21 | 21 | $sh->Enable;
|
|
24 | 24 | glBindTexture(GL_TEXTURE_2D, $stash->{planes}->[$_]->[2]);
|
25 | 25 | glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, $stash->{planes}->[$_]->[1]);
|
26 | 26 | glPixelStorei(GL_UNPACK_ROW_LENGTH, $stash->{info}->[$_]->{stride});
|
27 |
| - glPixelStorei(GL_UNPACK_SKIP_PIXELS, $stash->{video}->{pic_x}); |
28 |
| - glPixelStorei(GL_UNPACK_SKIP_ROWS, $stash->{video}->{pic_y}); |
29 |
| - glTexImage2D_c(GL_TEXTURE_2D, 0, 1, |
30 |
| - $stash->{info}->[$_]->{width} - $stash->{video}->{pic_x}, |
31 |
| - $stash->{info}->[$_]->{height} - $stash->{video}->{pic_y}, |
32 |
| - 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0 |
33 |
| - ); |
| 27 | + glTexImage2D_c(GL_TEXTURE_2D, 0, 1, $stash->{info}->[$_]->{width}, $stash->{info}->[$_]->{height}, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0); |
34 | 28 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
35 | 29 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
36 | 30 | glUniform1iARB($sh->Map("p$_"), $_);
|
37 | 31 | } 0..2; if (my $er = glGetError()) { say $er };
|
38 |
| - glScaled(4, 4 * $stash->{video}->{pic_height} / $stash->{video}->{pic_width}, 1); |
39 |
| - glTranslatef(-0.5,-0.5,-5); |
40 |
| - glBegin(GL_QUADS); |
41 |
| - glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1); glVertex3f(0, 0, 0); |
42 |
| - glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0); glVertex3f(0, 1, 0); |
43 |
| - glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0); glVertex3f(1, 1, 0); |
44 |
| - glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1); glVertex3f(1, 0, 0); |
45 |
| - glEnd(); |
| 32 | + glCallList(state $list = do { |
| 33 | + glNewList(my $id = glGenLists(1), GL_COMPILE); |
| 34 | + glTranslatef(-0.5,-0.5,0); |
| 35 | + glBegin(GL_QUADS); |
| 36 | + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1); glVertex3f(0, 0, 0); |
| 37 | + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0); glVertex3f(0, 1, 0); |
| 38 | + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0); glVertex3f(1, 1, 0); |
| 39 | + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1); glVertex3f(1, 0, 0); |
| 40 | + glEnd(); |
| 41 | + glEndList(); |
| 42 | + $id; |
| 43 | + }); |
46 | 44 | $sh->Disable;
|
47 | 45 | glDisable(GL_TEXTURE_2D)
|
48 | 46 | });
|
|
52 | 50 | $cond->recv; # start event loop
|
53 | 51 |
|
54 | 52 | sub ogg_stream {
|
55 |
| - my $fh = IO::File->new(shift || '../t/theora.ogg', 'r') || die $!.' - provide file name to play'; |
56 |
| - my $draw_cb = shift; |
57 | 53 | my $stream = {};
|
| 54 | + my $fh = IO::File->new(($stream->{file} = shift || '../t/theora.ogg'), 'r') || die $!.' - provide file name to play'; |
| 55 | + my $draw_cb = shift; |
58 | 56 | ogg_sync_init(my $oy = make_ogg_sync_state());
|
59 | 57 | ogg_read_page($fh, $oy, my $og = make_ogg_page());
|
60 | 58 | ogg_stream_init(my $os = make_ogg_stream_state(), ogg_page_serialno($og));
|
@@ -103,28 +101,25 @@ sub ogg_stream {
|
103 | 101 | }
|
104 | 102 |
|
105 | 103 | sub gl_context { # opengl boiler plate
|
| 104 | + my $stash = shift; |
106 | 105 | my $draw_callback = shift;
|
107 | 106 | my $c = { # window config
|
108 |
| - n => 'opengl glsl theora player demo', # window name |
109 |
| - w => 800, # width |
110 |
| - h => 600, # height |
111 |
| - a => 60, # view angle |
112 |
| - np => 1, # near plane |
113 |
| - nf => 15, # far plane |
| 107 | + n => 'playing: '.$stash->{file}, # window name |
| 108 | + w => $stash->{video}->{frame_width}, # width |
| 109 | + h => $stash->{video}->{frame_height}, # height |
114 | 110 | };
|
115 |
| - |
116 | 111 | glutInit();
|
117 | 112 | glutInitWindowSize($c->{w}, $c->{h});
|
118 | 113 | glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH) - $c->{w}) / 2, (glutGet(GLUT_SCREEN_HEIGHT) - $c->{h}) / 2);
|
119 |
| - glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE); |
| 114 | + glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); |
120 | 115 | glutSetWindow(glutCreateWindow($c->{n}));
|
121 | 116 | glutSetCursor(GLUT_CURSOR_NONE);
|
122 | 117 |
|
123 | 118 | glutReshapeFunc(sub {
|
124 | 119 | glViewport(0,0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
|
125 | 120 | glMatrixMode(GL_PROJECTION);
|
126 | 121 | glLoadIdentity();
|
127 |
| - gluPerspective($c->{a}, glutGet(GLUT_WINDOW_WIDTH)/glutGet(GLUT_WINDOW_HEIGHT), $c->{np}, $c->{nf}); |
| 122 | + gluOrtho2D((-0.5, 0.5) x 2); |
128 | 123 | glMatrixMode(GL_MODELVIEW);
|
129 | 124 | });
|
130 | 125 | glutDisplayFunc(sub {
|
|
0 commit comments