예제 #1
0
파일: Main.cpp 프로젝트: 88er/tutorials
// This can be used to free all of our resources in the application.
void GLApplication::Destroy()
{
	// Free the vertex buffers and array objects
	g_Model.Destroy();

	// If we have a window manager still allocated then destroy and delete it
	if ( WindowManager )
	{
		WindowManager->Destroy();

		delete WindowManager;
		WindowManager = nullptr;
	}
	
	// If we have the camera still, delete it
	if ( Camera )
	{
		delete Camera;
		Camera = nullptr;
	}
}
예제 #2
0
// ----------------------------------------------------------------------------------------------
bool XmlModelFactory::LoadResource(Resource* resource, const WCHAR * filename)
{
    UINT dataSize;
    BYTE* data = FileUtils::LoadFile(filename, &dataSize);
    if (!data)
    {
        return false;
    }

    Model * model = (Model*)resource;
    model->SetSourceFileName(filename);

    // char name for logging 'char*' exceptions
    char charName[MAX_PATH];
    WideCharToMultiByte(0, 0, filename, -1, charName, MAX_PATH, NULL, NULL);



    Model3dBuilder builder;
    builder.m_model = model;
    xml_document doc;
    bool succeeded = false;

    try
    {
        doc.parse<0>((char*)data);

        m_parseErrors = 0;

        builder.Begin();

        ProcessXml(doc.first_node(), &builder);

        builder.End();

        if (m_parseErrors > 0)
        {
            Logger::Log(OutputMessageType::Error, L"%d errors occured while parsing, '%s'\n",
                                                            m_parseErrors, filename);
        }
        else
        {
            // this will create the D3D vertex/index buffers as well
            // as trigger the loading of the textures.
            model->Construct(m_device, ResourceManager::Inst());
        }

        succeeded = true;
    }
    catch(rapidxml::parse_error& error)
    {
        Logger::Log(OutputMessageType::Error, "Parse exception: '%s' while processing '%s'\n", error.what(), charName);
    }
    catch(std::runtime_error& error)
    {
        Logger::Log(OutputMessageType::Error, "Processing exception: '%s' while processing '%s'\n", error.what(), charName);
    }
    catch(...)
    {
        Logger::Log(OutputMessageType::Error, L"Generic exception while processing '%s'\n", filename);
    }

    if (!succeeded)
    {
        // clean up model (remove all geometry), but don't free memory because there
        // are other references to this model from 
        model->Destroy();
    }

    SAFE_DELETE_ARRAY(data);

    return succeeded;
}