使用盖莫游戏引擎在线程中渲染的简单例子
绘制简单的几何体小例子
比较简单
代码如下:
1 #include <GEngine/GaiMo.hpp>
2
3 core::Color color1(0.0f,0.0f,1.0f),color2(0.0f,1.0f,0.0f);
4 core::Color color3(1.0f,0.0f,0.0f),color4(1.0f,0.0f,1.0f);
5 core::Color color5(1.0f,1.0f,0.0f),color6(0.0f,1.0f,1.0f);
6
7 core::Device *device = NULL;
8
9 ThreadId id = 0;
10 bool flag = true;
11
12 void G_CALL Render(void* ptr)
13 {
14 device->AttachRender();
15 do
16 {
17 BEGIN_LOOP(device)
18 //! 绘制矩形
19 core::Render::SetCurrentColor(color1);
20 core::Render::FillRect(100,120,50,50);
21 //! 绘制矩形
22 core::Render::SetCurrentColor(color2);
23 core::Render::DrawRect(100,180,50,50);
24 //! 绘制网格
25 core::Render::SetCurrentColor(color3);
26 core::Render::DrawGrid(Point(10,10),Point(20,20),Point(5,5));
27 //! 绘制变色矩形
28 core::Render::DrawRaisedRectangle(libmath::Rect<float>(250,50,50,50),color5,color6);
29 //! 绘制三角形
30 core::Render::SetCurrentColor(color4);
31 core::Render::DrawTriangle(Point(200,180),Point(200,270),Point(290,110),true);
32 END_LOOP(device);
33 }while(flag);
34 }
35
36 int Main()
37 {
38 device = core::InitDevice("线程渲染");
39 device->Ortho2D();
40 device->DetachRender();
41 id = device->CreateThread(Render,NULL);
42 BEGIN_LOOP(device)
43 if(device->GetInput()->IsPressedKey(KEY_BACKSPACE) == true)
44 flag = false;
45 END_LOOP(device)
46
47 device->Close();
48 device->Drop();
49
50 return 1;
51 }
52
贴图为:
说明使用线程渲染是先断开opengl上下文
然后在线程中再勾住opengl上下文
然后其他操作就一般化了