topical media & game development

talk show tell print

lib-game-darkgdk-video-sample-sample-darkgdk-Main.cpp / cpp



  // Dark Video - Deep Cove Software, Ltd. - www.deepcovesoftware.com
  // Dark GDK - The Game Creators - www.thegamecreators.com
  
  // this sample is based on the Dark Video DarkBASIC Professional sample,
  // which in turn is based on The Game Creators' 3DVideo sample.
  
  // whenever using Dark GDK you must ensure you include the header file
  include <DarkGDK.h>
  
  // include the header file for Dark Video
  include <DarkVideo.h>
  
  // the main entry point for the application is this function
  void DarkGDK ( void )
  {
          // initialize Dark Video
          DarkVideoInitialize();
  
          // when starting a Dark GDK program it is useful to set global
          // application properties, we begin by turning the sync rate on,
          // this means we control when the screen is updated, we also set
          // the maximum rate to 30 which means the maximum frame rate will
          // be set at 30 frames per second
          dbSyncOn   ( );
          dbSyncRate ( 30 );
  
          // set the window title
          dbSetWindowTitle( "Dark Video Dark GDK Sample" );
  
          // set default screen
          dbColorBackdrop( dbRGB( 0, 32, 32 ) );
  
          // open our Dark Video movie (*.dvf) and get the dimensions (we should
          // check the return value of DarkVideoOpen here but for simplicity...)
          int movieId = DarkVideoOpen( "sample.dvf" );
          int movieWidth = DarkVideoGetWidth( movieId );
          int movieHeight = DarkVideoGetHeight( movieId );
  
          // set the movie volume (between 0-255), no effect of course if there's
          // no audio in the movie.
          DarkVideoSetVolume( movieId, 255 );
  
          // arbitrary ids we'll use
          int memBlockId = 32;
          int imageId = 32;
  
          // create a blank 32-bit image of the same dimensions as the Dark Video
          // movie. Dark Video will decode each frame to this image.
          // the size is the width by the height by 4 bytes per pixel as it's
          // 32-bit color. we also add 12 bytes for 3 dwords at the start of
          // the memblock that contain the width, height and bit depth as we're
          // going to create an image from this memblock.
          dbMakeMemblock( memBlockId, movieWidth * movieHeight * 4 + 12 );
          dbWriteMemblockDword( memBlockId, 0, movieWidth );
          dbWriteMemblockDword( memBlockId, 4, movieHeight );
          dbWriteMemblockDword( memBlockId, 8, 32 );
          dbMakeImageFromMemblock( imageId, memBlockId );
          dbDeleteMemblock( memBlockId );
  
          // create 3D projection
          for ( int p = 1; p <= 3; p++ )
          {
                  dbMakeObjectBox( p, 320, 240, 10 );
                  dbScaleObject( p, p * 250, p * 250, p * 250 );
                  if ( p > 1 )
                          dbGhostObjectOn( p, 2 );
                  dbTextureObject( p, imageId );
          }
          dbSetObjectLight( 1, 0 );
  
          // setup camera
          dbPositionCamera( 0, 0, -700 );
          dbRotateCamera( 0, 0, 0 );
  
          bool begin = true;
          float a = 0.0f;
  
          // now we come to our main loop, we call LoopGDK so some internal
          // work can be carried out by the GDK
          while ( LoopGDK ( ) )
          {
                  // begin movie playback
                  if ( begin )
                  {
                          begin = false;
                          bool loop = true;
  
                          // note the last parameter? This *HAS* to be set to dbGetImagePointer
                          // or Dark Video is unable to decode the movie to a Dark GDK image.
                          DarkVideoPlay( movieId, imageId, loop, dbGetImagePointer );
                  }
  
                  // move projection around
                  for ( int p = 1; p <= 3; p++ )
                  {
                          a = dbWrapValue( a + 1.0f );
                          dbPositionObject( p, dbCOS( a ) * 20, dbSIN( a ) * 10, p * 75 );
                          dbYRotateObject( p, dbCOS( a ) * 20 );
                          dbZRotateObject( p, ( p - 1 ) * 10 );
                  }
                  
                  // here we make a call to update the contents of the screen
                  dbSync ( );
          }
  
          // stop and shutdown Dark Video movie
          DarkVideoStop( movieId );
          DarkVideoClose( movieId );
  
          // shutdown Dark Video
          DarkVideoShutdown();
  
          // and now everything is ready to return back to Windows
          return;
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.