mirror of https://github.com/Poikilos/b3view
first version that works without font
parent
d9643844f1
commit
94e3b8f883
27
CHANGELOG.md
27
CHANGELOG.md
|
@ -1,6 +1,29 @@
|
|||
# Changelog
|
||||
|
||||
## [git] - 2019-03-06
|
||||
(first poikilos changes, based on https://github.com/egrath)
|
||||
(first poikilos commit, based on https://github.com/egrath)
|
||||
### Added
|
||||
(CGUITTFont methods are in CGUITTFont class unless otherwise specified)
|
||||
* README.md
|
||||
* .gitignore (a [Qt .gitignore](https://github.com/github/gitignore/blob/master/Qt.gitignore))
|
||||
|
||||
### Changed
|
||||
* changed `#include <irrlicht.h>` to `#include <irrlicht/irrlicht.h>`
|
||||
* added Qt .gitignore
|
||||
* fixed instances of "0 as null pointer constant" (changed to `nullptr`)
|
||||
* changed inconsistent use of spaces and tabs (changed tabs to 4 spaces)
|
||||
* (UserInterface.cpp) fixed "logical not is only applied to the left hand side of this comparison..." (put parenthesis around `event.EventType == EET_GUI_EVENT`)
|
||||
* Silently degrade to pixel font if font file cannot be read (fixes
|
||||
Segmentation Fault when font file cannot be read).
|
||||
* check for nullptr before using:
|
||||
* (CGUITTFont.cpp) `tt_face->face` in `getWidthFromCharacter`,
|
||||
`getGlyphByChar` (return 0 as bad as per convention:
|
||||
existing code already checks for 0--see
|
||||
`getWidthFromCharacter`), `getKerningWidth`,
|
||||
`draw`, `attach` (also don't copy null by
|
||||
reference there--instead, set to nullptr if source is nullptr)
|
||||
* check length of array before using
|
||||
* (CGUITTFont.cpp) elements of `Glyph` array (type `core::array<CGUITTGlyph>`) in `getHeightFromCharacter`
|
||||
* (CGUITTFont.cpp) check whether file can be read in `CGUITTFace::load` before proceeding
|
||||
|
||||
### Removed
|
||||
* arial.tff removed, since it may be the "real" Arial font, which has a proprietary license
|
||||
|
|
16
Engine.cpp
16
Engine.cpp
|
@ -15,7 +15,7 @@ void Engine::setupScene()
|
|||
m_Scene->setAmbientLight( SColorf( 0.2f, 0.2f, 0.2f ));
|
||||
|
||||
// Setup Camera
|
||||
ICameraSceneNode *camera = m_Scene->addCameraSceneNode( 0, vector3df( 0, 0, -10 ), vector3df() );
|
||||
ICameraSceneNode *camera = m_Scene->addCameraSceneNode( nullptr, vector3df( 0, 0, -10 ), vector3df() );
|
||||
camera->setAspectRatio(( f32 ) m_Driver->getScreenSize().Width / m_Driver->getScreenSize().Height );
|
||||
}
|
||||
|
||||
|
@ -110,9 +110,9 @@ s32 Engine::getNumberOfVertices()
|
|||
Engine::Engine()
|
||||
{
|
||||
#if WIN32
|
||||
m_Device = createDevice( EDT_DIRECT3D9, dimension2d<u32>( 1024, 768 ), 32, false, false, false, 0 );
|
||||
m_Device = createDevice( EDT_DIRECT3D9, dimension2d<u32>( 1024, 768 ), 32, false, false, false, nullptr );
|
||||
#else
|
||||
m_Device = createDevice( EDT_OPENGL, dimension2d<u32>( 1024, 768 ), 32, false, false, false, 0 );
|
||||
m_Device = createDevice( EDT_OPENGL, dimension2d<u32>( 1024, 768 ), 32, false, false, false, nullptr );
|
||||
#endif
|
||||
m_Device->setResizable( true );
|
||||
|
||||
|
@ -122,8 +122,8 @@ Engine::Engine()
|
|||
m_Driver = m_Device->getVideoDriver();
|
||||
m_Scene = m_Device->getSceneManager();
|
||||
|
||||
wstringstream windowTitle;
|
||||
windowTitle << L"Blitz3D Viewer [" << m_Driver->getName() << L"]";
|
||||
wstringstream windowTitle;
|
||||
windowTitle << L"Blitz3D Viewer [" << m_Driver->getName() << L"]";
|
||||
m_Device->setWindowCaption( windowTitle.str().c_str() );
|
||||
|
||||
setupScene();
|
||||
|
@ -140,12 +140,14 @@ Engine::Engine()
|
|||
m_AxisFontFace = new CGUITTFace();
|
||||
m_AxisFontFace->load( "arial.ttf" );
|
||||
m_AxisFont = new CGUITTFont( m_UserInterface->getGUIEnvironment() );
|
||||
assert(m_AxisFontFace != nullptr);
|
||||
assert(m_AxisFontFace->face != nullptr);
|
||||
m_AxisFont->attach( m_AxisFontFace, 14 );
|
||||
m_AxisFont->AntiAlias = false;
|
||||
|
||||
// Set Engine enabled
|
||||
m_RunEngine = true;
|
||||
m_LoadedMesh = 0;
|
||||
m_LoadedMesh = nullptr;
|
||||
|
||||
// Store actual window size
|
||||
m_WindowSize = new dimension2d<u32>();
|
||||
|
@ -163,7 +165,7 @@ Engine::~Engine()
|
|||
|
||||
void Engine::loadMesh( const wstring &fileName )
|
||||
{
|
||||
if( m_LoadedMesh != 0 )
|
||||
if( m_LoadedMesh != nullptr )
|
||||
m_LoadedMesh->remove();
|
||||
|
||||
m_LoadedMesh = m_Scene->addAnimatedMeshSceneNode( m_Scene->getMesh( fileName.c_str() ));
|
||||
|
|
2
Engine.h
2
Engine.h
|
@ -68,7 +68,7 @@ public:
|
|||
~Engine();
|
||||
|
||||
void run();
|
||||
void loadMesh( const wstring &fileName );
|
||||
void loadMesh( const wstring &fileName );
|
||||
void setMeshDisplayMode( bool wireframe = false, bool lighting = true );
|
||||
};
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ EventHandler::~EventHandler()
|
|||
bool EventHandler::addEventReceiver( EventReceiverType type, IEventReceiver *receiver )
|
||||
{
|
||||
m_EventReceivers->insert( make_pair( type, receiver ));
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// IEventReceiver
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# b3view
|
||||
View B3D files (and possibly other files supported by Irrlicht).
|
||||
|
||||
This is a modernized fork by poikilos (see CHANGELOG.md).
|
||||
|
||||
## Installation
|
||||
* Open .pro file in Qt Creator
|
||||
* Build & Run (if you have trouble compiling, see
|
||||
[filehandoff#compiling-issues](https://github.com/poikilos/filehandoff#compiling-issues))
|
||||
* Copy all of the files from `./build` to your actual build directory,
|
||||
if your build directory is not `./build`
|
||||
* Copy your favorite font to `./build/arial.tff` (Arial is not included
|
||||
due its proprietary license).
|
||||
|
||||
## Usage
|
||||
* File, Open
|
||||
* Choose an Irrlicht-compatible B3D file.
|
|
@ -1,14 +1,15 @@
|
|||
#include "UserInterface.h"
|
||||
#include <iostream>
|
||||
|
||||
// PRIVATE
|
||||
void UserInterface::setupUserInterface()
|
||||
{
|
||||
// Menu
|
||||
// Menu
|
||||
IGUIContextMenu *menu = m_Gui->addMenu();
|
||||
menu->addItem( L"File", UIE_FILEMENU, true, true );
|
||||
menu->addItem( L"View", UIE_VIEWMENU, true, true );
|
||||
|
||||
// File Menu
|
||||
// File Menu
|
||||
IGUIContextMenu *fileMenu = menu->getSubMenu( 0 );
|
||||
fileMenu->addItem( L"Load", UIC_FILE_LOAD );
|
||||
fileMenu->addItem( L"Quit", UIC_FILE_QUIT );
|
||||
|
@ -21,28 +22,37 @@ void UserInterface::setupUserInterface()
|
|||
// Playback Control Window
|
||||
dimension2d<u32> windowSize = m_Engine->m_Driver->getScreenSize();
|
||||
IGUIWindow *playbackWindow = m_Gui->addWindow(
|
||||
rect<s32>( vector2d<s32>( windowSize.Width - 4 - 160, 28 ), dimension2d<s32>( 160, 300 )), false, L"Playback", 0, UIE_PLAYBACKWINDOW );
|
||||
rect<s32>( vector2d<s32>( windowSize.Width - 4 - 160, 28 ), dimension2d<s32>( 160, 300 )), false, L"Playback", nullptr, UIE_PLAYBACKWINDOW );
|
||||
playbackWindow->getCloseButton()->setVisible( false );
|
||||
IGUIButton *playbackStartStopButton = m_Gui->addButton(
|
||||
rect<s32>( vector2d<s32>( 4, 24 ), dimension2d<s32>( playbackWindow->getClientRect().getWidth() - 8, 24 )),
|
||||
playbackWindow,
|
||||
UIE_PLAYBACKSTARTSTOPBUTTON,
|
||||
L"Start/Stop",
|
||||
0
|
||||
nullptr
|
||||
);
|
||||
|
||||
// Set Font for UI Elements
|
||||
m_GuiFontFace = new CGUITTFace();
|
||||
m_GuiFontFace->load( "arial.ttf" );
|
||||
//irrString defines stringc as string<c8>
|
||||
std::string fontPath = "arial.ttf"; // core::stringc has implicit conversion to io::path
|
||||
//if (QFile(fontPath).exists()) {}
|
||||
m_GuiFontFace->load( fontPath.c_str() ); //actually takes `const io::path &`
|
||||
m_GuiFont = new CGUITTFont( m_Gui );
|
||||
m_GuiFont->attach( m_GuiFontFace, 14 );
|
||||
|
||||
m_Gui->getSkin()->setFont( m_GuiFont );
|
||||
assert(m_GuiFontFace != nullptr);
|
||||
if (m_GuiFontFace->face != nullptr) {
|
||||
m_GuiFont->attach( m_GuiFontFace, 14 );
|
||||
m_Gui->getSkin()->setFont( m_GuiFont );
|
||||
}
|
||||
else {
|
||||
cerr << "ERROR: Missing '" << fontPath << "'" << endl;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
void UserInterface::displayLoadFileDialog()
|
||||
{
|
||||
m_Gui->addFileOpenDialog( L"Select file to load", true, 0, UIE_LOADFILEDIALOG );
|
||||
m_Gui->addFileOpenDialog( L"Select file to load", true, nullptr, UIE_LOADFILEDIALOG );
|
||||
}
|
||||
|
||||
void UserInterface::handleMenuItemPressed( IGUIContextMenu *menu )
|
||||
|
@ -102,7 +112,7 @@ void UserInterface::drawStatusLine() const
|
|||
bool UserInterface::OnEvent( const SEvent &event )
|
||||
{
|
||||
// Events arriving here should be destined for us
|
||||
if( ! event.EventType == EET_GUI_EVENT )
|
||||
if( ! (event.EventType == EET_GUI_EVENT) )
|
||||
return false;
|
||||
|
||||
const SEvent::SGUIEvent *ge = &( event.GUIEvent );
|
||||
|
|
|
@ -23,7 +23,7 @@ void Utility::dumpMeshInfoToConsole( IAnimatedMeshSceneNode *node )
|
|||
// check for # textures
|
||||
int textures = 0;
|
||||
for( int ti = 0; ti < MATERIAL_MAX_TEXTURES; ti ++ )
|
||||
if( material.getTexture( ti ) != 0 ) textures ++;
|
||||
if( material.getTexture( ti ) != nullptr ) textures ++;
|
||||
debug() << "[MESH]: # of textures : " << textures << endl;
|
||||
}
|
||||
}
|
||||
|
|
BIN
build/arial.ttf
BIN
build/arial.ttf
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -9,159 +9,159 @@ namespace irr
|
|||
{
|
||||
namespace gui
|
||||
{
|
||||
//! Represents a font face.
|
||||
class CGUITTFace : public virtual IReferenceCounted
|
||||
{
|
||||
public:
|
||||
CGUITTFace();
|
||||
virtual ~CGUITTFace();
|
||||
//! Represents a font face.
|
||||
class CGUITTFace : public virtual IReferenceCounted
|
||||
{
|
||||
public:
|
||||
CGUITTFace();
|
||||
virtual ~CGUITTFace();
|
||||
|
||||
//! Loads a font face.
|
||||
//! \param filename Path to the font face.
|
||||
//! \param filesystem The Irrlicht filesystem to use. If 0, fonts will be loaded into memory by FreeType instead of by Irrlicht.
|
||||
//! \return Returns true if the font face loaded, false if it failed to load.
|
||||
bool load(const io::path& filename, io::IFileSystem* filesystem = 0);
|
||||
//! Loads a font face.
|
||||
//! \param filename Path to the font face.
|
||||
//! \param filesystem The Irrlicht filesystem to use. If 0, fonts will be loaded into memory by FreeType instead of by Irrlicht.
|
||||
//! \return Returns true if the font face loaded, false if it failed to load.
|
||||
bool load(const io::path& filename, io::IFileSystem* filesystem = nullptr);
|
||||
|
||||
//! The font face.
|
||||
FT_Face face;
|
||||
//! The font face.
|
||||
FT_Face face;
|
||||
|
||||
private:
|
||||
//! Flag to load the library.
|
||||
static bool libraryLoaded;
|
||||
bool faceLoaded;
|
||||
FT_Byte* font_buffer;
|
||||
FT_Long font_size;
|
||||
};
|
||||
private:
|
||||
//! Flag to load the library.
|
||||
static bool libraryLoaded;
|
||||
bool faceLoaded;
|
||||
FT_Byte* font_buffer;
|
||||
FT_Long font_size;
|
||||
};
|
||||
|
||||
//! Represents a glyph's bitmap info.
|
||||
struct CGUITTBitmapInfo
|
||||
{
|
||||
u32 top;
|
||||
u32 left;
|
||||
u32 width;
|
||||
u32 height;
|
||||
};
|
||||
//! Represents a glyph's bitmap info.
|
||||
struct CGUITTBitmapInfo
|
||||
{
|
||||
u32 top;
|
||||
u32 left;
|
||||
u32 width;
|
||||
u32 height;
|
||||
};
|
||||
|
||||
//! Class representing a single glyph.
|
||||
class CGUITTGlyph
|
||||
{
|
||||
public:
|
||||
CGUITTGlyph();
|
||||
virtual ~CGUITTGlyph();
|
||||
//! Class representing a single glyph.
|
||||
class CGUITTGlyph
|
||||
{
|
||||
public:
|
||||
CGUITTGlyph();
|
||||
virtual ~CGUITTGlyph();
|
||||
|
||||
//! Loads the glyph.
|
||||
void cache(u32 idx, bool fontHinting, bool autoHinting);
|
||||
//! Loads the glyph.
|
||||
void cache(u32 idx, bool fontHinting, bool autoHinting);
|
||||
|
||||
//! Informs if the glyph was loaded.
|
||||
bool cached;
|
||||
//! Informs if the glyph was loaded.
|
||||
bool cached;
|
||||
|
||||
//! Video driver.
|
||||
video::IVideoDriver* Driver;
|
||||
//! Video driver.
|
||||
video::IVideoDriver* Driver;
|
||||
|
||||
//! The face.
|
||||
FT_Face *face;
|
||||
//! The face.
|
||||
FT_Face *face;
|
||||
|
||||
//! The image data.
|
||||
//! Used for rendering with the software engine.
|
||||
u8* image;
|
||||
//! The image data.
|
||||
//! Used for rendering with the software engine.
|
||||
u8* image;
|
||||
|
||||
// Texture/image data.
|
||||
video::ITexture *texture;
|
||||
video::ITexture *texture_mono;
|
||||
// Texture/image data.
|
||||
video::ITexture *texture;
|
||||
video::ITexture *texture_mono;
|
||||
|
||||
// Size of the glyph.
|
||||
u32 size;
|
||||
// Size of the glyph.
|
||||
u32 size;
|
||||
|
||||
// The size of the glyph is expressed in pixels.
|
||||
bool size_is_pixels;
|
||||
// The size of the glyph is expressed in pixels.
|
||||
bool size_is_pixels;
|
||||
|
||||
// Info.
|
||||
bool hasDefault;
|
||||
bool hasMonochrome;
|
||||
// Info.
|
||||
bool hasDefault;
|
||||
bool hasMonochrome;
|
||||
|
||||
// Bitmap information.
|
||||
CGUITTBitmapInfo bitmap;
|
||||
CGUITTBitmapInfo bitmap_mono;
|
||||
// Bitmap information.
|
||||
CGUITTBitmapInfo bitmap;
|
||||
CGUITTBitmapInfo bitmap_mono;
|
||||
|
||||
// Texture information.
|
||||
core::dimension2du texture_size;
|
||||
core::dimension2du texture_mono_size;
|
||||
};
|
||||
// Texture information.
|
||||
core::dimension2du texture_size;
|
||||
core::dimension2du texture_mono_size;
|
||||
};
|
||||
|
||||
//! Class representing a font.
|
||||
class CGUITTFont : public IGUIFont
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CGUITTFont(IGUIEnvironment *env);
|
||||
//! Class representing a font.
|
||||
class CGUITTFont : public IGUIFont
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CGUITTFont(IGUIEnvironment *env);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CGUITTFont();
|
||||
//! Destructor
|
||||
virtual ~CGUITTFont();
|
||||
|
||||
//! Binds a font face to the class.
|
||||
//! \param face The font face to attach.
|
||||
//! \param size The size you want to load the font at.
|
||||
//! \param size_is_pixels If true, size is represented as pixels instead of points.
|
||||
bool attach(CGUITTFace *face, u32 size, bool size_is_pixels = false);
|
||||
//! Binds a font face to the class.
|
||||
//! \param face The font face to attach.
|
||||
//! \param size The size you want to load the font at.
|
||||
//! \param size_is_pixels If true, size is represented as pixels instead of points.
|
||||
bool attach(CGUITTFace *face, u32 size, bool size_is_pixels = false);
|
||||
|
||||
//! Draws some text and clips it to the specified rectangle if wanted.
|
||||
virtual void draw(const core::stringw& text, const core::rect<s32>& position,
|
||||
video::SColor color, bool hcenter=false, bool vcenter=false,
|
||||
const core::rect<s32>* clip=0);
|
||||
//! Draws some text and clips it to the specified rectangle if wanted.
|
||||
virtual void draw(const core::stringw& text, const core::rect<s32>& position,
|
||||
video::SColor color, bool hcenter=false, bool vcenter=false,
|
||||
const core::rect<s32>* clip=nullptr);
|
||||
|
||||
//! Returns the dimension of a text string.
|
||||
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const;
|
||||
//! Returns the dimension of a text string.
|
||||
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const;
|
||||
|
||||
//! Calculates the index of the character in the text which is on a specific position.
|
||||
virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const;
|
||||
//! Calculates the index of the character in the text which is on a specific position.
|
||||
virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const;
|
||||
|
||||
//! Sets global kerning width for the font.
|
||||
virtual void setKerningWidth(s32 kerning);
|
||||
//! Sets global kerning width for the font.
|
||||
virtual void setKerningWidth(s32 kerning);
|
||||
|
||||
//! Sets global kerning height for the font.
|
||||
virtual void setKerningHeight(s32 kerning);
|
||||
//! Sets global kerning height for the font.
|
||||
virtual void setKerningHeight(s32 kerning);
|
||||
|
||||
//! Gets kerning values (distance between letters) for the font. If no parameters are provided,
|
||||
virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const;
|
||||
//! Gets kerning values (distance between letters) for the font. If no parameters are provided,
|
||||
virtual s32 getKerningWidth(const wchar_t* thisLetter=nullptr, const wchar_t* previousLetter=nullptr) const;
|
||||
|
||||
//! Returns the distance between letters
|
||||
virtual s32 getKerningHeight() const;
|
||||
//! Returns the distance between letters
|
||||
virtual s32 getKerningHeight() const;
|
||||
|
||||
//! Define which characters should not be drawn by the font.
|
||||
virtual void setInvisibleCharacters(const wchar_t *s);
|
||||
//! Define which characters should not be drawn by the font.
|
||||
virtual void setInvisibleCharacters(const wchar_t *s);
|
||||
|
||||
//! Determines if the font will be loaded with antialiasing.
|
||||
//! Defaults true.
|
||||
bool AntiAlias;
|
||||
//! Determines if the font will be loaded with antialiasing.
|
||||
//! Defaults true.
|
||||
bool AntiAlias;
|
||||
|
||||
//! Determines if the font will be drawn with transparency.
|
||||
//! Defaults true.
|
||||
bool Transparency;
|
||||
//! Determines if the font will be drawn with transparency.
|
||||
//! Defaults true.
|
||||
bool Transparency;
|
||||
|
||||
//! Turns font hinting on or off. If a font looks odd, try toggling this option.
|
||||
//! This setting controls whether or not FreeType uses a font's built-in hinting.
|
||||
//! Defaults true.
|
||||
bool FontHinting;
|
||||
//! Turns font hinting on or off. If a font looks odd, try toggling this option.
|
||||
//! This setting controls whether or not FreeType uses a font's built-in hinting.
|
||||
//! Defaults true.
|
||||
bool FontHinting;
|
||||
|
||||
//! Turns FreeType auto-hinting on or off. If a font looks odd, try toggling this option.
|
||||
//! This setting controls whether or not FreeType uses its built-in auto hinting.
|
||||
//! Defaults to true.
|
||||
bool AutoHinting;
|
||||
//! Turns FreeType auto-hinting on or off. If a font looks odd, try toggling this option.
|
||||
//! This setting controls whether or not FreeType uses its built-in auto hinting.
|
||||
//! Defaults to true.
|
||||
bool AutoHinting;
|
||||
|
||||
private:
|
||||
u32 getWidthFromCharacter(wchar_t c) const;
|
||||
u32 getHeightFromCharacter(wchar_t c) const;
|
||||
u32 getGlyphByChar(wchar_t c) const;
|
||||
core::vector2di getKerning(const wchar_t thisLetter, const wchar_t previousLetter) const;
|
||||
private:
|
||||
u32 getWidthFromCharacter(wchar_t c) const;
|
||||
u32 getHeightFromCharacter(wchar_t c) const;
|
||||
u32 getGlyphByChar(wchar_t c) const;
|
||||
core::vector2di getKerning(const wchar_t thisLetter, const wchar_t previousLetter) const;
|
||||
|
||||
gui::IGUIEnvironment* Environment;
|
||||
video::IVideoDriver* Driver;
|
||||
mutable core::array< CGUITTGlyph > Glyphs;
|
||||
CGUITTFace *tt_face;
|
||||
s32 GlobalKerningWidth;
|
||||
s32 GlobalKerningHeight;
|
||||
core::stringw Invisible;
|
||||
};
|
||||
gui::IGUIEnvironment* Environment;
|
||||
video::IVideoDriver* Driver;
|
||||
mutable core::array< CGUITTGlyph > Glyphs;
|
||||
CGUITTFace *tt_face;
|
||||
s32 GlobalKerningWidth;
|
||||
s32 GlobalKerningHeight;
|
||||
core::stringw Invisible;
|
||||
};
|
||||
|
||||
} // end namespace gui
|
||||
} // end namespace irr
|
||||
|
|
54
main.cpp
54
main.cpp
|
@ -13,55 +13,55 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
|
|||
int main( int argc, char **argv )
|
||||
#endif
|
||||
{
|
||||
// Parse commandline to check if a filename argument has been passed
|
||||
// Parse commandline to check if a filename argument has been passed
|
||||
#ifdef WIN32
|
||||
int argc;
|
||||
char **argv;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
LPWSTR *args;
|
||||
args = CommandLineToArgvW( GetCommandLineW(), &argc );
|
||||
LPWSTR *args;
|
||||
args = CommandLineToArgvW( GetCommandLineW(), &argc );
|
||||
|
||||
argv = ( char ** ) malloc( sizeof( char * ) * argc );
|
||||
for( int index = 0; index < argc; index ++ )
|
||||
{
|
||||
int argumentBufferLength = wcslen( args[index] ) + 1;
|
||||
argv[index] = ( char * ) malloc( sizeof( char ) * argumentBufferLength );
|
||||
sprintf_s( argv[index], argumentBufferLength, "%ws", args[index] );
|
||||
}
|
||||
argv = ( char ** ) malloc( sizeof( char * ) * argc );
|
||||
for( int index = 0; index < argc; index ++ )
|
||||
{
|
||||
int argumentBufferLength = wcslen( args[index] ) + 1;
|
||||
argv[index] = ( char * ) malloc( sizeof( char ) * argumentBufferLength );
|
||||
sprintf_s( argv[index], argumentBufferLength, "%ws", args[index] );
|
||||
}
|
||||
|
||||
LocalFree( args );
|
||||
LocalFree( args );
|
||||
#endif
|
||||
|
||||
Engine *engine = new Engine();
|
||||
if( argc >= 2 )
|
||||
{
|
||||
wchar_t *initialFileName = getWideCharString( argv[1] );
|
||||
engine->loadMesh( wstring( initialFileName ));
|
||||
free( initialFileName );
|
||||
}
|
||||
else
|
||||
engine->loadMesh( L"test.b3d" );
|
||||
if( argc >= 2 )
|
||||
{
|
||||
wchar_t *initialFileName = getWideCharString( argv[1] );
|
||||
engine->loadMesh( wstring( initialFileName ));
|
||||
free( initialFileName );
|
||||
}
|
||||
else
|
||||
engine->loadMesh( L"test.b3d" );
|
||||
|
||||
engine->run();
|
||||
|
||||
delete engine;
|
||||
|
||||
#ifdef WIN32
|
||||
for( int index = 0; index < argc; index ++ )
|
||||
free( argv[index] );
|
||||
free( argv );
|
||||
for( int index = 0; index < argc; index ++ )
|
||||
free( argv[index] );
|
||||
free( argv );
|
||||
#endif
|
||||
}
|
||||
|
||||
wchar_t * getWideCharString( char *str )
|
||||
{
|
||||
wchar_t *dest = ( wchar_t * ) malloc( sizeof( wchar_t ) * ( strlen( str ) + 1 ));
|
||||
wchar_t *dest = ( wchar_t * ) malloc( sizeof( wchar_t ) * ( strlen( str ) + 1 ));
|
||||
|
||||
int resultSize = mbstowcs( 0, str, strlen( str ));
|
||||
int resultSize = mbstowcs( nullptr, str, strlen( str ));
|
||||
mbstowcs( dest, str, strlen( str ));
|
||||
|
||||
dest[resultSize] = '\0';
|
||||
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue