游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2241|回复: 0

盖莫游戏引擎2.1.1多线程渲染

[复制链接]

56

主题

94

帖子

98

积分

注册会员

Rank: 2

积分
98
发表于 2010-4-8 09:25:00 | 显示全部楼层 |阅读模式
/*!==========================================================================
*
*  盖莫游戏引擎(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:rawRaisedRectangle(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线程渲染的例子
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2024-5-12 21:51

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表