diff options
Diffstat (limited to 'ClientHamr/extantz/crappisspuke.cpp')
-rw-r--r-- | ClientHamr/extantz/crappisspuke.cpp | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/ClientHamr/extantz/crappisspuke.cpp b/ClientHamr/extantz/crappisspuke.cpp new file mode 100644 index 0000000..16513fa --- /dev/null +++ b/ClientHamr/extantz/crappisspuke.cpp | |||
@@ -0,0 +1,240 @@ | |||
1 | |||
2 | #include <irrlicht.h> | ||
3 | |||
4 | /* | ||
5 | In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if | ||
6 | you want to use a class of the engine, you have to write irr:: before the name | ||
7 | of the class. For example to use the IrrlichtDevice write: irr::IrrlichtDevice. | ||
8 | To get rid of the irr:: in front of the name of every class, we tell the | ||
9 | compiler that we use that namespace from now on, and we will not have to write | ||
10 | irr:: anymore. | ||
11 | */ | ||
12 | using namespace irr; | ||
13 | |||
14 | /* | ||
15 | There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can | ||
16 | read a detailed description of them in the documentation by clicking on the top | ||
17 | menu item 'Namespace List' or by using this link: | ||
18 | http://irrlicht.sourceforge.net/docu/namespaces.html | ||
19 | Like the irr namespace, we do not want these 5 sub namespaces now, to keep this | ||
20 | example simple. Hence, we tell the compiler again that we do not want always to | ||
21 | write their names. | ||
22 | */ | ||
23 | using namespace core; | ||
24 | using namespace scene; | ||
25 | using namespace video; | ||
26 | |||
27 | // This is here so that we can use the name spacing above, and not have to #ifdef lots of shit. | ||
28 | #include "extantz.h" | ||
29 | |||
30 | |||
31 | SExposedVideoData videoData; | ||
32 | |||
33 | IAnimatedMeshSceneNode* node; | ||
34 | // This is the movemen speed in units per second. | ||
35 | const f32 MOVEMENT_SPEED = 5.f; | ||
36 | // In order to do framerate independent movement, we have to know | ||
37 | // how long it was since the last frame | ||
38 | u32 then; | ||
39 | |||
40 | #ifdef __cplusplus | ||
41 | extern "C" { | ||
42 | #endif | ||
43 | |||
44 | EAPI int startIrr(GLData *gld) | ||
45 | { | ||
46 | SIrrlichtCreationParameters params; | ||
47 | IrrlichtDevice *device; | ||
48 | IVideoDriver *driver; | ||
49 | ISceneManager *smgr; | ||
50 | |||
51 | if (!gld->useIrr) | ||
52 | return 0; | ||
53 | |||
54 | void *display = NULL; | ||
55 | unsigned long sfc = 0; | ||
56 | void *ctx = NULL; | ||
57 | |||
58 | evas_gl_make_current(gld->evasgl, gld->sfc, gld->ctx); | ||
59 | |||
60 | display = glXGetCurrentDisplay(); | ||
61 | sfc = ecore_evas_window_get(ecore_evas_ecore_evas_get(evas_object_evas_get(gld->win))); | ||
62 | ctx = glXGetCurrentContext(); | ||
63 | |||
64 | /* For using a pre existing X11 window (with optional OpenGL). */ | ||
65 | videoData = SExposedVideoData(); | ||
66 | videoData.OpenGLLinux.X11Display = display; // void * - Connection to the X server. | ||
67 | videoData.OpenGLLinux.X11Window = sfc; // unsigned long - Specifies a GLX drawable. Must be either an X window ID or a GLX pixmap ID. | ||
68 | videoData.OpenGLLinux.X11Context = ctx; // void * - Specifies a GLX rendering context that is to be attached to drawable. | ||
69 | |||
70 | /* | ||
71 | The most important function of the engine is the createDevice() | ||
72 | function. The IrrlichtDevice is created by it, which is the root | ||
73 | object for doing anything with the engine. createDevice() has 7 | ||
74 | parameters: | ||
75 | |||
76 | - deviceType: Type of the device. This can currently be the Null-device, | ||
77 | one of the two software renderers, D3D8, D3D9, or OpenGL. In this | ||
78 | example we use EDT_SOFTWARE, but to try out, you might want to | ||
79 | change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, | ||
80 | EDT_DIRECT3D9, or EDT_OPENGL. | ||
81 | |||
82 | - windowSize: Size of the Window or screen in FullScreenMode to be | ||
83 | created. In this example we use 640x480. | ||
84 | |||
85 | - bits: Amount of color bits per pixel. This should be 16 or 32. The | ||
86 | parameter is often ignored when running in windowed mode. | ||
87 | |||
88 | - fullscreen: Specifies if we want the device to run in fullscreen mode | ||
89 | or not. | ||
90 | |||
91 | - stencilbuffer: Specifies if we want to use the stencil buffer (for | ||
92 | drawing shadows). | ||
93 | |||
94 | - vsync: Specifies if we want to have vsync enabled, this is only useful | ||
95 | in fullscreen mode. | ||
96 | |||
97 | - eventReceiver: An object to receive events. We do not want to use this | ||
98 | parameter here, and set it to 0. | ||
99 | |||
100 | Always check the return value to cope with unsupported drivers, | ||
101 | dimensions, etc. | ||
102 | */ | ||
103 | |||
104 | params.DeviceType = EIDT_X11; // EIDT_BEST might be preferable. | ||
105 | if (ctx) | ||
106 | params.DriverType = video::EDT_OPENGL; | ||
107 | else | ||
108 | params.DriverType = video::EDT_BURNINGSVIDEO; | ||
109 | params.WindowSize = dimension2d<u32>(gld->sfc_w, gld->sfc_h); | ||
110 | params.Bits = 32; // Ignored in windowed mode? | ||
111 | params.ZBufferBits = 16; // Default 16. | ||
112 | params.Fullscreen = false; // The default anyway. | ||
113 | params.Stencilbuffer = false; // For shadows. | ||
114 | params.Vsync = false; | ||
115 | params.WithAlphaChannel = true; | ||
116 | params.IgnoreInput = true; | ||
117 | params.EventReceiver = 0; | ||
118 | params.WindowId = (void *) videoData.OpenGLLinux.X11Window; | ||
119 | params.VideoData = &videoData; | ||
120 | |||
121 | device = createDeviceEx(params); | ||
122 | |||
123 | if (!device) | ||
124 | return 0; | ||
125 | gld->device = device; | ||
126 | |||
127 | /* | ||
128 | Get a pointer to the VideoDriver and the SceneManager so that we do not always have to write | ||
129 | device->getVideoDriver() or device->getSceneManager(). | ||
130 | */ | ||
131 | driver = device->getVideoDriver(); gld->driver = driver; | ||
132 | smgr = device->getSceneManager(); gld->smgr = smgr; | ||
133 | |||
134 | /* | ||
135 | To show something interesting, we load a Quake 2 model and display it. | ||
136 | We only have to get the Mesh from the Scene Manager with getMesh() and add | ||
137 | a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We | ||
138 | check the return value of getMesh() to become aware of loading problems | ||
139 | and other errors. | ||
140 | |||
141 | Instead of writing the filename sydney.md2, it would also be possible | ||
142 | to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any | ||
143 | other supported file format. By the way, that cool Quake 2 model | ||
144 | called sydney was modelled by Brian Collins. | ||
145 | */ | ||
146 | IAnimatedMesh* mesh = smgr->getMesh("media/sydney.md2"); | ||
147 | if (!mesh) | ||
148 | { | ||
149 | device->drop(); | ||
150 | return 0; | ||
151 | } | ||
152 | node = smgr->addAnimatedMeshSceneNode(mesh); | ||
153 | |||
154 | /* | ||
155 | To let the mesh look a little bit nicer, we change its material. We | ||
156 | disable lighting because we do not have a dynamic light in here, and | ||
157 | the mesh would be totally black otherwise. Then we set the frame loop, | ||
158 | such that the predefined STAND animation is used. And last, we apply a | ||
159 | texture to the mesh. Without it the mesh would be drawn using only a | ||
160 | color. | ||
161 | */ | ||
162 | if (node) | ||
163 | { | ||
164 | node->setMaterialFlag(EMF_LIGHTING, false); | ||
165 | node->setMD2Animation(scene::EMAT_STAND); | ||
166 | node->setMaterialTexture(0, driver->getTexture("media/sydney.bmp")); | ||
167 | } | ||
168 | |||
169 | /* | ||
170 | To look at the mesh, we place a camera into 3d space at the position | ||
171 | (0, 30, -40). The camera looks from there to (0,5,0), which is | ||
172 | approximately the place where our md2 model is. | ||
173 | */ | ||
174 | smgr->addCameraSceneNode(0, vector3df(0, 30, -40), vector3df(0, 5, 0)); | ||
175 | |||
176 | then = device->getTimer()->getTime(); | ||
177 | return 1; | ||
178 | } | ||
179 | |||
180 | EAPI void drawIrr_start(GLData *gld) | ||
181 | { | ||
182 | if (gld->useIrr) | ||
183 | { | ||
184 | IrrlichtDevice *device = gld->device; | ||
185 | IVideoDriver *driver = gld->driver; | ||
186 | ISceneManager *smgr = gld->smgr; | ||
187 | |||
188 | // Increase virtual timer time, instead of device->run() if doing our own input processing. | ||
189 | device->getTimer()->tick(); | ||
190 | |||
191 | // Work out a frame delta time. | ||
192 | const u32 now = device->getTimer()->getTime(); | ||
193 | const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds | ||
194 | then = now; | ||
195 | |||
196 | core::vector3df nodePosition = node->getPosition(); | ||
197 | // nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime; | ||
198 | node->setPosition(nodePosition); | ||
199 | |||
200 | /* | ||
201 | Anything can be drawn between a beginScene() and an endScene() | ||
202 | call. The beginScene() call clears the screen with a color and | ||
203 | the depth buffer, if desired. Then we let the Scene Manager and | ||
204 | the GUI Environment draw their content. With the endScene() | ||
205 | call everything is presented on the screen. | ||
206 | */ | ||
207 | driver->beginScene(true, true, SColor(255, 100, 101, 140), videoData, NULL); // This does the context change, then clearBuffers() | ||
208 | smgr->drawAll(); | ||
209 | } | ||
210 | } | ||
211 | |||
212 | EAPI void drawIrr_end(GLData *gld) | ||
213 | { | ||
214 | IVideoDriver *driver = gld->driver; | ||
215 | |||
216 | if (gld->useIrr) | ||
217 | driver->endScene(); | ||
218 | } | ||
219 | |||
220 | EAPI void finishIrr(GLData *gld) | ||
221 | { | ||
222 | IrrlichtDevice *device = gld->device; | ||
223 | |||
224 | /* | ||
225 | After we are done with the render loop, we have to delete the Irrlicht | ||
226 | Device created before with createDevice(). In the Irrlicht Engine, you | ||
227 | have to delete all objects you created with a method or function which | ||
228 | starts with 'create'. The object is simply deleted by calling ->drop(). | ||
229 | See the documentation at irr::IReferenceCounted::drop() for more | ||
230 | information. | ||
231 | */ | ||
232 | if (gld->useIrr) | ||
233 | device->drop(); | ||
234 | } | ||
235 | |||
236 | |||
237 | #ifdef __cplusplus | ||
238 | } | ||
239 | #endif | ||
240 | |||