]> git.jsancho.org Git - c-irrlicht.git/blob - examples/01.HelloWorld.c
HelloWorld example
[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                      0, 0, 0);
32
33   if (!device)
34     {
35       return 1;
36     }
37
38   // set window caption
39   irr_IrrlichtDevice_setWindowCaption(device, "Hello World! - Irrlicht Engine Demo");
40
41   // instances for doing things
42   irr_video_IVideoDriver* driver = irr_IrrlichtDevice_getVideoDriver(device);
43   irr_scene_ISceneManager* smgr = irr_IrrlichtDevice_getSceneManager(device);
44   irr_gui_IGUIEnvironment* guienv = irr_IrrlichtDevice_getGUIEnvironment(device);
45
46   // add a static text
47   irr_core_rect_s32 box = {10, 10, 260, 22};
48   irr_gui_IGUIEnvironment_addStaticText(guienv,
49                                         "Hello World! This is the Irrlicht Software renderer!",
50                                         &box, 1, 1, NULL, -1, 0);
51
52   // load a quake2 mesh
53   irr_scene_IAnimatedMesh* mesh = irr_scene_ISceneManager_getMesh(smgr, "media/sydney.md2");
54   if (!mesh)
55     {
56       irr_IrrlichtDevice_drop(device);
57       return 1;
58     }
59   irr_scene_IAnimatedMeshSceneNode* node =
60     irr_scene_ISceneManager_addAnimatedMeshSceneNode(smgr, mesh, NULL, -1,
61                                                      NULL, NULL, NULL, 0);
62
63   if (node)
64     {
65       irr_scene_IAnimatedMeshSceneNode_setMaterialFlag(node, irr_video_EMF_LIGHTING, 0);
66       irr_scene_IAnimatedMeshSceneNode_setMD2Animation(node, irr_scene_EMAT_STAND);
67       irr_video_ITexture* texture = irr_video_IVideoDriver_getTexture(driver,
68                                                                       "media/sydney.bmp");
69       irr_scene_IAnimatedMeshSceneNode_setMaterialTexture(node, 0, texture);
70     }
71
72   // camera
73   irr_core_vector3df position = {0, 30, -40};
74   irr_core_vector3df lookat = {0, 5, 0};
75   irr_scene_ISceneManager_addCameraSceneNode(smgr, NULL, &position, &lookat,
76                                              -1, 1);
77                                              
78   // loop
79   irr_video_SColor bgcolor = {255, 100, 101, 140};
80   while (irr_IrrlichtDevice_run(device))
81     {
82       irr_video_IVideoDriver_beginScene(driver, 1, 1, &bgcolor, NULL, NULL);
83       irr_gui_IGUIEnvironment_drawAll(guienv);
84       irr_scene_ISceneManager_drawAll(smgr);
85       irr_video_IVideoDriver_endScene(driver);
86     }
87
88   irr_IrrlichtDevice_drop(device);
89   return 0;
90 }