]> git.jsancho.org Git - c-irrlicht.git/blob - examples/01.HelloWorld.c
Use structs with casting, without classes replication
[c-irrlicht.git] / examples / 01.HelloWorld.c
1 /* c-irrlicht --- C bindings for Irrlicht Engine
2
3    Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of c-irrlicht.
6
7    c-irrlicht is free software; you can redistribute it and/or modify
8    it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 3 of the
10    License, or (at your option) any later version.
11
12    c-irrlicht is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with guile-irrlicht.  If not, see
19    <http://www.gnu.org/licenses/>.
20 */
21
22 #include <cirrlicht/cirrlicht.h>
23 #include <stddef.h>
24
25 int main()
26 {
27   // create irrlicht window
28   irr_core_dimension2d_u32 windowSize = {640, 480};
29   irr_IrrlichtDevice *device =
30     irr_createDevice(irr_video_EDT_SOFTWARE, &windowSize, 16,
31                      false, false, false);
32
33   if (!device)
34     {
35       return 1;
36     }
37
38   // set window caption
39   irr_setWindowCaption(device, "Hello World! - Irrlicht Engine Demo");
40
41   // instances for doing things
42   irr_video_IVideoDriver* driver = irr_getVideoDriver(device);
43   irr_scene_ISceneManager* smgr = irr_getSceneManager(device);
44   irr_gui_IGUIEnvironment* guienv = irr_getGUIEnvironment(device);
45
46   // add a static text
47   irr_core_rect_s32 box = {10, 10, 260, 22};
48   irr_gui_addStaticText(guienv,
49                         "Hello World! This is the Irrlicht Software renderer!",
50                         &box, true, true, NULL, -1, false);
51
52   // load a quake2 mesh
53   irr_scene_IAnimatedMesh* mesh = irr_scene_getMesh(smgr, "media/sydney.md2");
54   if (!mesh)
55     {
56       irr_drop(device);
57       return 1;
58     }
59   irr_scene_IAnimatedMeshSceneNode* node =
60     irr_scene_addAnimatedMeshSceneNode(smgr, mesh, NULL, -1,
61                                        NULL, NULL, NULL, false);
62
63   if (node)
64     {
65       irr_scene_setMaterialFlag(node, irr_video_EMF_LIGHTING, false);
66       irr_scene_setMD2Animation(node, irr_scene_EMAT_STAND);
67       irr_video_ITexture* texture = irr_video_getTexture(driver, "media/sydney.bmp");
68       irr_scene_setMaterialTexture(node, 0, texture);
69     }
70
71   // camera
72   irr_core_vector3df position = {0, 30, -40};
73   irr_core_vector3df lookat = {0, 5, 0};
74   irr_scene_addCameraSceneNode(smgr, NULL, &position, &lookat, -1, true);
75                                              
76   // loop
77   irr_video_SColor bgcolor = MAKE_COLOR(255, 100, 101, 140);
78   while (irr_run(device))
79     {
80       irr_video_beginScene(driver, true, true, &bgcolor, NULL, NULL);
81       irr_gui_drawAll(guienv);
82       irr_scene_drawAll(smgr);
83       irr_video_endScene(driver);
84     }
85
86   irr_drop(device);
87   return 0;
88 }