tools/toolgrabview3d/ortoolgrabview3d_view.cxx

tools/toolgrabview3d/ortoolgrabview3d_view.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declaration
#include "ortoolgrabview3d_view.h"
#if defined( KARCH_ENV_WIN )
#include <windows.h> //For wglUseFontBitmaps
#endif
#pragma comment(lib,"user32.lib") // This is to avoid changing the template for the .dsp files.
/************************************************
* Constructor
************************************************/
ORView3D::ORView3D() :
mRender(NULL),
mFontDisplayList(0)
{
mRender = mSystem.Renderer;
// The resulting file will depend on the extension of the output file.
// "output.avi" will generate a Windows Media file, and "output.mov"
// will generate a QuickTime file. The QuickTime authoring module must
// be installed on your machine to generate this type of file. On Windows
// it comes with the free version of the player, but is not installed
// by default.
mFileName = "output.avi";
mFilePath = "C:";
//Here, we show that it is easy to enable/disable final artifacts,
//like the SafeArea or the CameraLabel. IMPORTANT: For this, we must
//not forget to pass this FBView to RenderEnd or these won't be drawed.
FBViewingOptions* lVO = mRender->GetViewingOptions();
lVO->ShowTimeCode() = true;
lVO->ShowSafeArea() = true;
lVO->ShowCameraLabel() = true;
}
/************************************************
* Destructor
************************************************/
void ORView3D::FBDestroy()
{
if( mFontDisplayList )
{
glDeleteLists(mFontDisplayList,256);
mFontDisplayList = 0;
}
}
/************************************************
* Refresh callback
************************************************/
void ORView3D::Refresh(bool pNow)
{
FBView::Refresh(pNow);
}
/************************************************
* Expose callback
************************************************/
void ORView3D::ViewExpose()
{
//-------------------------------------------------------------------------
// Important Note:
//
// You need to make sure that the render size here is the same that you
// passed to the grab options.
//-------------------------------------------------------------------------
int Width = Region.Position.X[1] - Region.Position.X[0];
int Height = Region.Position.Y[1] - Region.Position.Y[0];
if( mRender->RenderBegin(0, 0, Width, Height) )
{
mRender->PreRender();
mRender->Render();
mRender->RenderEnd(this);
}
//Here we add a custom render pass to draw some text onto the render result.
CustomGLDrawString(5, 15, "Custom Title!");
}
void ORView3D::ViewInput(int pMouseX, int pMouseY, FBInputType pAction, int pButtonKey, int pModifier)
{
//-------------------------------------------------------------------------
// Important Note:
//
// Since we don't render in memory, we need the render window to be shown
// before we begin the video grabbing, or it will give unpredicted results.
//-------------------------------------------------------------------------
if( pAction == kFBButtonDoubleClick )
{
FBVideoGrabber VideoGrabber;
FBVideoGrabOptions GrabOptions = VideoGrabber.GetOptions();
FBTime lStart, lStop, lStep;
lStart.SetTime(0, 0, 0, 0, 0); //Frame 0
lStop.SetTime(0, 0, 0, 150, 0); //Frame 150
lStep.SetTime(0, 0, 0, 1, 0); //1 Frame
GrabOptions.mTimeSpan.Set(lStart, lStop);
GrabOptions.mTimeSteps.SetTime(0, 0, 0, 1, 0);
GrabOptions.mCameraResolution = kFBResolutionCustom;
GrabOptions.mBitsPerPixel = FBVideoRender32Bits;
GrabOptions.mFieldMode = FBFieldModeNoField;
GrabOptions.mViewingMode = FBViewingModeModelsOnly;
GrabOptions.mOutputFileName = mFilePath + FBString( "\\" ) + mFileName;
GrabOptions.mAntiAliasing = false;
GrabOptions.mRenderAudio = false;
GrabOptions.mAudioRenderFormat = FBAudioFmt_GetDefaultFormat(); //44100Hz 16bits stereo
VideoGrabber.SetOptions(&GrabOptions);
VideoGrabber.SetRefreshViewFunc(this, RefreshViewCallback);
//Start rendering while grabbing each frame
if( VideoGrabber.BeginGrab() ) //Check if we can grab
{
VideoGrabber.Grab(); //Grab all frame
VideoGrabber.EndGrab(); //End grabbing session
}
}
}
void ORView3D::RefreshViewCallback(void* pThis)
{
ORView3D* lThis = (ORView3D*)pThis;
lThis->Refresh(true);
}
FBString ORView3D::GetFileName()
{
return mFileName;
}
void ORView3D::SetFileName( const char* pFileName )
{
mFileName = pFileName;
}
FBString ORView3D::GetFilePath()
{
return mFilePath;
}
void ORView3D::SetFilePath( const char* pFilePath )
{
mFilePath = pFilePath;
}
void ORView3D::CustomGLDrawString(int pX, int pY, const char* pText)
{
// For now we cannot draw custom strings on Mac OSX...
#if defined( KARCH_ENV_WIN )
if( mFontDisplayList == 0 ) //Create fonts display list. (256 is for the ascii table size)
{
mFontDisplayList = glGenLists(256);
if( !wglUseFontBitmaps(GetDC(NULL), 0, 256, mFontDisplayList) )
{
glDeleteLists(mFontDisplayList, 256);
mFontDisplayList = 0;
}
}
if( mFontDisplayList )
{
//We must initialize 2D coordinate system so that the upper-left corner is the origin.
int Width = Region.Position.X[1] - Region.Position.X[0];
int Height = Region.Position.Y[1] - Region.Position.Y[0];
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Width, Height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Draw text
glRasterPos2i(pX, pY); //Position the string in space
glListBase(mFontDisplayList); //Indicate start of glyph display lists
glCallLists((GLsizei)strlen(pText), GL_UNSIGNED_BYTE, pText); //Now draw the characters in a string
}
#endif
}