the opengl displayversion should be at least 1.5 display shaded scene,是什么意思

ViewScene/SceneContext.cxx
#include &SceneContext.h&
#include &SceneCache.h&
#include &SetCamera.h&
#include &DrawScene.h&
#include &DrawText.h&
#include &targa.h&
#include &../Common/Common.h&
const char * SAMPLE_FILENAME = &humanoid.fbx&;
const int LEFT_BUTTON = 0;
const int MIDDLE_BUTTON = 1;
const int RIGHT_BUTTON = 2;
const int BUTTON_DOWN = 0;
const int BUTTON_UP = 1;
void FillCameraArrayRecursive(* pNode, & pCameraArray)
if (pNode)
if (pNode-&())
if (pNode-&()-&() == )
pCameraArray.(pNode);
const int lCount = pNode-&();
for (int i = 0; i & lC i++)
FillCameraArrayRecursive(pNode-&(i), pCameraArray);
void FillCameraArray(* pScene, & pCameraArray)
pCameraArray.();
FillCameraArrayRecursive(pScene-&(), pCameraArray);
void FillPoseArray(* pScene, & pPoseArray)
const int lPoseCount = pScene-&();
for (int i=0; i & lPoseC ++i)
pPoseArray.(pScene-&(i));
void PreparePointCacheData(* pScene,
&pCache_Start,
&pCache_Stop)
const int lNodeCount = pScene-&&&();
for (int lIndex=0; lIndex&lNodeC lIndex++)
* lNode = pScene-&&&(lIndex);
if (lNode-&())
int i, lVertexCacheDeformerCount = lNode-&()-&();
lVertexCacheDeformerCount = lVertexCacheDeformerCount & 0 ? 1 : 0;
for (i=0; i&lVertexCacheDeformerC ++i )
* lDeformer = static_cast&*&(lNode-&()-&(i, ));
if( !lDeformer ) continue;
* lCache = lDeformer-&();
if( !lCache ) continue;
if (lDeformer-&.())
if (lCache-&() == )
if (!lCache-&(,
(pScene-&GetGlobalTimeSettings().GetTimeMode())))
lTheErrorIs = lCache-&GetStaus().GetErrorString();
else if (lCache-&() == )
if (!lCache-&((pScene-&().()), 0, &lStatus))
lTheErrorIs = lStatus.GetErrorString();
if (!lCache-&(&lStatus))
lTheErrorIs = lStatus.GetErrorString();
lDeformer-& = false;
lChannel_S
lChannel_S
int lChannelIndex = lCache-&(lDeformer-&.());
if(lCache-&(lChannelIndex, lChannel_Start, lChannel_Stop))
if(lChannel_Start & pCache_Start) pCache_Start = lChannel_S
if(lChannel_Stop
& pCache_Stop)
pCache_Stop
= lChannel_S
bool LoadTextureFromFile(const
& pFilePath, unsigned int & pTextureObject)
if (pFilePath.(3).() == &TGA&)
tga_image lTGAI
if (tga_read(&lTGAImage, pFilePath.()) == TGA_NOERR)
if (tga_is_right_to_left(&lTGAImage))
tga_flip_horiz(&lTGAImage);
if (tga_is_top_to_bottom(&lTGAImage))
tga_flip_vert(&lTGAImage);
tga_convert_depth(&lTGAImage, 24);
glGenTextures(1, &pTextureObject);
glBindTexture(GL_TEXTURE_2D, pTextureObject);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, lTGAImage.width, lTGAImage.height, 0, GL_BGR,
GL_UNSIGNED_BYTE, lTGAImage.image_data);
glBindTexture(GL_TEXTURE_2D, 0);
tga_free_buffers(&lTGAImage);
return true;
return false;
void LoadCacheRecursive( * pNode,
* pAnimLayer, bool pSupportVBO)
const int lMaterialCount = pNode-&();
for (int lMaterialIndex = 0; lMaterialIndex & lMaterialC ++lMaterialIndex)
* lMaterial = pNode-&(lMaterialIndex);
if (lMaterial && !lMaterial-&())
lMaterialCache(new MaterialCache);
if (lMaterialCache-&Initialize(lMaterial))
lMaterial-&(lMaterialCache.());
* lNodeAttribute = pNode-&();
if (lNodeAttribute)
if (lNodeAttribute-&() == )
* lMesh = pNode-&();
if (pSupportVBO && lMesh && !lMesh-&())
lMeshCache(new VBOMesh);
if (lMeshCache-&Initialize(lMesh))
lMesh-&(lMeshCache.());
else if (lNodeAttribute-&() == )
* lLight = pNode-&();
if (lLight && !lLight-&())
lLightCache(new LightCache);
if (lLightCache-&Initialize(lLight, pAnimLayer))
lLight-&(lLightCache.());
const int lChildCount = pNode-&();
for (int lChildIndex = 0; lChildIndex & lChildC ++lChildIndex)
LoadCacheRecursive(pNode-&(lChildIndex), pAnimLayer, pSupportVBO);
void UnloadCacheRecursive( * pNode)
const int lMaterialCount = pNode-&();
for (int lMaterialIndex = 0; lMaterialIndex & lMaterialC ++lMaterialIndex)
* lMaterial = pNode-&(lMaterialIndex);
if (lMaterial && lMaterial-&())
MaterialCache * lMaterialCache = static_cast&MaterialCache *&(lMaterial-&());
lMaterial-&();
delete lMaterialC
* lNodeAttribute = pNode-&();
if (lNodeAttribute)
if (lNodeAttribute-&() == )
* lMesh = pNode-&();
if (lMesh && lMesh-&())
VBOMesh * lMeshCache = static_cast&VBOMesh *&(lMesh-&());
lMesh-&();
delete lMeshC
else if (lNodeAttribute-&() == )
* lLight = pNode-&();
if (lLight && lLight-&())
LightCache * lLightCache = static_cast&LightCache *&(lLight-&());
lLight-&();
delete lLightC
const int lChildCount = pNode-&();
for (int lChildIndex = 0; lChildIndex & lChildC ++lChildIndex)
UnloadCacheRecursive(pNode-&(lChildIndex));
void LoadCacheRecursive( * pScene,
* pAnimLayer, const char * pFbxFileName, bool pSupportVBO)
const int lTextureCount = pScene-&();
for (int lTextureIndex = 0; lTextureIndex & lTextureC ++lTextureIndex)
* lTexture = pScene-&(lTextureIndex);
* lFileTexture = FbxCast&FbxFileTexture&(lTexture);
if (lFileTexture && !lFileTexture-&())
lFileName = lFileTexture-&();
if (lFileName.(3).() != &TGA&)
FBXSDK_printf(&Only TGA textures are supported now: %s\n&, lFileName.());
GLuint lTextureObject = 0;
bool lStatus = LoadTextureFromFile(lFileName, lTextureObject);
lAbsFbxFileName = (pFbxFileName);
lAbsFolderName = (lAbsFbxFileName);
if (!lStatus)
lResolvedFileName = (lAbsFolderName, lFileTexture-&());
lStatus = LoadTextureFromFile(lResolvedFileName, lTextureObject);
if (!lStatus)
lTextureFileName = (lFileName);
lResolvedFileName = (lAbsFolderName, lTextureFileName);
lStatus = LoadTextureFromFile(lResolvedFileName, lTextureObject);
if (!lStatus)
FBXSDK_printf(&Failed to load texture file: %s\n&, lFileName.());
if (lStatus)
GLuint * lTextureName = new GLuint(lTextureObject);
lFileTexture-&(lTextureName);
LoadCacheRecursive(pScene-&(), pAnimLayer, pSupportVBO);
void UnloadCacheRecursive( * pScene)
const int lTextureCount = pScene-&();
for (int lTextureIndex = 0; lTextureIndex & lTextureC ++lTextureIndex)
* lTexture = pScene-&(lTextureIndex);
* lFileTexture = FbxCast&FbxFileTexture&(lTexture);
if (lFileTexture && lFileTexture-&())
GLuint * lTextureName = static_cast&GLuint *&(lFileTexture-&());
lFileTexture-&();
glDeleteTextures(1, lTextureName);
delete lTextureN
UnloadCacheRecursive(pScene-&());
bool InitializeOpenGL()
GLenum lError = glewInit();
if (lError != GLEW_OK)
FBXSDK_printf(&GLEW Error: %s\n&, glewGetErrorString(lError));
return false;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glClearColor(0.0, 0.0, 0.0, 0.0);
if (!GLEW_VERSION_1_5)
FBXSDK_printf(&The OpenGL version should be at least 1.5 to display shaded scene!\n&);
return false;
return true;
SceneContext::SceneContext(const char * pFileName, int pWindowWidth, int pWindowHeight, bool pSupportVBO)
: mFileName(pFileName), mStatus(UNLOADED),
mSdkManager(), mScene(), mImporter(), mCurrentAnimLayer(), mSelectedNode(),
mPoseIndex(-1), mCameraStatus(CAMERA_NOTHING), mPause(false), mShadingMode(SHADING_MODE_SHADED),
mSupportVBO(pSupportVBO), mCameraZoomMode(ZOOM_FOCAL_LENGTH),
mWindowWidth(pWindowWidth), mWindowHeight(pWindowHeight), mDrawText(new DrawText)
if (mFileName == )
mFileName = SAMPLE_FILENAME;
mCache_Start = ;
mCache_Stop
InitializeSdkObjects(mSdkManager, mScene);
if (mSdkManager)
int lFileFormat = -1;
mImporter = (mSdkManager,&&);
if (!mSdkManager-&GetIOPluginRegistry()-&DetectReaderFileFormat(mFileName, lFileFormat) )
lFileFormat = mSdkManager-&GetIOPluginRegistry()-&FindReaderIDByDescription( &FBX binary (*.fbx)& );;
if(mImporter-&Initialize(mFileName, lFileFormat) == true)
mWindowMessage = &Importing file &;
mWindowMessage += mFileN
mWindowMessage += &\nPlease wait!&;
mStatus = MUST_BE_LOADED;
mWindowMessage = &Unable to open file &;
mWindowMessage += mFileN
mWindowMessage += &\nError reported: &;
mWindowMessage += mImporter-&GetStatus().GetErrorString();
mWindowMessage += &\nEsc to exit&;
mWindowMessage = &Unable to create the FBX SDK manager&;
mWindowMessage += &\nEsc to exit&;
SceneContext::~SceneContext()
(mAnimStackNameArray);
delete mDrawT
if (mScene)
UnloadCacheRecursive(mScene);
DestroySdkObjects(mSdkManager, true);
bool SceneContext::LoadFile()
bool lResult = false;
if (mStatus == MUST_BE_LOADED)
if (mImporter-&Import(mScene) == true)
mStatus = MUST_BE_REFRESHED;
SceneAxisSystem = mScene-&GetGlobalSettings().GetAxisSystem();
OurAxisSystem(, , );
if( SceneAxisSystem != OurAxisSystem )
OurAxisSystem.ConvertScene(mScene);
SceneSystemUnit = mScene-&GetGlobalSettings().GetSystemUnit();
if( SceneSystemUnit.() != 1.0 )
.( mScene);
mScene-&FillAnimStackNameArray(mAnimStackNameArray);
FillCameraArray(mScene, mCameraArray);
lGeomConverter(mSdkManager);
lGeomConverter.Triangulate(mScene, true);
LoadCacheRecursive(mScene, mCurrentAnimLayer, mFileName, mSupportVBO);
PreparePointCacheData(mScene, mCache_Start, mCache_Stop);
FillPoseArray(mScene, mPoseArray);
mWindowMessage = &File &;
mWindowMessage += mFileN
mWindowMessage += &\nClick on the right mouse button to enter menu.&;
mWindowMessage += &\nEsc to exit.&;
mFrameTime.SetTime(0, 0, 0, 1, 0, mScene-&GetGlobalSettings().GetTimeMode());
FBXSDK_printf(&Play/Pause Animation: Space Bar.\n&);
FBXSDK_printf(&Camera Rotate: Left Mouse Button.\n&);
FBXSDK_printf(&Camera Pan: Left Mouse Button + Middle Mouse Button.\n&);
FBXSDK_printf(&Camera Zoom: Middle Mouse Button.\n&);
lResult = true;
mStatus = UNLOADED;
mWindowMessage = &Unable to import file &;
mWindowMessage += mFileN
mWindowMessage += &\nError reported: &;
mWindowMessage += mImporter-&GetStatus().GetErrorString();
mImporter-&Destroy();
mImporter = ;
bool SceneContext::SetCurrentAnimStack(int pIndex)
const int lAnimStackCount = mAnimStackNameArray.GetCount();
if (!lAnimStackCount || pIndex &= lAnimStackCount)
return false;
* lCurrentAnimationStack = mScene-&&&(mAnimStackNameArray[pIndex]-&Buffer());
if (lCurrentAnimationStack == )
return false;
mCurrentAnimLayer = lCurrentAnimationStack-&&&();
mScene-&SetCurrentAnimationStack(lCurrentAnimationStack);
* lCurrentTakeInfo = mScene-&GetTakeInfo(*(mAnimStackNameArray[pIndex]));
if (lCurrentTakeInfo)
mStart = lCurrentTakeInfo-&.();
mStop = lCurrentTakeInfo-&.();
lTimeLineTimeS
mScene-&GetGlobalSettings().GetTimelineDefaultTimeSpan(lTimeLineTimeSpan);
mStart = lTimeLineTimeSpan.();
= lTimeLineTimeSpan.();
if(mCache_Start & mStart)
mStart = mCache_S
if(mCache_Stop
= mCache_S
mCurrentTime = mS
mStatus = MUST_BE_REFRESHED;
return true;
bool SceneContext::SetCurrentCamera(const char * pCameraName)
if (!pCameraName)
return false;
& lGlobalCameraSettings = mScene-&GetGlobalSettings();
lGlobalCameraSettings.(pCameraName);
mStatus = MUST_BE_REFRESHED;
return true;
bool SceneContext::SetCurrentPoseIndex(int pPoseIndex)
mPoseIndex = pPoseI
mStatus = MUST_BE_REFRESHED;
return true;
void SceneContext::OnTimerClick() const
if (mStop & mStart && !mPause)
mStatus = MUST_BE_REFRESHED;
mCurrentTime += mFrameT
if (mCurrentTime & mStop)
mCurrentTime = mS
mStatus = REFRESHED;
bool SceneContext::OnDisplay()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (mStatus != UNLOADED && mStatus != MUST_BE_LOADED)
glPushAttrib(GL_ENABLE_BIT);
glPushAttrib(GL_LIGHTING_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
SetCamera(mScene, mCurrentTime, mCurrentAnimLayer, mCameraArray,
mWindowWidth, mWindowHeight);
* lPose = ;
if (mPoseIndex != -1)
lPose = mScene-&GetPose(mPoseIndex);
lDummyGlobalP
if (mSelectedNode)
InitializeLights(mScene, mCurrentTime, lPose);
DrawNodeRecursive(mSelectedNode, mCurrentTime, mCurrentAnimLayer, lDummyGlobalPosition, lPose, mShadingMode);
DisplayGrid(lDummyGlobalPosition);
InitializeLights(mScene, mCurrentTime, lPose);
DrawNodeRecursive(mScene-&GetRootNode(), mCurrentTime, mCurrentAnimLayer, lDummyGlobalPosition, lPose, mShadingMode);
DisplayGrid(lDummyGlobalPosition);
glPopAttrib();
glPopAttrib();
DisplayWindowMessage();
return true;
void SceneContext::OnReshape(int pWidth, int pHeight)
glViewport(0, 0, (GLsizei)pWidth, (GLsizei)pHeight);
mWindowWidth = pW
mWindowHeight = pH
void SceneContext::OnKeyboard(unsigned char pKey)
if (pKey == 43 || pKey == 61)
* lCamera = GetCurrentCamera(mScene);
if(lCamera)
CameraZoom(mScene, 10, mCameraZoomMode);
mStatus = MUST_BE_REFRESHED;
if (pKey == 45 || pKey == 95)
* lCamera = GetCurrentCamera(mScene);
if(lCamera)
CameraZoom(mScene, 0 - 10, mCameraZoomMode);
mStatus = MUST_BE_REFRESHED;
if (pKey == 'N' || pKey == 'n')
if (pKey == ' ')
SetPause(!GetPause());
void SceneContext::OnMouse(int pButton, int pState, int pX, int pY)
* lCamera = GetCurrentCamera(mScene);
if (lCamera)
mCamPosition = lCamera-&.Get();
mCamCenter = lCamera-&.Get();
mRoll = lCamera-&.();
mLastX = pX;
mLastY = pY;
switch (pButton)
case LEFT_BUTTON:
switch (pState)
case BUTTON_DOWN:
if (mCameraStatus == CAMERA_ZOOM)
mCameraStatus = CAMERA_PAN;
mCameraStatus = CAMERA_ORBIT;
if (mCameraStatus == CAMERA_PAN)
mCameraStatus = CAMERA_ZOOM;
mCameraStatus = CAMERA_NOTHING;
case MIDDLE_BUTTON:
switch (pState)
case BUTTON_DOWN:
if (mCameraStatus == CAMERA_ORBIT)
mCameraStatus = CAMERA_PAN;
mCameraStatus = CAMERA_ZOOM;
if (mCameraStatus == CAMERA_PAN)
mCameraStatus = CAMERA_ORBIT;
mCameraStatus = CAMERA_NOTHING;
void SceneContext::OnMouseMotion(int pX, int pY)
switch (mCameraStatus)
case CAMERA_ORBIT:
CameraOrbit(mScene, mCamPosition, mRoll, pX-mLastX, mLastY-pY);
mStatus = MUST_BE_REFRESHED;
case CAMERA_ZOOM:
motion = mLastY-pY;
CameraZoom(mScene, motion, mCameraZoomMode);
mLastY = pY;
mStatus = MUST_BE_REFRESHED;
case CAMERA_PAN:
CameraPan(mScene, mCamPosition, mCamCenter, mRoll, pX-mLastX, mLastY-pY);
mStatus = MUST_BE_REFRESHED;
void SceneContext::SetSelectedNode( * pSelectedNode)
mSelectedNode = pSelectedN
mStatus = MUST_BE_REFRESHED;
void SceneContext::SetShadingMode(ShadingMode pMode)
mShadingMode = pM
mStatus = MUST_BE_REFRESHED;
void SceneContext::DisplayWindowMessage()
glColor3f(1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, mWindowWidth, 0, mWindowHeight);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
const float lX = 5;
const float lY = static_cast&float&(mWindowHeight) - 20;
glTranslatef(lX, lY, 0);
mDrawText-&SetPointSize(15.f);
mDrawText-&Display(mWindowMessage.Buffer());
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
void SceneContext::DisplayGrid(const
& pTransform)
glPushMatrix();
glMultMatrixd(pTransform);
glColor3f(0.3f, 0.3f, 0.3f);
glLineWidth(1.0);
const int hw = 500;
const int step = 20;
const int bigstep = 100;
for (i = - i &= i+=step) {
if (i % bigstep == 0) {
glLineWidth(2.0);
glLineWidth(1.0);
glBegin(GL_LINES);
glVertex3i(i,0,-hw);
glVertex3i(i,0,hw);
glBegin(GL_LINES);
glVertex3i(-hw,0,i);
glVertex3i(hw,0,i);
const GLfloat zoffset = -2.f;
const GLfloat xoffset = 1.f;
mDrawText-&SetPointSize(4.f);
for (i = - i &= i+=bigstep)
if (i == 0) {
scoord = &0&;
lCount = (int)scoord.();
glPushMatrix();
glVertex3f(i+xoffset,0,zoffset);
glRotatef(-90,1,0,0);
mDrawText-&Display(scoord.());
glPopMatrix();
scoord = &X: &;
lCount = (int)scoord.();
glPushMatrix();
glTranslatef(i+xoffset,0,zoffset);
glRotatef(-90,1,0,0);
mDrawText-&Display(scoord.());
glPopMatrix();
scoord = &Z: &;
lCount = (int)scoord.();
glPushMatrix();
glTranslatef(xoffset,0,i+zoffset);
glRotatef(-90,1,0,0);
mDrawText-&Display(scoord.());
glPopMatrix();
glPopMatrix();
void SceneContext::SetZoomMode( CameraZoomMode pZoomMode)
if( pZoomMode == ZOOM_POSITION)
mCameraZoomMode = ZOOM_POSITION;
mCameraZoomMode =
ZOOM_FOCAL_LENGTH; 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
The Red Book Opengl Graphic Design
下载积分:300
内容提示:The Red Book Opengl Graphic Design
文档格式:PDF|
浏览次数:7|
上传日期: 04:10:26|
文档星级:
全文阅读已结束,如果下载本文需要使用
 300 积分
下载此文档
该用户还上传了这些文档
The Red Book Opengl Graphic Design
官方公共微信I do these for fun, but if you like what you read and want more, this is how you can help :) 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
opengl programming guide the official guide to learning opengl, version 1.1 (otl.
下载积分:3000
内容提示:opengl programming guide the official guide to learning opengl, version 1.1 (otl):(opengl编程指南官方指南学习opengl 1.1版本(otl))
文档格式:PDF|
浏览次数:1|
上传日期: 04:53:29|
文档星级:
全文阅读已结束,如果下载本文需要使用
 3000 积分
下载此文档
该用户还上传了这些文档
opengl programming guide the official guide to lea
官方公共微信

我要回帖

更多关于 opengl display list 的文章

 

随机推荐