Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
这是设计的盖莫游戏引擎2.1.2的demo例子小试

interface设计如下:
以后还会修改之
///////////////////////////////////////////////////////////
/// 定义渲染到纹理对象
/////////////////////////////////////////////////////////// 
class G_DLL_API RenderToTexture : public Renderable

public:
    
////////////////////////////////////////////////////////
    //! 构造,析构渲染到纹理
    ////////////////////////////////////////////////////////
    RenderToTexture();
    
virtual ~RenderToTexture();
public:    
    
////////////////////////////////////////////////////////
    //! 设置渲染回调函数
    ////////////////////////////////////////////////////////    
    virtual void SetRenderCallBack(RenderCallBack rendertexture) = 0;
 
    
////////////////////////////////////////////////////////
    //! 设置渲染到纹理参数 
    ////////////////////////////////////////////////////////    
    virtual void SetPara(float fov,float near,float far) = 0;
    
    
////////////////////////////////////////////////////////
    //! 设置纹理清屏色,fbo色 
    ////////////////////////////////////////////////////////      
    virtual void SetClearColor(const Color& color) = 0
    
virtual void SetFboColor(const Color& color) = 0
    
    DECLARE_OBJECT(RenderToTexture)  
};

}

#endif 
//! ccsdu2004


测试代码如下:

#include <GEngine/Gaimo.hpp>
using namespace std;
using namespace core;

RefPtr
<Texture> boxtexture = NULL;
RefPtr
<Camera> camera = NULL;
//! 获取引擎视频驱动器
RefPtr<VideoDriver> videodriver = NULL;

//! 立方体绘制    
void _RenderCube_(float color[6][4]);

float color[6][4];
float yaw_angle = 0.0f;
float pitch_angle = 0.0f;

void InitClearColor()
{
    
for(int i = 0; i < 6; i++)
       
for(int j = 0; j < 4; j++)
          color[i][j] 
= 0.8f;
 
    color[
0][0= 0.5f;
    color[
1][1= 0.5f;
    color[
2][2= 0.5f;
    color[
3][0= 0.5f;
    color[
3][1= 0.5f;
    color[
4][1= 0.5f;
    color[
4][2= 0.5f;
    color[
5][0= 0.5f;        
}

void G_CALL draw()
{
    videodriver
->SetPilotView(0.0f,0.0f,5.0f,-55.0f,-pitch_angle,-yaw_angle);
    _RenderCube_(color);
}

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<LightManager> lightmanager = resourcemanager->GetLightManager();    
    
    
//! 获取引擎图形管理器
    RefPtr<ImageManager>   imagemanager = resourcemanager->GetImageManager();
    
//! 获取引擎视频驱动器
    videodriver = device->GetVideoDriver();
    glEnable(GL_TEXTURE_2D);
    
    
//! 启用环境光
    lightmanager->RenderGlobalAmbient(false); 
    
//! 启用光源
    lightmanager->EnableLight();    
    
//! 获取光指针
    RefPtr<Light> light = lightmanager->CreateObject("rttlight","..\\script//rtt.lua","light"); 
    
    
//! 获取全局摄像机,设置摄像机参数 
    camera = scenemanager->GetActiveCamera();
    camera
->SetPosition(Vector3f(0,0,18));
    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,1.0f,100.0f);

    InitClearColor();
    
    RefPtr
<RenderToTexture> rtt = device->GetRenderer()->GetRenderToTexture(&draw);
    rtt
->SetClearColor(Color(0.2f,0.2f,0.7f,0.5f));
    rtt
->SetFboColor(Color(1.0f,0.9f,0.7f,0.6f));

    light
->Render();
 
    BEGIN_LOOP(device)
       
//camera->Render();
           yaw_angle += 0.3f;
        pitch_angle 
+= 0.21f;
        rtt
->Render();
    END_LOOP(device)
    
    
//delete fbo;

    
return 0;
}

//! 立方体绘制    
void _RenderCube_(float color[6][4])
{    
    
//! draw cube
    glEnable(GL_COLOR_MATERIAL);
    
    glColor4fv(color[
0]);
    glBegin(GL_TRIANGLE_STRIP);
        glNormal3f(
0.0f0.0f-1.0f);
        glTexCoord2f(
0.0f0.0f);
        glVertex3f(
-1.0f-1.0f-1.0f);
        glTexCoord2f(
1.0f0.0f);
        glVertex3f(
1.0f-1.0f-1.0f);
        glTexCoord2f(
0.0f1.0f);
        glVertex3f(
-1.0f1.0f-1.0f);
        glTexCoord2f(
1.0f1.0f);
        glVertex3f(
1.0f1.0f-1.0f);
    glEnd();
    
    glColor4fv(color[
1]);
    glBegin(GL_TRIANGLE_STRIP);
        glNormal3f(
1.0f0.0f0.0f);
        glTexCoord2f(
0.0f0.0f);
        glVertex3f(
1.0f-1.0f-1.0f);
        glTexCoord2f(
1.0f0.0f);
        glVertex3f(
1.0f-1.0f1.0f);
        glTexCoord2f(
0.0f1.0f);
        glVertex3f(
1.0f1.0f-1.0f);
        glTexCoord2f(
1.0f1.0f);
        glVertex3f(
1.0f1.0f1.0f);
    glEnd();
    
    glColor4fv(color[
2]);
    glBegin(GL_TRIANGLE_STRIP);
        glNormal3f(
0.0f0.0f1.0f);
        glTexCoord2f(
0.0f0.0f);
        glVertex3f(
1.0f-1.0f1.0f);
        glTexCoord2f(
1.0f0.0f);
        glVertex3f(
-1.0f-1.0f1.0f);
        glTexCoord2f(
0.0f1.0f);
        glVertex3f(
1.0f1.0f1.0f);
        glTexCoord2f(
1.0f1.0f);
        glVertex3f(
-1.0f1.0f1.0f);
    glEnd();
    
    glColor4fv(color[
3]);
    glBegin(GL_TRIANGLE_STRIP);
        glNormal3f(
-1.0f0.0f0.0f);
        glTexCoord2f(
0.0f0.0f);
        glVertex3f(
-1.0f-1.0f1.0f);
        glTexCoord2f(
1.0f0.0f);
        glVertex3f(
-1.0f-1.0f-1.0f);
        glTexCoord2f(
0.0f1.0f);
        glVertex3f(
-1.0f1.0f1.0f);
        glTexCoord2f(
1.0f1.0f);
        glVertex3f(
-1.0f1.0f-1.0f);
    glEnd();
    
    glColor4fv(color[
4]);
    glBegin(GL_TRIANGLE_STRIP);
        glNormal3f(
0.0f-1.0f0.0f);
        glTexCoord2f(
0.0f0.0f);
        glVertex3f(
-1.0f-1.0f1.0f);
        glTexCoord2f(
1.0f0.0f);
        glVertex3f(
1.0f-1.0f1.0f);
        glTexCoord2f(
0.0f1.0f);
        glVertex3f(
-1.0f-1.0f-1.0f);
        glTexCoord2f(
1.0f1.0f);
        glVertex3f(
1.0f-1.0f-1.0f);
    glEnd();
    
    glColor4fv(color[
5]);
    glBegin(GL_TRIANGLE_STRIP);
        glNormal3f(
0.0f1.0f0.0f);
        glTexCoord2f(
0.0f0.0f);
        glVertex3f(
-1.0f1.0f-1.0f);
        glTexCoord2f(
1.0f0.0f);
        glVertex3f(
1.0f1.0f-1.0f);
        glTexCoord2f(
0.0f1.0f);
        glVertex3f(
-1.0f1.0f1.0f);
        glTexCoord2f(
1.0f1.0f);
        glVertex3f(
1.0f1.0f1.0f);
    glEnd();
}

贴图为:

.

....................................................................................................................................................................
继续.
posted on 2010-05-08 21:13 ccsdu2009 阅读(1417) 评论(2)  编辑 收藏 引用 所属分类: Game引擎
Comments
  • # re: 盖莫游戏引擎2.1.2-rtt demo小试
    陈昱(CY)
    Posted @ 2010-05-08 22:58
    看不明白,RenderToTexture 是个负责干什么的对象。。。。  回复  更多评论   
  • # re: 盖莫游戏引擎2.1.2-rtt demo小试
    ccsdu2009
    Posted @ 2010-05-09 13:16
    @陈昱(CY)
    其实现在很多东西都是中间对象
    上面少了高级层  回复  更多评论   

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