这是使用盖莫游戏引擎2.1.2测试环境映射的demo
对opengl而言
环境映射主要就围绕函数glTexEnv工作的
但是其实现起来不是那么容易
该测试例子源于2.1.1版本demo中的球面映射一例
增加的代码为:
RefPtr<TexEnv> texenv = reflect->GetTexEnv();
texenv->SetEnvColor(Color::Blue);
texenv->SetMode(TEXTURE_ENV_MODE_BLEND);
texenv->SetLodBias(0.2f);
texenv->SetPointSpriteCoordReplace(true);
texenv->SetRGBScale(1.2f);
texenv->SetAlphaScale(0.8f);
texenv->SetCombineMode(TEXTURE_ENV_MODE_INTERPOLATE);
texenv->SetEnvSource0(TEXTURE_ENV_SOURCE_TEXTURE0);
texenv->SetEnvSource1(TEXTURE_ENV_SOURCE_TEXTURE1);
texenv->SetEnvSource2(TEXTURE_ENV_SOURCE_TEXTURE2);
环境映射的操作模式就是从纹理中获取对应的环境映射指针并设置合适的参数数值
全demo源码为:
/*!==========================================================================
*
* 盖莫游戏引擎(GaiMo Game Engine)
*
* 版权所有 (C) 2009-2009 成都盖莫软件技术工作室 保留所有权利
* Copyright (C) 成都盖莫软件技术工作室. All Rights Reserved.
*
* 了解更多情况,请访问 http://www.gaimo.net
****************************************************************************/
#include <GEngine/Gaimo.hpp>
using namespace std;
using namespace core;
int main(int argc, char **argv)
{
//! 初始化引擎设备并得到设备指针
RefPtr<Device> device = core::InitDevice("环境映射");
//! 得到引擎场景指针
RefPtr<SceneManager> scenemanager = device->GetSceneManager();
//! 得到引擎资源指针
RefPtr<ResourceManager> resourcemanager = device->GetResourceManager();
//! 获取引擎纹理管理器指针
RefPtr<TextureManager> texturemanager = resourcemanager->GetTextureManager();
//! 获取引擎图形管理器
RefPtr<ImageManager> imagemanager = resourcemanager->GetImageManager();
//! 获取引擎视频驱动器
RefPtr<VideoDriver> videodriver = device->GetVideoDriver();
//! 得到图形和其纹理
RefPtr<Image> image1 = imagemanager->CreateObject("background","..\\image//spheremap//tree.jpg");
RefPtr<Texture> background = texturemanager->CreateObject("background",image1);
background->Generate();
RefPtr<Image> image2 = imagemanager->CreateObject("reflect","..\\image//spheremap//tree1.jpg");
RefPtr<Texture> reflect = texturemanager->CreateSphereMap("reflect",image2);
RefPtr<TexEnv> texenv = reflect->GetTexEnv();
texenv->SetEnvColor(Color::Blue);
texenv->SetMode(TEXTURE_ENV_MODE_BLEND);
texenv->SetLodBias(0.2f);
texenv->SetPointSpriteCoordReplace(true);
texenv->SetRGBScale(1.2f);
texenv->SetAlphaScale(0.8f);
texenv->SetCombineMode(TEXTURE_ENV_MODE_INTERPOLATE);
texenv->SetEnvSource0(TEXTURE_ENV_SOURCE_TEXTURE0);
texenv->SetEnvSource1(TEXTURE_ENV_SOURCE_TEXTURE1);
texenv->SetEnvSource2(TEXTURE_ENV_SOURCE_TEXTURE2);
reflect->Generate();
//! 获取全局摄像机,设置摄像机参数
core::RefPtr<core::Camera> camera = scenemanager->GetActiveCamera();
camera->SetPosition(Vector3f(0,0,30));
camera->SetView(Vector3f(0,0,0));
camera->SetDirection(Vector3f(0,1,0));
camera->SetViewPort(Recti(0,0,640,480));
camera->SetPerspective(50.0f,640.0f/480.0f,0.1f,300.0f);
videodriver->EnableCulling();
BEGIN_LOOP(device)
videodriver->SetClearBuffer(ENGINE_CLEAR_COLOR | ENGINE_CLEAR_DEPTH);
videodriver->SetClearColor(core::Color::Blue);
camera->Render();
background->AttachRenderTarget();
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-13.0f, -12.0f, 10.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 13.0f, -12.0f, 10.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 13.0f, 12.0f, 10.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-13.0f, 12.0f, 10.0f);
glEnd();
reflect->AttachRenderTarget();
videodriver->RenderSphere(12,32,32);
videodriver->RenderSphere(9,32,32);
videodriver->RenderSphere(6,32,32);
reflect->Destroy();
END_LOOP(device)
return 0;
}
当前测试例子设置环境映射模式为渲染模式
则其效果为:
再贴一次对应的无环境映射的图片如下:
可以看出盖莫游戏引擎一直在不断完善ing.