-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing16.html
executable file
·1160 lines (978 loc) · 40.9 KB
/
listing16.html
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>OpenGLMovieQT - /OpenGL Movie.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/LegacyTechnologies/index.html">Legacy Documents</a> > <a href="../../samplecode/LegacyTechnologies/idxQuickTime-date.html">QuickTime</a> > <A HREF="javascript:location.replace('index.html');">OpenGLMovieQT</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<div style="width:100%; position:fixed;"><div align="center" id="watermark" style="position: relative; margin-left:auto; margin-right:auto; z-index:20; width:500px;"><div class="legacybox"><h1>Legacy Document<span class=closebutton><a href="javascript:closeWatermark()"><img src="../../images/closebutton.png" width="14" height="14" border="0" alt="close button"></a></span></h1>
<p><strong>Important: </strong>This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.</p>
<div class="reflibtopic">
<p>Current information on this Reference Library topic can be found here:</p>
<ul>
<li><a href="http://developer.apple.com/referencelibrary/QuickTime/idxGraphicsImaging-date.html" target="_blank">QuickTime > Graphics & Imaging</a></li>
</ul>
</div>
</div></div></div>
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">OpenGLMovieQT</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/OpenGL Movie.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/Carbon Include.h</option>
<option value="listing2.html">/Carbon Resource.r</option>
<option value="listing3.html">/Carbon SetupGL/aglString/aglString.c</option>
<option value="listing4.html">/Carbon SetupGL/aglString/aglString.h</option>
<option value="listing5.html">/Carbon SetupGL/Carbon_Error_Handler.c</option>
<option value="listing6.html">/Carbon SetupGL/Carbon_Error_Handler.h</option>
<option value="listing7.html">/Carbon SetupGL/Carbon_Include.h</option>
<option value="listing8.html">/Carbon SetupGL/Carbon_Resource.r</option>
<option value="listing9.html">/Carbon SetupGL/Carbon_SetupDSp.c</option>
<option value="listing10.html">/Carbon SetupGL/Carbon_SetupDSp.h</option>
<option value="listing11.html">/Carbon SetupGL/Carbon_SetupGL.c</option>
<option value="listing12.html">/Carbon SetupGL/Carbon_SetupGL.h</option>
<option value="listing13.html">/Carbon SetupGL/Carbon_SetupGL_Test.c</option>
<option value="listing14.html">/OpenGL Movie Controls.c</option>
<option value="listing15.html">/OpenGL Movie Main.c</option>
<option value="listing16.html">/OpenGL Movie.c</option>
<option value="listing17.html">/OpenGLMovie.h</option></select>
</p>
</form>
<p><strong><a href="OpenGLMovieQT.zip">Download Sample</a></strong> (“OpenGLMovieQT.zip”, 139.4K)<BR>
<strong><a href="OpenGLMovieQT.dmg">Download Sample</a></strong> (“OpenGLMovieQT.dmg”, 197.4K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/*
File: OpenGLMovie.c
Contains: OpenGL Movie demo
Copyright: 2000 Apple Computer, Inc., All Rights Reserved
Change History (most recent first):
<6+> 2/24/01 ggs fix window return for full screen
<6> 12/5/00 ggs Fixed unused variables
<5> 12/4/00 ggs Fixed some Carbon and mac OS X things
<4> 11/25/00 ggs fixed non-Carbon parts and added comments
<3> 11/25/00 ggs Split controls
<2> 11/25/00 ggs Completed options and dialog)
<1> 10/29/00 ggs Name change
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __APPLE_CC__
#include "Carbon Include.h"
#include <Carbon/Carbon.h>
#include <AGL/agl.h>
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#include <AGL/aglRenderers.h>
#else
#include <FixMath.h>
#include <Fonts.h>
#include <Gestalt.h>
#include <Navigation.h>
#include <sound.h>
#include <DrawSprocket.h>
#include <gl.h>
#include <glext.h>
#include <glm.h>
#include <agl.h>
#include <aglRenderers.h>
#endif
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "Carbon_SetupGL.h"
#include "AGLString.h"
#include "OpenGLMovie.h"
//-----------------------------------------------------------------------------------------------------------------------
struct structMovieSettings gMovieSettings = {640, 480, 256, 16, false, true, true, true, true};
// GL texturing
GLubyte * gpTexture; // texture storage (used on for set up when direct texturing
short gUsedTextureHeight = 0, gUsedTextureWidth = 0;
float gfTextureScale = (float) 1.0;
short gvTextureOffset = 0, gvTextureEnd = 0, ghTextureOffset = 0, ghTextureEnd = 0;
// Movie
Rect gMovieRect = {0, 0, 0, 0};
short gMovieWidth = 100, gMovieHeight = 75;
Movie gMovie = NULL;
TimeValue gMovieDuration = 0L;
// Movie off screen
GWorldPtr gpOffscreen = NULL;
PixMapHandle ghPixMap = NULL;
unsigned char * gpBaseAddr = NULL;
unsigned long gRowStride = 0;
MovieDrawingCompleteUPP gMovieDrawUPP;
Boolean gfMovieDraw = false;
// GL stuff
Boolean gfHasPackedPixels = false;
structGLInfo glInfo;
structGLWindowInfo glWInfo;
AGLDrawable gaglDraw = NULL;
Rect grectWin;
AGLContext gaglContext = 0;
DSpContextReference gdspContext = 0;
GLuint gFontList = 0;
char gInfoString [512] = "";
//-----------------------------------------------------------------------------------------------------------------------
OSErr QTPlayMovieFrameAtTime (Movie theMovie, TimeValue atTime);
void SetPlaybackInfoString (void);
void InitializeQTEnvironment (void);
pascal OSErr MovieDrawProc (Movie movie, long refcon);
OSErr InitializeMovie (void);
void InitGL (short width, short height);
void SetFrustum (short width, short height, float focalLen, float minDepth, float maxDepth);
void MoveFrame (float * outx, float * outy, float * outz, float time);
void SwizzleMovieToTexture (void);
void DrawGL(Rect * pRect);
#pragma mark -
//-----------------------------------------------------------------------------------------------------------------------
// QTPlayMovieFrameAtTime - sets movie to time and updates
OSErr QTPlayMovieFrameAtTime (Movie theMovie, TimeValue atTime)
{
OSErr anErr = noErr;
if (NULL == theMovie)
return paramErr;
if (atTime == 0L)
{
GoToBeginningOfMovie (theMovie);
anErr = GetMoviesError ();
}
else
{
if (atTime > gMovieDuration)
SetMovieTimeValue (theMovie, gMovieDuration);
else
SetMovieTimeValue (theMovie, atTime);
anErr = GetMoviesError ();
}
if (noErr == anErr)
anErr = UpdateMovie (theMovie);
if (noErr == anErr)
{
MoviesTask (theMovie, 0L);
anErr = GetMoviesError ();
}
return anErr;
}
#pragma mark -
//-----------------------------------------------------------------------------------------------------------------------
// UseWaitNextEvent - accessor function to determine whether user wants to use WNE
Boolean UseWaitNextEvent (void)
{
return gMovieSettings.fUseWaitNextEvent;
}
//-----------------------------------------------------------------------------------------------------------------------
// IsFullScreen - are we in full screen mode
Boolean IsFullScreen (void)
{
return gMovieSettings.fFullScreen;
}
//-----------------------------------------------------------------------------------------------------------------------
// ProcessFullScreenEvent - handle DrawSprocket events call safe for full screen and non-full screen
Boolean ProcessFullScreenEvent (EventRecord * pEvent)
{
Boolean fProcessed = false;
if (IsFullScreen ())
DSpProcessEvent (pEvent, &fProcessed);
return (fProcessed);
}
#pragma mark -
//-----------------------------------------------------------------------------------------------------------------------
// SetPlaybackInfoString - Set playback info string based on user selected options
void SetPlaybackInfoString (void)
{
char strTemp [512];
short texDepth;
if (!gMovieSettings.fTryPackedPixel || !gfHasPackedPixels)
texDepth = 24;
else
texDepth = gMovieSettings.wOffScreenDepth;
sprintf (gInfoString, "Win: %dx%d, Tex: %dx%dx%d (Update: %dx%d)", gMovieSettings.wWindowWidth, gMovieSettings.wWindowHeight,
gMovieSettings.wTextureSize, gMovieSettings.wTextureSize, texDepth, gUsedTextureWidth, gUsedTextureHeight);
if (gMovieSettings.fTryPackedPixel && gfHasPackedPixels)
{
sprintf (strTemp, "%s, Packed Pix", gInfoString);
sprintf (gInfoString, "%s", strTemp);
}
if (gMovieSettings.fTryPackedPixel && gfHasPackedPixels && !gMovieSettings.fDirectTexturing)
{
sprintf (strTemp, "%s, glmCopy", gInfoString);
sprintf (gInfoString, "%s", strTemp);
}
if (gMovieSettings.fVBLSync)
{
sprintf (strTemp, "%s, VSync", gInfoString);
sprintf (gInfoString, "%s", strTemp);
}
if (gMovieSettings.fUseFog)
{
sprintf (strTemp, "%s, Fog", gInfoString);
sprintf (gInfoString, "%s", strTemp);
}
if (gMovieSettings.fUseWaitNextEvent)
{
sprintf (strTemp, "%s, WNE", gInfoString);
sprintf (gInfoString, "%s", strTemp);
}
}
//-----------------------------------------------------------------------------------------------------------------------
// SetupGLMovie - setup GL, set up GL texturing, set up QT playback into off screen
// returns a CGrafPtr (aglDrawable) that is the drawable, for fullscreen we may not own the window
// associated with the drawable, for non-fullscreen we will
OSStatus SetupGLMovie (void)
{
Rect rectWin;
// OSErr anErr = noErr;
// OSType mediaType = VideoMediaType;
GDHandle origDevice;
CGrafPtr origPort;
short i = 0, deviceNum = -1;
MatrixRecord movieMatrix;
Rect rectNewMovie;
// Boolean done = false;
InitializeQTEnvironment();
if ( InitializeMovie() != noErr ) ExitToShell(); // we had problems with the movie.
if (!gMovie)
ExitToShell();
GetGWorld (&origPort, &origDevice); // save onscreen graphics port
// Build GL context and window --------------------------
if (gMovieSettings.fFullScreen)
{
// we want a context and a drawable
deviceNum = -1;
glInfo.width = gMovieSettings.wWindowWidth; // width of drawable (screen width in full screen mode)
glInfo.height = gMovieSettings.wWindowHeight; // height of drawable (screen height in full screen mode)
glInfo.fSizeMust = true; // dspContext must be requested height (ignored in window mode)
// Note: This basically determines whether or not displays will step down to allocate or fail
glInfo.pixelDepth = gMovieSettings.wOffScreenDepth;// requested pixel depth
glInfo.fDepthMust = true; // pixel depth must be set (if false then curretn depth will be used if able)
glInfo.fFullscreen = true; // use DSp to get fullscreen?
glInfo.fAcceleratedMust = true; // must renderer be accelerated?
glInfo.VRAM = 0 * 1000000; // minimum VRAM
glInfo.freq = 0; // desired vertical refresh frquency in Hz (0 = any)
glInfo.fmt = 0; // output pixel format
glInfo.aglAttributes [i++] = AGL_RGBA;
glInfo.aglAttributes [i++] = AGL_ALL_RENDERERS;
glInfo.aglAttributes [i++] = AGL_DOUBLEBUFFER;
glInfo.aglAttributes [i++] = AGL_NO_RECOVERY; // should be used whenever packed pixels is used to disable software back up textures
glInfo.aglAttributes [i++] = AGL_NONE;
if (noErr != BuildGL (&gaglDraw, &gaglContext, &gdspContext, &deviceNum, &glInfo, NULL))
return paramErr;
if (!gaglContext)
return paramErr;
SetRect (&rectWin, (short) 0, (short) 0, (short) glInfo.width, (short) glInfo.height); // l t r b
HideCursor ();
}
else
{
SetRect (&rectWin, (short) 50, (short) 50, (short) (gMovieSettings.wWindowWidth + 50), (short) (gMovieSettings.wWindowHeight + 50)); // l t r b
#if TARGET_API_MAC_CARBON
gaglDraw = GetWindowPort (NewCWindow (NULL, &rectWin, "\pOpenGL Movie", false, kWindowFullZoomGrowDocumentProc, (WindowPtr)-1, true, 0));
ShowWindow (GetWindowFromPort (gaglDraw));
#else
gaglDraw = (CGrafPtr) NewCWindow (NULL, &rectWin, "\pOpenGL Movie", false, kWindowFullZoomGrowDocumentProc, (WindowPtr)-1, true, 0);
ShowWindow ((WindowPtr) gaglDraw);
#endif
glWInfo.fAcceleratedMust = true; // must renderer be accelerated?
glWInfo.VRAM = 0 * 1048576; // minimum VRAM (if not zero this is always required)
glWInfo.textureRAM = 0 * 1048576; // minimum texture RAM (if not zero this is always required)
glWInfo.fDraggable = false; // desired vertical refresh frquency in Hz (0 = any)
glWInfo.fmt = 0; // output pixel format
i = 0;
glWInfo.aglAttributes [i++] = AGL_RGBA;
glWInfo.aglAttributes [i++] = AGL_DOUBLEBUFFER;
glWInfo.aglAttributes [i++] = AGL_ACCELERATED;
glWInfo.aglAttributes [i++] = AGL_NO_RECOVERY; // should be used whenever packed pixels is used to disable software back up textures
glWInfo.aglAttributes [i++] = AGL_NONE;
BuildGLFromWindow (GetWindowFromPort (gaglDraw), &gaglContext, &glWInfo, NULL);
if (!gaglContext)
return paramErr;
}
if (gaglDraw)
SetPort ((GrafPtr)gaglDraw);
// font handling
{
short fNum;
GetFNum("\pMonaco", &fNum); // build font
gFontList = BuildFontGL (gaglContext, fNum, normal, 9);
}
// Setup OpenGL for movie texturing ---------------------
InitGL (rectWin.right - rectWin.left, rectWin.bottom - rectWin.top);
grectWin = rectWin;
// Setup texturing and movie scaling -------------------
gMovieWidth = (short) (gMovieRect.right - gMovieRect.left);
gMovieHeight = (short) (gMovieRect.bottom - gMovieRect.top);
if (gMovieSettings.wTextureSize == 0) // set to power of two larger than movie
{
short shift = 0;
long value;
if (gMovieWidth > gMovieHeight)
value = gMovieWidth;
else
value = gMovieHeight;
while (value)
{
value = value >> 1;
shift++;
}
value = 1;
while (shift)
{
value = value << 1;
shift--;
}
gMovieSettings.wTextureSize = (short) value;
}
gvTextureOffset = 0; gvTextureEnd = gMovieHeight; ghTextureOffset = 0; ghTextureEnd = gMovieWidth;
if (gMovieWidth > gMovieHeight)
{
gfTextureScale = (float) gMovieWidth / (float) (gMovieSettings.wTextureSize);
gUsedTextureHeight = (short) (gMovieHeight / gfTextureScale);
gUsedTextureWidth = (short) (gMovieWidth / gfTextureScale);
gvTextureOffset = (short) ((gMovieSettings.wTextureSize - gUsedTextureHeight) / 2);
ghTextureOffset = 0;
}
else // harder case needs to be inset left and right
{
gfTextureScale = (float) gMovieHeight / (float) gMovieSettings.wTextureSize;
gUsedTextureHeight = (short) (gMovieHeight / gfTextureScale);
gUsedTextureWidth = (short) (gMovieWidth / gfTextureScale);
ghTextureOffset = (short) ((gMovieSettings.wTextureSize - gUsedTextureWidth) / 2);
gvTextureOffset = 0;
}
gvTextureEnd = (short) (gUsedTextureHeight + gvTextureOffset);
ghTextureEnd = (short) (gUsedTextureWidth + ghTextureOffset);
// Setup QuickTimemovie playback -----------------------
SetIdentityMatrix (&movieMatrix);
ScaleMatrix (&movieMatrix, X2Fix ( 1.0 / gfTextureScale), X2Fix (1.0 / gfTextureScale), X2Fix (0.0), X2Fix (0.0));
SetMovieMatrix (gMovie, &movieMatrix);
SetRect (&rectNewMovie, 0, 0, gUsedTextureWidth, gUsedTextureHeight); // l,t, r, b
// force 32 bit offscreen if no packed pixel
if (!gMovieSettings.fTryPackedPixel || !gfHasPackedPixels)
gMovieSettings.wOffScreenDepth = 32;
gRowStride = gUsedTextureWidth * gMovieSettings.wOffScreenDepth / 8;
gpBaseAddr = (unsigned char *) NewPtrClear (gRowStride * gUsedTextureHeight);
if (gMovieSettings.wOffScreenDepth == 32)
QTNewGWorldFromPtr (&gpOffscreen, k32ARGBPixelFormat, &rectNewMovie, NULL, NULL, 0, gpBaseAddr, gRowStride);
else
QTNewGWorldFromPtr (&gpOffscreen, k16BE555PixelFormat, &rectNewMovie, NULL, NULL, 0, gpBaseAddr, gRowStride);
if (NULL == gpOffscreen)
{
DebugStr ("\pCould not allocate off screen");
ExitToShell ();
}
SetGWorld(gpOffscreen, NULL); // set current graphics port to offscreen
SetMovieGWorld(gMovie, (CGrafPtr)gpOffscreen, NULL);
ghPixMap = GetGWorldPixMap (gpOffscreen);
if (ghPixMap)
{
if (LockPixels (ghPixMap)) // lock offscreen pixel map
{
gpBaseAddr = (unsigned char *) GetPixBaseAddr (ghPixMap);//(**ghPixMap).baseAddr; // find base addr and stride
gRowStride = (unsigned long) GetPixRowBytes (ghPixMap); //(**ghPixMap).rowBytes & 0x3FFF;
}
else
{
DebugStr ("\pCould not lock PixMap");
ExitToShell ();
}
}
else
{
DebugStr ("\pCould not GetGWorldPixMap");
ExitToShell ();
}
SetGWorld(origPort, origDevice); // set current graphics port to offscreen
QTPlayMovieFrameAtTime (gMovie, 0L);
SetPlaybackInfoString ();
return noErr;
}
//-----------------------------------------------------------------------------------------------------------------------
// CleanupGLMovie - dump QT offscreen, texture storage, GL and window
void CleanupGLMovie (void)
{
// how to dispose QTGWorldFromPtr correctly?
DisposeGWorld (gpOffscreen);
//DisposePtr ((Ptr) gpBaseAddr); // dump gworld image area
DisposePtr ((Ptr) gpTexture); // dump texture memory
DeleteFontGL (gFontList);
if (gMovieSettings.fFullScreen)
{
DestroyGL (&gaglDraw, &gaglContext, &gdspContext, &glInfo);
ShowCursor ();
}
else
{
DestroyGLFromWindow (&gaglContext, &glWInfo);
if (gaglDraw)
#if TARGET_API_MAC_CARBON
DisposeWindow (GetWindowFromPort (gaglDraw));
#else
DisposeWindow ((WindowPtr) gaglDraw);
#endif
gaglDraw = NULL;
}
DisposeMovieDrawingCompleteUPP (gMovieDrawUPP);
}
//-----------------------------------------------------------------------------------------------------------------------
pascal OSErr MovieDrawProc (Movie movie, long refcon)
{
#pragma unused (movie, refcon)
gfMovieDraw = true;
return noErr;
}
//-----------------------------------------------------------------------------------------------------------------------
// InitializeMovie - Initialize needed movie parts for the offscreen handling.
OSErr InitializeMovie(void)
{
OSErr anErr = OpenMovie (&gMovie);
GetMovieBox(gMovie, &gMovieRect);
OffsetRect(&gMovieRect, -gMovieRect.left, -gMovieRect.top);
SetMovieBox(gMovie, &gMovieRect);
gMovieDuration = GetMovieDuration(gMovie);
gMovieDrawUPP = NewMovieDrawingCompleteUPP (MovieDrawProc);
SetMovieDrawingCompleteProc (gMovie, movieDrawingCallWhenChanged, gMovieDrawUPP,0);
return anErr;
}
//-----------------------------------------------------------------------------------------------------------------------
// InitializeQTEnvironment - check for at least AT 4.0 and activate QT
void InitializeQTEnvironment(void)
{
OSErr anErr = noErr;
long qtVersion = 0L;
if(noErr != Gestalt (gestaltQuickTime, &qtVersion))
{
DebugStr ("\pThe QuickTime extension is not present in this system");
ExitToShell();
}
if( (qtVersion >> 16 ) < 0x400 )
{
DebugStr ("\pWe need QT 4.0 or higher due to APIs used in this sample, consult the sources (exit).");
ExitToShell();
}
anErr = EnterMovies();
if(anErr != noErr)
{
DebugStr ("\pProblems with Entermovies, returning errors (exit)");
ExitToShell();
}
}
//-----------------------------------------------------------------------------------------------------------------------
// SuspendFullScreenGLMovie - suspends full screen for background switch
OSStatus SuspendFullScreenGLMovie (void)
{
return SuspendFullScreenGL (gaglDraw, gaglContext);
ShowCursor ();
}
//-----------------------------------------------------------------------------------------------------------------------
// ResumeFullScreenGLMovie - resumes full screen after background switch
OSStatus ResumeFullScreenGLMovie (void)
{
HideCursor ();
return ResumeFullScreenGL (gaglDraw, gaglContext);
}
//-----------------------------------------------------------------------------------------------------------------------
// ResumeGLMovie - resumes after background switch
OSStatus ResumeGLMovie (void)
{
return ResumeGL (gaglContext);
// resume QuickTime
SetMovieRate (gMovie, X2Fix (1.0));
}
//-----------------------------------------------------------------------------------------------------------------------
// ResumeGLMovie - resumes after background switch
OSStatus SuspendGLMovie (void)
{
// pause QuickTime
SetMovieRate (gMovie, X2Fix (0.0));
return PauseGL (gaglContext);
}
//-----------------------------------------------------------------------------------------------------------------------
// UpdateGLMovieForGrow - handles GL updates for growing windows
void UpdateGLMovieForGrow (short width, short height)
{
gMovieSettings.wWindowWidth = width;
gMovieSettings.wWindowHeight = height;
SetPlaybackInfoString ();
if (!IsFullScreen ())
aglUpdateContext (gaglContext); // can't call with aglSetFullScreen
glViewport (0, 0, width, height);
SetFrustum (width, height, 2.0, 1.0, 100.0);
}
//-----------------------------------------------------------------------------------------------------------------------
// SetFrustum - sets up view frustrum to maintain movie aspect ratio
void SetFrustum (short width, short height, float focalLen, float minDepth, float maxDepth)
{
float heightOverWidth = (float) height / (float) width; // 0.75 intially;
float f = minDepth / focalLen;
float h = heightOverWidth * f;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-f, f, -h, h, minDepth, maxDepth);
}
//-----------------------------------------------------------------------------------------------------------------------
// InitGL - checks for packed pixel support, sets up GL for texturing (with or without packed pixel support) and fog if needed
void InitGL (short width, short height)
{
GLfloat rFog[4] = {0.0, 0.0, 0.0, 1.0};
long sizeTexture;
// set up GL params
UpdateGLMovieForGrow (width, height);
glEnable(GL_TEXTURE_2D);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if (gMovieSettings.fUseFog)
{
rFog[0] = 0.8; rFog[1] = 0.9; rFog[2] = 0.9; rFog[3] = 1.0;
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, 1.0);
glFogf(GL_FOG_END, 6.5);
glFogfv(GL_FOG_COLOR, rFog);
glHint(GL_FOG_HINT, GL_NICEST);
}
glClearColor(rFog[0], rFog[1], rFog[2], rFog[3]);
if (gMovieSettings.fVBLSync)
{
GLint swapInt = 1;
aglSetInteger (gaglContext, AGL_SWAP_INTERVAL, &swapInt);
}
// packed pixel extension check
if (gMovieSettings.fTryPackedPixel)
{
// get version string
const GLubyte * strVersion = glGetString (GL_VERSION);
// get extension string
const GLubyte * strExtension = glGetString (GL_EXTENSIONS);
if (strstr ((const char *) strVersion, "1.2") || strstr ((const char *) strExtension, "GL_APPLE_packed_pixel"))
gfHasPackedPixels = true;
else
gfHasPackedPixels = false;
}
// allocated texture buffer must be allocated for all cases
if (!gMovieSettings.fTryPackedPixel || !gfHasPackedPixels)
// allocate RGB 888 texture buffer
sizeTexture = 3 * gMovieSettings.wTextureSize * gMovieSettings.wTextureSize; // size of texture in bytes
else
//allocate 32 or 16 bit buffer
sizeTexture = gMovieSettings.wOffScreenDepth / 8 * gMovieSettings.wTextureSize * gMovieSettings.wTextureSize; // size of texture in bytes
gpTexture = (GLubyte *) NewPtrClear (sizeTexture);
if (!gpTexture)
ExitToShell ();
if (gMovieSettings.fUseFog) // clear buffer to fog color
{
long i, j;
short stepSize;
long pixValue;
if (!gMovieSettings.fTryPackedPixel || !gfHasPackedPixels)
{
pixValue = ((((long)(rFog[0] * 255)) << 16) & 0x00FF0000) + ((((long)(rFog[1] * 255)) << 8) & 0x0000FF00) + ((((long)(rFog[2] * 255))) & 0x000000FF);
stepSize = 3;
}
else if (gMovieSettings.wOffScreenDepth == 32)
{
pixValue = ((((long)(rFog[0] * 255)) << 16) & 0x00FF0000) + ((((long)(rFog[1] * 255)) << 8) & 0x0000FF00) + ((((long)(rFog[2] * 255))) & 0x000000FF);
stepSize = 4;
}
else
{
pixValue = ((((long)(rFog[0] * 255)) << 7) & 0x00007C00) + ((((long)(rFog[1] * 255)) << 2) & 0x000003E0) + ((((long)(rFog[2] * 255)) >> 3) & 0x0000001F);
stepSize = 2;
}
for (i = 0; i < sizeTexture; i += stepSize)
for (j = 0; j < stepSize; j++)
*(((unsigned char *)gpTexture) + i + j) = (unsigned char) (pixValue >> ((stepSize - 1 - j) * 8));
}
// set up initial black texture
if (gMovieSettings.fTryPackedPixel && gfHasPackedPixels)
{
if (gMovieSettings.wOffScreenDepth == 32)
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, gMovieSettings.wTextureSize, gMovieSettings.wTextureSize, 0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, gpTexture);
else
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, gMovieSettings.wTextureSize, gMovieSettings.wTextureSize, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV, gpTexture);
}
else
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, gMovieSettings.wTextureSize, gMovieSettings.wTextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, gpTexture);
}
//-----------------------------------------------------------------------------------------------------------------------
// DrawGLMovieFrame - draws one movie frame at current time
void DrawGLMovieFrame (void)
{
MoviesTask (gMovie, 0);
DrawGL (&grectWin);
}
//-----------------------------------------------------------------------------------------------------------------------
// GLMovieDone - checks for complet movie, reseting if we are looping
Boolean GLMovieDone (void)
{
if (!gMovieSettings.fLoopMovie)
return IsMovieDone (gMovie);
else if (IsMovieDone (gMovie))
StartGLMovie ();
return false;
}
//-----------------------------------------------------------------------------------------------------------------------
// StartGLMovie - sets movie to beginning
void StartGLMovie (void)
{
GoToBeginningOfMovie (gMovie);
StartMovie (gMovie);
}
//-----------------------------------------------------------------------------------------------------------------------
// EndGLMovie - draws last frame
void EndGLMovie (void)
{
QTPlayMovieFrameAtTime (gMovie, GetMovieTime (gMovie, NULL)); // nudge one last time to make sure last frame is drawn.
DrawGL (&grectWin);
}
//-----------------------------------------------------------------------------------------------------------------------
// MoveFrame - moves quad in 3D space based on frustum edges and velocities
void MoveFrame (float * outx, float * outy, float * outz, float time)
{
static Boolean init = true;
static float vmax = 0.3, vmin = 0.1;
static float currx = 0.0, curry = 0.0, currz = 0.0;
static float vx = 0.0, vy = 0.0, vz = 0.0;
static float zMod = 8.0;
// static float size = 1.0;
static float ax = 0.1, ay = 0.1, az = 0.1;
float xedge = 1.0, yedge = .75;
float edgeDelta;
// init velocities ---------------------
if (init == true)
{
init = false;
vx = (vmax - vmin) / 2 + vmin + vmin / 3;
vy = (vmax - vmin) / 2 + vmin - vmin / 5;
vz = (vmax * zMod - vmin * zMod) / 2 + vmin * zMod;
}
// move polygon -------------------
currz = currz + vz * time;
if ((currz > 8.0) || (currz < 2.0))
{
if (currz > 8.0)
currz = 8.0;
if (currz < 2.0)
currz = 2.0;
vz = - vz;
if (vz > 0.0)
{
if (vz > vmax * zMod)
az = -vmax;
else if (vx < vmin * zMod)
az = vmax;
vz += az * time;
}
else
{
if (vz < -vmax * zMod)
az = vmax;
else if (vz > -vmin * zMod)
az = -vmax;
vz += az * time;
}
}
edgeDelta = 1.414 / currz; // size offset
currx = currx + vx * currz * time;
if ((((currx / currz * 2.0) > (xedge - edgeDelta)) && (vx > 0)) || (((currx / currz * 2.0) < -(xedge - edgeDelta)) && (vx < 0)))
{
vx = - vx;
if (vx > 0.0)
{
if (vx > vmax)
ax = -vmax / 10.0;
else if (vx < vmin)
ax = vmax / 10.0;
vx += ax * time;
}
else
{
if (vx < -vmax)
ax = vmax / 10.0;
else if (vx > -vmin)
ax = -vmax / 10.0;
vx += ax * time;
}
}
curry = curry + vy * currz * time;
if ((((curry / currz * 2.0) > (yedge - edgeDelta)) && (vy > 0)) || (((curry / currz * 2.0) < -(yedge - edgeDelta)) && (vy < 0)))
{
vy = - vy;
if (vy > 0.0)
{
if (vy > vmax)
ay = -vmax / 10.0;
else if (vy < vmin)
ax = vmax / 10.0;
vy += ay * time;
}
else
{
if (vy < -vmax)
ay = vmax / 10.0;
else if (vy > -vmin)
ay = -vmax / 10.0;
vy += ay * time;
}
}
*outx = currx;
*outy = curry;
*outz = currz;
}
//-----------------------------------------------------------------------------------------------------------------------
// SwizzleMovieToTexture - non-packed pixels texture swizzle standard Mac ARGB_8888 to RGB_888
void SwizzleMovieToTexture (void)
{
// will have 32 bit QT movie if were ever get here
register int i,j;
register unsigned char * pos = NULL;
register unsigned char * pTextile = gpTexture;
for (j = 0; j < gUsedTextureHeight; j++)
{
for (i = 0; i < gUsedTextureWidth; i++)
{
pos = (unsigned char *)(gpBaseAddr + (j * gRowStride) + (i * 4));
*(pTextile++) = *(pos + 1);
*(pTextile++) = *(pos + 2);
*(pTextile++) = *(pos + 3);
}
}
}
//-----------------------------------------------------------------------------------------------------------------------
// OpenGL Drawin
void DrawGL(Rect * pRect)
{
short width;
short height;
static float time = 0.0;
static long ticksPrev = 0;