Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
/*!==========================================================================
*
*  盖莫游戏引擎(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线程渲染的例子
由于比较简单这里就不提图片了(免得浪费空间)
posted on 2010-04-08 09:26 ccsdu2009 阅读(369) 评论(0)  编辑 收藏 引用 所属分类: Game引擎

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理