/* Most of the hard work is done. We only need to create the Irrlicht Engine device and all the buttons, menus and toolbars. We start up the engine as usual, using createDevice(). To make our application catch events, we set our eventreceiver as parameter. As you can see, there is also a call to IrrlichtDevice::setResizeable(). This makes the render window resizeable, which is quite useful for a mesh viewer. */ int main(int argc, char* argv[]) { // ask user for driver video::E_DRIVER_TYPE driverType=driverChoiceConsole(); if (driverType==video::EDT_COUNT) return 1; // create device and exit if creation failed MyEventReceiver receiver; Device = createDevice(driverType, core::dimension2d<u32>(800, 600), 16, false, false, false, &receiver); if (Device == 0) return 1; // could not create selected driver. Device->setResizable(true); Device->setWindowCaption(L"Irrlicht Engine - Loading..."); video::IVideoDriver* driver = Device->getVideoDriver(); IGUIEnvironment* env = Device->getGUIEnvironment(); scene::ISceneManager* smgr = Device->getSceneManager(); smgr->getParameters()->setAttribute(scene::COLLADA_CREATE_SCENE_INSTANCES, true); driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true); smgr->addLightSceneNode(0, core::vector3df(200,200,200), video::SColorf(1.0f,1.0f,1.0f),2000); smgr->setAmbientLight(video::SColorf(0.3f,0.3f,0.3f)); // add our media directory as "search path" Device->getFileSystem()->addFileArchive("../../media/"); /* The next step is to read the configuration file. It is stored in the xml format and looks a little bit like this: @verbatim <?xml version="1.0"?> <config> <startUpModel file="some filename" /> <messageText caption="Irrlicht Engine Mesh Viewer"> Hello! </messageText> </config> @endverbatim We need the data stored in there to be written into the global variables StartUpModelFile, MessageText and Caption. This is now done using the Irrlicht Engine integrated XML parser: */ // read configuration from xml file io::IXMLReader* xml = Device->getFileSystem()->createXMLReader( L"config.xml"); while(xml && xml->read()) { switch(xml->getNodeType()) { case io::EXN_TEXT: // in this xml file, the only text which occurs is the // messageText MessageText = xml->getNodeData(); break; case io::EXN_ELEMENT: { if (core::stringw("startUpModel") == xml->getNodeName()) StartUpModelFile = xml->getAttributeValue(L"file"); else if (core::stringw("messageText") == xml->getNodeName()) Caption = xml->getAttributeValue(L"caption"); } break; default: break; } } if (xml) xml->drop(); // don't forget to delete the xml reader if (argc > 1) StartUpModelFile = argv[1]; /* That wasn't difficult. Now we'll set a nicer font and create the Menu. It is possible to create submenus for every menu item. The call menu->addItem(L"File", -1, true, true); for example adds a new menu Item with the name "File" and the id -1. The following parameter says that the menu item should be enabled, and the last one says, that there should be a submenu. The submenu can now be accessed with menu->getSubMenu(0), because the "File" entry is the menu item with index 0. */ // set a nicer font IGUISkin* skin = env->getSkin(); IGUIFont* font = env->getFont("fonthaettenschweiler.bmp"); if (font) skin->setFont(font); // create menu gui::IGUIContextMenu* menu = env->addMenu(); menu->addItem(L"File", -1, true, true); menu->addItem(L"View", -1, true, true); menu->addItem(L"Camera", -1, true, true); menu->addItem(L"Help", -1, true, true); gui::IGUIContextMenu* submenu; submenu = menu->getSubMenu(0); submenu->addItem(L"Open Model File & Texture...", GUI_ID_OPEN_MODEL); submenu->addItem(L"Set Model Archive...", GUI_ID_SET_MODEL_ARCHIVE); submenu->addItem(L"Load as Octree", GUI_ID_LOAD_AS_OCTREE); submenu->addSeparator(); submenu->addItem(L"Quit", GUI_ID_QUIT); submenu = menu->getSubMenu(1); submenu->addItem(L"sky box visible", GUI_ID_SKY_BOX_VISIBLE, true, false, true); submenu->addItem(L"toggle model debug information", GUI_ID_TOGGLE_DEBUG_INFO, true, true); submenu->addItem(L"model material", -1, true, true ); submenu = submenu->getSubMenu(1); submenu->addItem(L"Off", GUI_ID_DEBUG_OFF); submenu->addItem(L"Bounding Box", GUI_ID_DEBUG_BOUNDING_BOX); submenu->addItem(L"Normals", GUI_ID_DEBUG_NORMALS); submenu->addItem(L"Skeleton", GUI_ID_DEBUG_SKELETON); submenu->addItem(L"Wire overlay", GUI_ID_DEBUG_WIRE_OVERLAY); submenu->addItem(L"Half-Transparent", GUI_ID_DEBUG_HALF_TRANSPARENT); submenu->addItem(L"Buffers bounding boxes", GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES); submenu->addItem(L"All", GUI_ID_DEBUG_ALL); submenu = menu->getSubMenu(1)->getSubMenu(2); submenu->addItem(L"Solid", GUI_ID_MODEL_MATERIAL_SOLID); submenu->addItem(L"Transparent", GUI_ID_MODEL_MATERIAL_TRANSPARENT); submenu->addItem(L"Reflection", GUI_ID_MODEL_MATERIAL_REFLECTION); submenu = menu->getSubMenu(2); submenu->addItem(L"Maya Style", GUI_ID_CAMERA_MAYA); submenu->addItem(L"First Person", GUI_ID_CAMERA_FIRST_PERSON); submenu = menu->getSubMenu(3); submenu->addItem(L"About", GUI_ID_ABOUT); /* Below the menu we want a toolbar, onto which we can place colored buttons and important looking stuff like a senseless combobox. */ // create toolbar gui::IGUIToolBar* bar = env->addToolBar(); video::ITexture* image = driver->getTexture("open.png"); bar->addButton(GUI_ID_BUTTON_OPEN_MODEL, 0, L"Open a model",image, 0, false, true); image = driver->getTexture("tools.png"); bar->addButton(GUI_ID_BUTTON_SHOW_TOOLBOX, 0, L"Open Toolset",image, 0, false, true); image = driver->getTexture("zip.png"); bar->addButton(GUI_ID_BUTTON_SELECT_ARCHIVE, 0, L"Set Model Archive",image, 0, false, true); image = driver->getTexture("help.png"); bar->addButton(GUI_ID_BUTTON_SHOW_ABOUT, 0, L"Open Help", image, 0, false, true); // create a combobox for texture filters gui::IGUIComboBox* box = env->addComboBox(core::rect<s32>(250,4,350,23), bar, GUI_ID_TEXTUREFILTER); box->addItem(L"No filtering"); box->addItem(L"Bilinear"); box->addItem(L"Trilinear"); box->addItem(L"Anisotropic"); box->addItem(L"Isotropic"); /* To make the editor look a little bit better, we disable transparent gui elements, and add an Irrlicht Engine logo. In addition, a text showing the current frames per second value is created and the window caption is changed. */ // disable alpha for (s32 i=0; i<gui::EGDC_COUNT ; ++i) { video::SColor col = env->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); col.setAlpha(255); env->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)i, col); } // add a tabcontrol createToolBox(); // create fps text IGUIStaticText* fpstext = env->addStaticText(L"", core::rect<s32>(400,4,570,23), true, false, bar); IGUIStaticText* postext = env->addStaticText(L"", core::rect<s32>(10,50,470,80),false, false, 0, GUI_ID_POSITION_TEXT); postext->setVisible(false); // set window caption Caption += " - ["; Caption += driver->getName(); Caption += "]"; Device->setWindowCaption(Caption.c_str()); /* That's nearly the whole application. We simply show the about message box at start up, and load the first model. To make everything look better, a skybox is created and a user controled camera, to make the application a little bit more interactive. Finally, everything is drawn in a standard drawing loop. */ // show about message box and load default model if (argc==1) showAboutText(); loadModel(StartUpModelFile.c_str()); // add skybox SkyBox = smgr->addSkyBoxSceneNode( driver->getTexture("irrlicht2_up.jpg"), driver->getTexture("irrlicht2_dn.jpg"), driver->getTexture("irrlicht2_lf.jpg"), driver->getTexture("irrlicht2_rt.jpg"), driver->getTexture("irrlicht2_ft.jpg"), driver->getTexture("irrlicht2_bk.jpg")); // add a camera scene node Camera[0] = smgr->addCameraSceneNodeMaya(); Camera[0]->setFarValue(20000.f); // Maya cameras reposition themselves relative to their target, so target the location // where the mesh scene node is placed. Camera[0]->setTarget(core::vector3df(0,30,0)); Camera[1] = smgr->addCameraSceneNodeFPS(); Camera[1]->setFarValue(20000.f); Camera[1]->setPosition(core::vector3df(0,0,-70)); Camera[1]->setTarget(core::vector3df(0,30,0)); setActiveCamera(Camera[0]); // load the irrlicht engine logo IGUIImage *img = env->addImage(driver->getTexture("irrlichtlogo2.png"), core::position2d<s32>(10, driver->getScreenSize().Height - 128)); // lock the logo's edges to the bottom left corner of the screen img->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT); // remember state so we notice when the window does lose the focus bool hasFocus = Device->isWindowFocused(); // draw everything while(Device->run() && driver) { // Catch focus changes (workaround until Irrlicht has events for this) bool focused = Device->isWindowFocused(); if ( hasFocus && !focused ) onKillFocus(); hasFocus = focused; if (Device->isWindowActive()) { driver->beginScene(true, true, video::SColor(150,50,50,50)); smgr->drawAll(); env->drawAll(); driver->endScene(); // update information about current frame-rate core::stringw str(L"FPS: "); str.append(core::stringw(driver->getFPS())); str += L" Tris: "; str.append(core::stringw(driver->getPrimitiveCountDrawn())); fpstext->setText(str.c_str()); // update information about the active camera scene::ICameraSceneNode* cam = Device->getSceneManager()->getActiveCamera(); str = L"Pos: "; str.append(core::stringw(cam->getPosition().X)); str += L" "; str.append(core::stringw(cam->getPosition().Y)); str += L" "; str.append(core::stringw(cam->getPosition().Z)); str += L" Tgt: "; str.append(core::stringw(cam->getTarget().X)); str += L" "; str.append(core::stringw(cam->getTarget().Y)); str += L" "; str.append(core::stringw(cam->getTarget().Z)); postext->setText(str.c_str()); // update the tool dialog updateToolBox(); } else Device->yield(); } Device->drop(); return 0; }
/*! Startup a Windows Mobile Device */ IrrlichtDevice *startup() { // both software and burnings video can be used E_DRIVER_TYPE driverType = EDT_SOFTWARE; // EDT_BURNINGSVIDEO; // create device IrrlichtDevice *device = 0; #if defined (_IRR_USE_WINDOWS_CE_DEVICE_) // set to standard mobile fullscreen 240x320 device = createDevice(driverType, dimension2d<u32>(240, 320), 16, true ); #else // on PC. use window mode device = createDevice(driverType, dimension2d<u32>(240, 320), 16, false ); #endif if ( 0 == device ) return 0; IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); // set the filesystem relative to the executable #if defined (_IRR_WINDOWS_) { wchar_t buf[255]; GetModuleFileNameW ( 0, buf, 255 ); string<c16> base = buf; base = base.subString ( 0, base.findLast ( '\\' ) + 1 ); device->getFileSystem()->registerFileArchive ( base ); } #endif IGUIStaticText *text = guienv->addStaticText(L"FPS: 25", rect<s32>(140,15,200,30), false, false, 0, 100 ); guienv->addButton(core::rect<int>(200,10,238,30), 0, 2, L"Quit"); // add irrlicht logo guienv->addImage(driver->getTexture("../../media/irrlichtlogo3.png"), core::position2d<s32>(0,-2)); return device; }
/* OK, now for the more interesting part. First, create the Irrlicht device. As in some examples before, we ask the user which driver he wants to use for this example. */ int main() { // create device and exit if creation failed IrrlichtDevice * device = createDevice(EDT_OPENGL,core::dimension2d<u32>(640, 480)); if (device == 0) return 1; // could not create selected driver. /* The creation was successful, now we set the event receiver and store pointers to the driver and to the gui environment. */ device->setWindowCaption(L"Irrlicht Engine - User Interface Demo"); device->setResizable(true); video::IVideoDriver* driver = device->getVideoDriver(); IGUIEnvironment* env = device->getGUIEnvironment(); const io::path mediaPath = getExampleMediaPath(); /* To make the font a little bit nicer, we load an external font and set it as the new default font in the skin. To keep the standard font for tool tip text, we set it to the built-in font. */ IGUISkin* skin = env->getSkin(); IGUIFont* font = env->getFont(mediaPath + "fonthaettenschweiler.bmp"); if (font) skin->setFont(font); skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP); /* We add three buttons. The first one closes the engine. The second creates a window and the third opens a file open dialog. The third parameter is the id of the button, with which we can easily identify the button in the event receiver. */ env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON, L"Quit", L"Exits Program"); env->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON, L"New Window", L"Launches a new Window"); env->addButton(rect<s32>(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON, L"File Open", L"Opens a file"); /* Now, we add a static text and a scrollbar, which modifies the transparency of all gui elements. We set the maximum value of the scrollbar to 255, because that's the maximal value for a color value. Then we create an other static text and a list box. */ env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true); IGUIScrollBar* scrollbar = env->addScrollBar(true, rect<s32>(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR); scrollbar->setMax(255); scrollbar->setPos(255); setSkinTransparency( scrollbar->getPos(), env->getSkin()); // set scrollbar position to alpha value of an arbitrary element scrollbar->setPos(env->getSkin()->getColor(EGDC_WINDOW).getAlpha()); env->addStaticText(L"Logging ListBox:", rect<s32>(10,110,350,130), true); IGUIListBox * listbox = env->addListBox(rect<s32>(10, 140, 350, 210)); env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100)); // Store the appropriate data in a context structure. SAppContext context; context.device = device; context.counter = 0; context.listbox = listbox; // Then create the event receiver, giving it that context structure. MyEventReceiver receiver(context); // And tell the device to use our custom event receiver. device->setEventReceiver(&receiver); /* And at last, we create a nice Irrlicht Engine logo in the top left corner. */ env->addImage(driver->getTexture(mediaPath + "irrlichtlogo2.png"), position2d<int>(10,10)); /* That's all, we only have to draw everything. */ fluid_settings_t* settings; // int arg1 = 1; char buf[512]; // int c, i; int interactive = 1; int midi_in = 1; fluid_player_t* player = NULL; fluid_midi_router_t* router = NULL; //fluid_sequencer_t* sequencer = NULL; fluid_midi_driver_t* mdriver = NULL; fluid_audio_driver_t* adriver = NULL; fluid_synth_t* synth = NULL; #ifdef NETWORK_SUPPORT fluid_server_t* server = NULL; int with_server = 0; #endif char* config_file = NULL; int audio_groups = 0; int audio_channels = 0; int dump = 0; int fast_render = 0; static const char optchars[] = "a:C:c:dE:f:F:G:g:hijK:L:lm:nO:o:p:R:r:sT:Vvz:"; #ifdef LASH_ENABLED int connect_lash = 1; int enabled_lash = 0; /* set to TRUE if lash gets enabled */ fluid_lash_args_t *lash_args; lash_args = fluid_lash_extract_args (&argc, &argv); #endif settings = new_fluid_settings(); /* The 'groups' setting is relevant for LADSPA operation and channel mapping * in rvoice_mixer. * If not given, set number groups to number of audio channels, because * they are the same (there is nothing between synth output and 'sound card') */ if ((audio_groups == 0) && (audio_channels != 0)) { audio_groups = audio_channels; } if (audio_groups != 0) { fluid_settings_setint(settings, "synth.audio-groups", audio_groups); } if (fast_render) { midi_in = 0; interactive = 0; #ifdef NETWORK_SUPPORT with_server = 0; #endif fluid_settings_setstr(settings, "player.timing-source", "sample"); fluid_settings_setint(settings, "synth.lock-memory", 0); } /* create the synthesizer */ synth = new_fluid_synth(settings); if (synth == NULL) { fprintf(stderr, "Failed to create the synthesizer\n"); exit(-1); } /* load the soundfonts (check that all non options are SoundFont or MIDI files) */ // for (i = arg1; i < argc; i++) { if (fluid_is_soundfont(psoundfont)) { if (fluid_synth_sfload(synth, psoundfont, 1) == -1) fprintf(stderr, "Failed to load the SoundFont %s\n", psoundfont); } else if (!fluid_is_midifile(psoundfont)) fprintf (stderr, "Parameter '%s' not a SoundFont or MIDI file or error occurred identifying it.\n", psoundfont); /* start the synthesis thread */ if (!fast_render) { fluid_settings_setstr(settings, "audio.driver", "alsa"); adriver = new_fluid_audio_driver(settings, synth); if (adriver == NULL) { fprintf(stderr, "Failed to create the audio driver\n"); // goto cleanup; } } /* start the midi router and link it to the synth */ #if WITH_MIDI if (midi_in) { /* In dump mode, text output is generated for events going into and out of the router. * The example dump functions are put into the chain before and after the router.. */ //sequencer = new_fluid_sequencer2(0); router = new_fluid_midi_router( settings, dump ? fluid_midi_dump_postrouter : fluid_synth_handle_midi_event, (void*)synth); if (router == NULL) { fprintf(stderr, "Failed to create the MIDI input router; no MIDI input\n" "will be available. You can access the synthesizer \n" "through the console.\n"); } else { mdriver = new_fluid_midi_driver( settings, dump ? fluid_midi_dump_prerouter : fluid_midi_router_handle_midi_event, (void*) router); if (mdriver == NULL) { fprintf(stderr, "Failed to create the MIDI thread; no MIDI input\n" "will be available. You can access the synthesizer \n" "through the console.\n"); } } } #endif /* play the midi fildes, if any */ // for (i = arg1; i < argc; i++) { if (fluid_is_midifile(psong)) { if (player == NULL) { player = new_fluid_player(synth); if (player == NULL) { fprintf(stderr, "Failed to create the midifile player.\n" "Continuing without a player.\n"); // break; } } fluid_player_add(player, psong); } // } if (player != NULL) { if (fluid_synth_get_sfont(synth, 0) == NULL) { /* Try to load the default soundfont if no soundfont specified */ char *s; if (fluid_settings_dupstr(settings, "synth.default-soundfont", &s) != FLUID_OK) s = NULL; if ((s != NULL) && (s[0] != '\0')) fluid_synth_sfload(synth, s, 1); FLUID_FREE(s); } fluid_player_play(player); } cmd_handler = new_fluid_cmd_handler(synth, router); if (cmd_handler == NULL) { fprintf(stderr, "Failed to create the command handler\n"); // goto cleanup; } /* try to load the user or system configuration */ if (config_file != NULL) { fluid_source(cmd_handler, config_file); } else if (fluid_get_userconf(buf, sizeof(buf)) != NULL) { fluid_source(cmd_handler, buf); } else if (fluid_get_sysconf(buf, sizeof(buf)) != NULL) { fluid_source(cmd_handler, buf); } /* run the server, if requested */ #ifdef NETWORK_SUPPORT if (with_server) { server = new_fluid_server(settings, synth, router); if (server == NULL) { fprintf(stderr, "Failed to create the server.\n" "Continuing without it.\n"); } } #endif #ifdef LASH_ENABLED if (enabled_lash) fluid_lash_create_thread (synth); #endif while(device->run() && driver) if (device->isWindowActive()) { driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0,200,200,200)); env->drawAll(); //fast_render; // if (fast_render) { // char *filename; // if (player == NULL) { // fprintf(stderr, "No midi file specified!\n"); // // fluid_player_play(player); //// goto cleanup; // } // // fluid_settings_dupstr (settings, "audio.file.name", &filename); // printf ("Rendering audio to file '%s'..\n", filename); // if (filename) FLUID_FREE (filename); // // fast_render_loop(settings, synth, player); // } /* Play a note */ // fluid_synth_noteon(synth, 0, 60, 100); // printf("Press \"Enter\" to stop: "); // fgetc(stdin); // printf("done\n"); device->sleep(129); driver->endScene(); } if (adriver) { delete_fluid_audio_driver(adriver); } if (synth) { delete_fluid_synth(synth); } if (settings) { delete_fluid_settings(settings); } device->drop(); return 0; }
/* Ok, now for the more interesting part. First, create the Irrlicht device. As in some examples before, we ask the user which driver he wants to use for this example: */ int main() { // ask user for driver video::E_DRIVER_TYPE driverType=driverChoiceConsole(); if (driverType==video::EDT_COUNT) return 1; // create device and exit if creation failed IrrlichtDevice * device = createDevice(driverType, core::dimension2d<u32>(640, 480)); if (device == 0) return 1; // could not create selected driver. /* The creation was successful, now we set the event receiver and store pointers to the driver and to the gui environment. */ device->setWindowCaption(L"Irrlicht Engine - User Interface Demo"); device->setResizable(true); video::IVideoDriver* driver = device->getVideoDriver(); IGUIEnvironment* env = device->getGUIEnvironment(); /* To make the font a little bit nicer, we load an external font and set it as the new default font in the skin. To keep the standard font for tool tip text, we set it to the built-in font. */ IGUISkin* skin = env->getSkin(); IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp"); if (font) skin->setFont(font); skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP); /* We add three buttons. The first one closes the engine. The second creates a window and the third opens a file open dialog. The third parameter is the id of the button, with which we can easily identify the button in the event receiver. */ env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON, L"Quit", L"Exits Program"); env->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON, L"New Window", L"Launches a new Window"); env->addButton(rect<s32>(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON, L"File Open", L"Opens a file"); /* Now, we add a static text and a scrollbar, which modifies the transparency of all gui elements. We set the maximum value of the scrollbar to 255, because that's the maximal value for a color value. Then we create an other static text and a list box. */ env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true); IGUIScrollBar* scrollbar = env->addScrollBar(true, rect<s32>(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR); scrollbar->setMax(255); scrollbar->setPos(255); setSkinTransparency( scrollbar->getPos(), env->getSkin()); // set scrollbar position to alpha value of an arbitrary element scrollbar->setPos(env->getSkin()->getColor(EGDC_WINDOW).getAlpha()); env->addStaticText(L"Logging ListBox:", rect<s32>(10,110,350,130), true); IGUIListBox * listbox = env->addListBox(rect<s32>(10, 140, 350, 210)); env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100)); // Store the appropriate data in a context structure. SAppContext context; context.device = device; context.counter = 0; context.listbox = listbox; // Then create the event receiver, giving it that context structure. MyEventReceiver receiver(context); // And tell the device to use our custom event receiver. device->setEventReceiver(&receiver); /* And at last, we create a nice Irrlicht Engine logo in the top left corner. */ env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"), position2d<int>(10,10)); /* That's all, we only have to draw everything. */ while(device->run() && driver) if (device->isWindowActive()) { driver->beginScene(true, true, SColor(0,200,200,200)); env->drawAll(); driver->endScene(); } device->drop(); return 0; }
bool EventReciever::OnEvent(const SEvent& event) { switch (event.EventType) { case EET_KEY_INPUT_EVENT: { keyDown[event.KeyInput.Key] = event.KeyInput.PressedDown; break; } case EET_GUI_EVENT: { s32 id = event.GUIEvent.Caller->getID(); IGUIEnvironment* env = context.device->getGUIEnvironment(); switch (event.GUIEvent.EventType) { case EGET_BUTTON_CLICKED: { switch (id) { case GUI_ID_PLAY_BUTTON: env->clear(); *(context.gameStatePtr) = WAVE_1; break; case GUI_ID_INSTRUCTIONS_BUTTON: env->clear(); env->addImage(context.device->getVideoDriver()->getTexture("Textures/Instructions.bmp"), vector2d<s32>(0, 0), false); env->addButton(rect<s32>(270, 380, 370, 420), NULL, GUI_ID_INSTRUCTIONS_BACK_BUTTON, L"Back"); break; case GUI_ID_INSTRUCTIONS_BACK_BUTTON: env->clear(); env->addImage(context.device->getVideoDriver()->getTexture("Textures/Menu.bmp"), vector2d<s32>(0, 0), false); env->addButton(rect<s32>(210, 100, 450, 170), NULL, GUI_ID_PLAY_BUTTON, L"Play"); env->addButton(rect<s32>(210, 200, 450, 270), NULL, GUI_ID_INSTRUCTIONS_BUTTON, L"Instructions"); env->addButton(rect<s32>(210, 300, 450, 370), NULL, GUI_ID_CONTROLS_BUTTON, L"Controls"); env->addButton(rect<s32>(210, 400, 450, 470), NULL, GUI_ID_QUIT_BUTTON, L"Exit"); break; case GUI_ID_CONTROLS_BUTTON: env->clear(); env->addImage(context.device->getVideoDriver()->getTexture("Textures/Controls.bmp"), vector2d<s32>(0, 0), false); env->addButton(rect<s32>(270, 380, 370, 420), NULL, GUI_ID_CONTROLS_BACK_BUTTON, L"Back"); break; case GUI_ID_CONTROLS_BACK_BUTTON: env->clear(); env->addImage(context.device->getVideoDriver()->getTexture("Textures/Menu.bmp"), vector2d<s32>(0, 0), false); env->addButton(rect<s32>(210, 100, 450, 170), NULL, GUI_ID_PLAY_BUTTON, L"Play"); env->addButton(rect<s32>(210, 200, 450, 270), NULL, GUI_ID_INSTRUCTIONS_BUTTON, L"Instructions"); env->addButton(rect<s32>(210, 300, 450, 370), NULL, GUI_ID_CONTROLS_BUTTON, L"Controls"); env->addButton(rect<s32>(210, 400, 450, 470), NULL, GUI_ID_QUIT_BUTTON, L"Exit"); break; case GUI_ID_QUIT_BUTTON: env->clear(); context.device->closeDevice(); break; } } } } default: break; } return false; }
/* OK, now for the more interesting part. First, create the Irrlicht device. As in some examples before, we ask the user which driver he wants to use for this example. */ int main() { // create device and exit if creation failed IrrlichtDevice * device = createDevice(EDT_OPENGL,core::dimension2d<u32>(640, 480)); if (device == 0) return 1; // could not create selected driver. /* The creation was successful, now we set the event receiver and store pointers to the driver and to the gui environment. */ device->setWindowCaption(L"Irrlicht Engine - User Interface Demo"); device->setResizable(true); video::IVideoDriver* driver = device->getVideoDriver(); IGUIEnvironment* env = device->getGUIEnvironment(); const io::path mediaPath = getExampleMediaPath(); /* To make the font a little bit nicer, we load an external font and set it as the new default font in the skin. To keep the standard font for tool tip text, we set it to the built-in font. */ IGUISkin* skin = env->getSkin(); IGUIFont* font = env->getFont(mediaPath + "fonthaettenschweiler.bmp"); if (font) skin->setFont(font); skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP); /* We add three buttons. The first one closes the engine. The second creates a window and the third opens a file open dialog. The third parameter is the id of the button, with which we can easily identify the button in the event receiver. */ env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON, L"Quit", L"Exits Program"); env->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON, L"New Window", L"Launches a new Window"); env->addButton(rect<s32>(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON, L"File Open", L"Opens a file"); /* Now, we add a static text and a scrollbar, which modifies the transparency of all gui elements. We set the maximum value of the scrollbar to 255, because that's the maximal value for a color value. Then we create an other static text and a list box. */ env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true); IGUIScrollBar* scrollbar = env->addScrollBar(true, rect<s32>(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR); scrollbar->setMax(255); scrollbar->setPos(255); setSkinTransparency( scrollbar->getPos(), env->getSkin()); // set scrollbar position to alpha value of an arbitrary element scrollbar->setPos(env->getSkin()->getColor(EGDC_WINDOW).getAlpha()); env->addStaticText(L"Logging ListBox:", rect<s32>(10,110,350,130), true); IGUIListBox * listbox = env->addListBox(rect<s32>(10, 140, 350, 210)); env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100)); // Store the appropriate data in a context structure. SAppContext context; context.device = device; context.counter = 0; context.listbox = listbox; // Then create the event receiver, giving it that context structure. MyEventReceiver receiver(context); // And tell the device to use our custom event receiver. device->setEventReceiver(&receiver); /* And at last, we create a nice Irrlicht Engine logo in the top left corner. */ env->addImage(driver->getTexture(mediaPath + "irrlichtlogo2.png"), position2d<int>(10,10)); /* That's all, we only have to draw everything. */ fluid_settings_t* settings; fluid_synth_t* synth = NULL; fluid_audio_driver_t* adriver = NULL; int err = 0; struct fx_data_t fx_data; // // if (argc != 3) { // fprintf(stderr, "Usage: fluidsynth_simple [soundfont] [gain]\n"); // return 1; // } // /* Create the settings object. This example uses the default * values for the settings. */ settings = new_fluid_settings(); if (settings == NULL) { fprintf(stderr, "Failed to create the settings\n"); err = 2; goto cleanup; } /* Create the synthesizer */ synth = new_fluid_synth(settings); if (synth == NULL) { fprintf(stderr, "Failed to create the synthesizer\n"); err = 3; goto cleanup; } /* Load the soundfont */ // if (fluid_synth_sfload(synth, "soundfonts/example.sf2", 1) == -1) { if (fluid_synth_sfload(synth, "soundfonts/VintageDreamsWaves-v2.sf2", 1) == -1) { // if (fluid_synth_sfload(synth, "soundfonts/VintageDreamsWaves-v2.sf3", 1) == -1) { // if (fluid_synth_sfload(synth, "soundfonts/philharmonia_violin_short.gig", 1) == -1) { //was to check and see if it had gig support but no. fprintf(stderr, "Failed to load the SoundFont\n"); err = 4; goto cleanup; } /* Fill in the data of the effects unit */ fx_data.synth = synth; fx_data.gain = 10; //atof(argv[2]); /* Create the audio driver. As soon as the audio driver is * created, the synthesizer can be played. */ fluid_settings_setstr(settings, "audio.driver", "alsa"); adriver = new_fluid_audio_driver2(settings, fx_function, (void*) &fx_data); if (adriver == NULL) { fprintf(stderr, "Failed to create the audio driver\n"); err = 5; goto cleanup; } while(device->run() && driver) if (device->isWindowActive()) { driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0,200,200,200)); env->drawAll(); /* Play a note */ fluid_synth_noteon(synth, 0, 60, 100); // printf("Press \"Enter\" to stop: "); // fgetc(stdin); // printf("done\n"); driver->endScene(); } cleanup: if (adriver) { delete_fluid_audio_driver(adriver); } if (synth) { delete_fluid_synth(synth); } if (settings) { delete_fluid_settings(settings); } device->drop(); return 0; }