/*!==========================================================================
*
* 蓋莫游戲引擎(GaiMo Game Engine)
*
* 版權所有 (C) 2009-2009 成都蓋莫軟件技術工作室 保留所有權利
* Copyright (C) 成都蓋莫軟件技術工作室. All Rights Reserved.
*
* 了解更多情況,請訪問 http://www.gaimo.net
****************************************************************************/
//! 本例子主要測試蓋莫游戲引擎的線程渲染和繪制基本2d幾何對象
//! 2010.04.08
#include <GEngine/Gaimo.hpp>
using namespace core;
using namespace ZThread;
Color color1(0.0f,0.5f,0.5f),color2(0.0f,1.0f,0.0f);
Color color3(1.0f,0.0f,0.0f),color4(1.0f,0.0f,1.0f);
Color color5(1.0f,1.0f,0.0f),color6(0.0f,1.0f,1.0f);
RefPtr<Device> device;
RefPtr<VideoDriver> videodriver;
void Render(bool flag);
//! 線程渲染類
class RenderThread : public Runnable
{
public:
RenderThread():flag(false){}
void run(){Render(flag);}
void Stop(){flag = true;}
private:
bool flag;
};
int Main()
{
device = core::InitDevice("線程渲染");
videodriver = device->GetVideoDriver();
videodriver->DetachRender();
RenderThread* render;
try
{
render = new RenderThread;
ZThread::Thread thread(render);
render->Stop();
}
catch(Synchronization_Exception& e)
{
std::cout<<e.what()<<std::endl;
}
BEGIN_LOOP(device)
END_LOOP(device)
return 1;
}
void Render(bool flag)
{
//! 獲取引擎資源管理器
core::RefPtr<core::ResourceManager> resmgr = device->GetResourceManager();
videodriver->AttachRender();
videodriver->Ortho2D();
videodriver->SetClearColor(core::Color::Blue);
BEGIN_LOOP(device)
videodriver->SetClearBuffer(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
//! 繪制矩形
videodriver->SetColor(color1);
videodriver->FillRect(100,120,50,50);
//! 繪制矩形
videodriver->SetColor(color2);
videodriver->DrawRect(100,180,50,50);
//! 繪制網格
videodriver->SetColor(color3);
videodriver->DrawGrid(Point(10,10),Point(20,20),Point(5,5));
//! 繪制變色矩形
//core::Render::DrawRaisedRectangle(libmath::Rect<float>(250,50,50,50),color5,color6);
//! 繪制三角形
videodriver->SetColor(color4);
//videodriver->DrawTriangle(Point(200,180),Point(200,270),Point(290,110),true);
//! 繪制點
videodriver->DrawPoint(Point(200,120));
RETURN_LOOP(flag,true)
END_LOOP(device);
}
這是使用蓋莫游戲引擎2.1.1線程渲染的例子
由于比較簡單這里就不提圖片了(免得浪費空間)