这是盖莫游戏引擎的立方体纹理一例
代码如下:
1 //! 2010.03.03
2 /////////////////////////////////////////////////////
3 /// 盖莫游戏引擎的立方体绘制
4 /////////////////////////////////////////////////////
5 //! 测试立方体绘制函数,矩阵,输入输出
6 //! 按键f1,f2,f3旋转立方体
7 #include <GEngine/Gaimo.hpp>
8
9 #define BOX_SIDE (12.0)
10 using namespace std;
11 using namespace core;
12 Matrix4f mat;
13
14 //! 处理鼠标响应
15 void MouseCheck(core::RefPtr<core::Input> input);
16
17 int main(int argc, char **argv)
18 {
19 //! 初始化引擎设备并得到设备指针
20 RefPtr<Device> device = core::InitDevice("立方体纹理");
21 //! 得到引擎场景指针
22 RefPtr<SceneManager> scenemanager = device->GetSceneManager();
23 //! 得到引擎资源指针
24 RefPtr<ResourceManager> resourcemanager = device->GetResourceManager();
25 //! 获取引擎纹理管理器指针
26 RefPtr<TextureManager> texturemanager = resourcemanager->GetTextureManager();
27 //! 获取引擎图形管理器
28 RefPtr<ImageManager> imagemanager = resourcemanager->GetImageManager();
29 //! 获取引擎视频驱动器
30 RefPtr<VideoDriver> videodriver = device->GetVideoDriver();
31 //! 获取文件系统指针
32 RefPtr<FileSystem> filesystem = device->GetFileSystem();
33 filesystem->AddToSearchPath("..\\image//cubemap.zip");
34
35 //! 得到tile图形和其纹理
36 core::RefPtr<Image> image1 = imagemanager->CreateObject("cube1",filesystem->OpenRead("cm_front.png"));
37 CHECK_PTR_PRINT(image1,"bad image1");
38 core::RefPtr<Image> image2 = imagemanager->CreateObject("cube2",filesystem->OpenRead("cm_back.png"));
39 CHECK_PTR_PRINT(image2,"bad image2");
40 core::RefPtr<Image> image3 = imagemanager->CreateObject("cube3",filesystem->OpenRead("cm_left.png"));
41 CHECK_PTR_PRINT(image3,"bad image3");
42 core::RefPtr<Image> image4 = imagemanager->CreateObject("cube4",filesystem->OpenRead("cm_right.png"));
43 CHECK_PTR_PRINT(image4,"bad image4");
44 core::RefPtr<Image> image5 = imagemanager->CreateObject("cube5",filesystem->OpenRead("cm_top.png"));
45 CHECK_PTR_PRINT(image5,"bad image5");
46 core::RefPtr<Image> image6 = imagemanager->CreateObject("cube6",filesystem->OpenRead("cm_bottom.png"));
47 CHECK_PTR_PRINT(image6,"bad image6");
48 core::RefPtr<Texture> cubemap = texturemanager->CreateCubeMap("cubemap",image1,image2,image3,image4,image5,image6);
49 cubemap->Generate();
50
51 //! 获取全局摄像机,设置摄像机参数
52 core::RefPtr<core::Camera> camera = scenemanager->GetActiveCamera();
53 camera->SetPosition(Vector3f(20,20,20));
54 camera->SetView(Vector3f(0,0,0));
55 camera->SetDirection(Vector3f(0,1,0));
56
57 camera->SetViewPort(Recti(0,0,640,480));
58 camera->SetPerspective(50.0f,640.0f/480.0f,0.1f,1000.0f);
59 videodriver->EnableCulling();
60
61 float sides[] = {BOX_SIDE,BOX_SIDE,BOX_SIDE};
62 float pos[] = {0,0,0};
63 BEGIN_LOOP(device)
64 videodriver->SetClearBuffer(ENGINE_CLEAR_COLOR | ENGINE_CLEAR_DEPTH);
65 videodriver->SetClearColor(core::Color::Blue);
66 camera->Render();
67 MouseCheck(device->GetInput());
68 cubemap->AttachRenderTarget();
69 videodriver->RenderCube(pos,mat.ptr(),sides);
70 END_LOOP(device)
71
72 return 0;
73 }
74
75 //! 处理鼠标响应
76 void MouseCheck(core::RefPtr<core::Input> input)
77 {
78 if(input->IsPressedKey(KEY_F1))
79 {
80 mat*=mat.Rotate((rand()%200)/1200.0f,1,0,0);
81 }
82 else if(input->IsPressedKey(KEY_F2))
83 {
84 mat*=mat.Rotate((rand()%200)/1200.0f,0,1,0);
85 }
86 else if(input->IsPressedKey(KEY_F3))
87 {
88 mat*=mat.Rotate((rand()%200)/1200.0f,0,0,1);
89 }
90 }
91
92
93
具体的使用方法就是从设备指针中获取资源管理器指针
然后从资源管理器获取纹理管理器指针
之后调用CreateCubeMap();传入6个图形指针即可
之后调用成员函数Generate函数
在使用的时候调用AttachRenderTarget绑定当前纹理即可使用很方便吧
下面是具体的贴图: