Click here to Skip to main content
15,896,557 members
Articles / Multimedia / OpenGL

XML parser of OSG with Qt support

Rate me:
Please Sign up or sign in to vote.
4.86/5 (6 votes)
24 Dec 2012CPOL4 min read 16K   1.1K   10  
Simple XML parser for creation scenes in OSG 3D Engine
  • OSGXML.zip
    • OSGXML
      • Common
        • OpenSceneGraph-3.1.3
          • include
            • OpenThreads
              • Atomic
              • Barrier
              • Block
              • Condition
              • Config
              • Exports
              • Mutex
              • ReadWriteMutex
              • ReentrantMutex
              • ScopedLock
              • Thread
              • Version
            • osg
              • AlphaFunc
              • AnimationPath
              • ApplicationUsage
              • ArgumentParser
              • Array
              • ArrayDispatchers
              • AudioStream
              • AutoTransform
              • Billboard
              • BlendColor
              • BlendEquation
              • BlendFunc
              • BoundingBox
              • BoundingSphere
              • BoundsChecking
              • buffered_value
              • BufferIndexBinding
              • BufferObject
              • Camera
              • CameraNode
              • CameraView
              • ClampColor
              • ClearNode
              • ClipNode
              • ClipPlane
              • ClusterCullingCallback
              • CollectOccludersVisitor
              • ColorMask
              • ColorMatrix
              • ComputeBoundsVisitor
              • Config
              • ConvexPlanarOccluder
              • ConvexPlanarPolygon
              • CoordinateSystemNode
              • CopyOp
              • CullFace
              • CullingSet
              • CullSettings
              • CullStack
              • DeleteHandler
              • Depth
              • DisplaySettings
              • Drawable
              • DrawPixels
              • Endian
              • Export
              • fast_back_stack
              • Fog
              • FragmentProgram
              • FrameBufferObject
              • FrameStamp
              • FrontFace
              • Geode
              • Geometry
              • GL
              • GL2Extensions
              • GLBeginEndAdapter
              • GLExtensions
              • GLObjects
              • GLU
              • GraphicsContext
              • GraphicsCostEstimator
              • GraphicsThread
              • Group
              • Hint
              • Image
              • ImageSequence
              • ImageStream
              • ImageUtils
              • io_utils
              • KdTree
              • Light
              • LightModel
              • LightSource
              • LineSegment
              • LineStipple
              • LineWidth
              • LOD
              • LogicOp
              • Material
              • Math
              • Matrix
              • Matrixd
              • Matrixf
              • MatrixTransform
              • MixinVector
              • Multisample
              • Node
              • NodeCallback
              • NodeTrackerCallback
              • NodeVisitor
              • Notify
              • Object
              • Observer
              • observer_ptr
              • ObserverNodePath
              • OccluderNode
              • OcclusionQueryNode
              • OperationThread
              • PagedLOD
              • Plane
              • Point
              • PointSprite
              • PolygonMode
              • PolygonOffset
              • PolygonStipple
              • Polytope
              • PositionAttitudeTransform
              • PrimitiveSet
              • Program
              • Projection
              • ProxyNode
              • Quat
              • ref_ptr
              • Referenced
              • RenderInfo
              • Scissor
              • Sequence
              • ShadeModel
              • Shader
              • ShaderAttribute
              • ShaderComposer
              • ShadowVolumeOccluder
              • Shape
              • ShapeDrawable
              • State
              • StateAttribute
              • StateAttributeCallback
              • StateSet
              • Stats
              • Stencil
              • StencilTwoSided
              • Switch
              • TemplatePrimitiveFunctor
              • TexEnv
              • TexEnvCombine
              • TexEnvFilter
              • TexGen
              • TexGenNode
              • TexMat
              • Texture
              • Texture1D
              • Texture2D
              • Texture2DArray
              • Texture2DMultisample
              • Texture3D
              • TextureCubeMap
              • TextureRectangle
              • Timer
              • TransferFunction
              • Transform
              • TriangleFunctor
              • TriangleIndexFunctor
              • Uniform
              • UserDataContainer
              • ValueObject
              • Vec2
              • Vec2b
              • Vec2d
              • Vec2f
              • Vec2s
              • Vec3
              • Vec3b
              • Vec3d
              • Vec3f
              • Vec3s
              • Vec4
              • Vec4b
              • Vec4d
              • Vec4f
              • Vec4s
              • Vec4ub
              • Version
              • VertexProgram
              • View
              • Viewport
            • osgAnimation
              • Action
              • ActionAnimation
              • ActionBlendIn
              • ActionBlendOut
              • ActionCallback
              • ActionStripAnimation
              • ActionVisitor
              • Animation
              • AnimationManagerBase
              • AnimationUpdateCallback
              • BasicAnimationManager
              • Bone
              • BoneMapVisitor
              • Channel
              • CubicBezier
              • EaseMotion
              • Export
              • FrameAction
              • Interpolator
              • Keyframe
              • LinkVisitor
              • MorphGeometry
              • RigGeometry
              • RigTransform
              • RigTransformHardware
              • RigTransformSoftware
              • Sampler
              • Skeleton
              • StackedMatrixElement
              • StackedQuaternionElement
              • StackedRotateAxisElement
              • StackedScaleElement
              • StackedTransform
              • StackedTransformElement
              • StackedTranslateElement
              • StatsHandler
              • StatsVisitor
              • Target
              • Timeline
              • TimelineAnimationManager
              • UpdateBone
              • UpdateMaterial
              • UpdateMatrixTransform
              • Vec3Packed
              • VertexInfluence
            • osgDB
              • Archive
              • AuthenticationMap
              • Callbacks
              • ConvertUTF
              • DatabasePager
              • DatabaseRevisions
              • DataTypes
              • DotOsgWrapper
              • DynamicLibrary
              • Export
              • ExternalFileWriter
              • FileCache
              • FileNameUtils
              • FileUtils
              • fstream
              • ImageOptions
              • ImagePager
              • ImageProcessor
              • Input
              • InputStream
              • ObjectWrapper
              • Options
              • Output
              • OutputStream
              • ParameterOutput
              • PluginQuery
              • ReaderWriter
              • ReadFile
              • Registry
              • Serializer
              • SharedStateManager
              • StreamOperator
              • Version
              • WriteFile
              • XmlParser
            • osgFX
              • AnisotropicLighting
              • BumpMapping
              • Cartoon
              • Effect
              • Export
              • MultiTextureControl
              • Outline
              • Registry
              • Scribe
              • SpecularHighlights
              • Technique
              • Validator
              • Version
            • osgGA
              • AnimationPathManipulator
              • CameraManipulator
              • CameraViewSwitchManipulator
              • DriveManipulator
              • EventQueue
              • EventVisitor
              • Export
              • FirstPersonManipulator
              • FlightManipulator
              • GUIActionAdapter
              • GUIEventAdapter
              • GUIEventHandler
              • KeySwitchMatrixManipulator
              • MultiTouchTrackballManipulator
              • NodeTrackerManipulator
              • OrbitManipulator
              • SphericalManipulator
              • StandardManipulator
              • StateSetManipulator
              • TerrainManipulator
              • TrackballManipulator
              • UFOManipulator
              • Version
            • osgManipulator
              • AntiSquish
              • Command
              • CommandManager
              • Constraint
              • Dragger
              • Export
              • Projector
              • RotateCylinderDragger
              • RotateSphereDragger
              • Scale1DDragger
              • Scale2DDragger
              • ScaleAxisDragger
              • Selection
              • TabBoxDragger
              • TabBoxTrackballDragger
              • TabPlaneDragger
              • TabPlaneTrackballDragger
              • TrackballDragger
              • Translate1DDragger
              • Translate2DDragger
              • TranslateAxisDragger
              • TranslatePlaneDragger
              • Version
            • osgParticle
              • AccelOperator
              • AngularAccelOperator
              • AngularDampingOperator
              • BounceOperator
              • BoxPlacer
              • CenteredPlacer
              • CompositePlacer
              • ConnectedParticleSystem
              • ConstantRateCounter
              • Counter
              • DampingOperator
              • DomainOperator
              • Emitter
              • ExplosionDebrisEffect
              • ExplosionEffect
              • ExplosionOperator
              • Export
              • FireEffect
              • FluidFrictionOperator
              • FluidProgram
              • ForceOperator
              • Interpolator
              • LinearInterpolator
              • ModularEmitter
              • ModularProgram
              • MultiSegmentPlacer
              • Operator
              • OrbitOperator
              • Particle
              • ParticleEffect
              • ParticleProcessor
              • ParticleSystem
              • ParticleSystemUpdater
              • Placer
              • PointPlacer
              • PrecipitationEffect
              • Program
              • RadialShooter
              • RandomRateCounter
              • range
              • SectorPlacer
              • SegmentPlacer
              • Shooter
              • SinkOperator
              • SmokeEffect
              • SmokeTrailEffect
              • VariableRateCounter
              • Version
            • osgPresentation
              • AnimationMaterial
              • CompileSlideCallback
              • Export
              • PickEventHandler
              • SlideEventHandler
              • SlideShowConstructor
            • osgQt
              • Export
              • GraphicsWindowQt
              • QFontImplementation
              • QGraphicsViewAdapter
              • QWebViewImage
              • QWidgetImage
            • osgShadow
              • ConvexPolyhedron
              • DebugShadowMap
              • Export
              • LightSpacePerspectiveShadowMap
              • MinimalCullBoundsShadowMap
              • MinimalDrawBoundsShadowMap
              • MinimalShadowMap
              • OccluderGeometry
              • ParallelSplitShadowMap
              • ProjectionShadowMap
              • ShadowedScene
              • ShadowMap
              • ShadowSettings
              • ShadowTechnique
              • ShadowTexture
              • ShadowVolume
              • SoftShadowMap
              • StandardShadowMap
              • Version
              • ViewDependentShadowMap
              • ViewDependentShadowTechnique
            • osgSim
              • BlinkSequence
              • ColorRange
              • DOFTransform
              • ElevationSlice
              • Export
              • GeographicLocation
              • HeightAboveTerrain
              • Impostor
              • ImpostorSprite
              • InsertImpostorsVisitor
              • LightPoint
              • LightPointNode
              • LightPointSystem
              • LineOfSight
              • MultiSwitch
              • ObjectRecordData
              • OverlayNode
              • ScalarBar
              • ScalarsToColors
              • Sector
              • ShapeAttribute
              • SphereSegment
              • Version
              • VisibilityGroup
            • osgTerrain
              • Export
              • GeometryTechnique
              • Layer
              • Locator
              • Terrain
              • TerrainTechnique
              • TerrainTile
              • ValidDataOperator
              • Version
            • osgText
              • Export
              • FadeText
              • Font
              • Font3D
              • Glyph
              • KerningType
              • String
              • Style
              • Text
              • Text3D
              • TextBase
              • Version
            • osgUtil
              • ConvertVec
              • CubeMapGenerator
              • CullVisitor
              • DelaunayTriangulator
              • DisplayRequirementsVisitor
              • DrawElementTypeSimplifier
              • EdgeCollector
              • Export
              • GLObjectsVisitor
              • HalfWayMapGenerator
              • HighlightMapGenerator
              • IncrementalCompileOperation
              • IntersectionVisitor
              • IntersectVisitor
              • LineSegmentIntersector
              • MeshOptimizers
              • OperationArrayFunctor
              • Optimizer
              • PerlinNoise
              • PlaneIntersector
              • PolytopeIntersector
              • PositionalStateContainer
              • PrintVisitor
              • ReflectionMapGenerator
              • RenderBin
              • RenderLeaf
              • RenderStage
              • ReversePrimitiveFunctor
              • SceneGraphBuilder
              • SceneView
              • ShaderGen
              • Simplifier
              • SmoothingVisitor
              • StateGraph
              • Statistics
              • TangentSpaceGenerator
              • Tessellator
              • TransformAttributeFunctor
              • TransformCallback
              • TriStripVisitor
              • UpdateVisitor
              • Version
            • osgViewer
              • api
                • Win32
                  • GraphicsHandleWin32
                  • GraphicsWindowWin32
                  • PixelBufferWin32
              • CompositeViewer
              • Export
              • GraphicsWindow
              • Renderer
              • Scene
              • Version
              • View
              • Viewer
              • ViewerBase
              • ViewerEventHandlers
            • osgVolume
              • Export
              • FixedFunctionTechnique
              • Layer
              • Locator
              • Property
              • RayTracedTechnique
              • Version
              • Volume
              • VolumeTechnique
              • VolumeTile
            • osgWidget
              • Box
              • Browser
              • Canvas
              • EventInterface
              • Export
              • Frame
              • Input
              • Label
              • Lua
              • PdfReader
              • Python
              • ScriptEngine
              • StyleInterface
              • StyleManager
              • Table
              • Types
              • UIObjectParent
              • Util
              • Version
              • ViewerEventHandlers
              • VncClient
              • Widget
              • Window
              • WindowManager
          • lib
            • Debug
              • OpenThreadsd.lib
              • osgAnimationd.lib
              • osgd.lib
              • osgDBd.lib
              • osgFXd.lib
              • osgGAd.lib
              • osgManipulatord.lib
              • osgParticled.lib
              • osgPresentationd.lib
              • osgQtd.lib
              • osgShadowd.lib
              • osgSimd.lib
              • osgTerraind.lib
              • osgTextd.lib
              • osgUtild.lib
              • osgViewerd.lib
              • osgVolumed.lib
              • osgWidgetd.lib
              • pkgconfig
                • openscenegraph.pc
                • openscenegraph-osg.pc
                • openscenegraph-osgAnimation.pc
                • openscenegraph-osgDB.pc
                • openscenegraph-osgFX.pc
                • openscenegraph-osgGA.pc
                • openscenegraph-osgManipulator.pc
                • openscenegraph-osgParticle.pc
                • openscenegraph-osgQt.pc
                • openscenegraph-osgShadow.pc
                • openscenegraph-osgSim.pc
                • openscenegraph-osgTerrain.pc
                • openscenegraph-osgText.pc
                • openscenegraph-osgUtil.pc
                • openscenegraph-osgViewer.pc
                • openscenegraph-osgVolume.pc
                • openscenegraph-osgWidget.pc
                • openthreads.pc
            • Release
              • OpenThreads.lib
              • osg.lib
              • osgAnimation.lib
              • osgDB.lib
              • osgFX.lib
              • osgGA.lib
              • osgManipulator.lib
              • osgParticle.lib
              • osgPresentation.lib
              • osgQt.lib
              • osgShadow.lib
              • osgSim.lib
              • osgTerrain.lib
              • osgText.lib
              • osgUtil.lib
              • osgViewer.lib
              • osgVolume.lib
              • osgWidget.lib
              • pkgconfig
                • openscenegraph.pc
                • openscenegraph-osg.pc
                • openscenegraph-osgAnimation.pc
                • openscenegraph-osgDB.pc
                • openscenegraph-osgFX.pc
                • openscenegraph-osgGA.pc
                • openscenegraph-osgManipulator.pc
                • openscenegraph-osgParticle.pc
                • openscenegraph-osgQt.pc
                • openscenegraph-osgShadow.pc
                • openscenegraph-osgSim.pc
                • openscenegraph-osgTerrain.pc
                • openscenegraph-osgText.pc
                • openscenegraph-osgUtil.pc
                • openscenegraph-osgViewer.pc
                • openscenegraph-osgVolume.pc
                • openscenegraph-osgWidget.pc
                • openthreads.pc
      • OSGLoader
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
**     of its contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QDebug>
#include <QVBoxLayout>

#include <QAudioOutput>
#include <QAudioDeviceInfo>
#include <QtCore/qmath.h>
#include <QtCore/qendian.h>
#include "audiooutput.h"


const int DurationSeconds = 1;
const int ToneFrequencyHz = 600;
const int DataFrequencyHz = 44100;
const int BufferSize      = 32768;


WrapAudioStream::WrapAudioStream(osg::AudioStream *audioStream,
                     QObject *parent)
    :   QIODevice(parent)
    ,   _audioStream(audioStream)
{
}

WrapAudioStream::~WrapAudioStream()
{

}

void WrapAudioStream::start()
{
    open(QIODevice::ReadOnly);
}

void WrapAudioStream::stop()
{
    close();
}

qint64 WrapAudioStream::readData(char *data, qint64 len)
{
    qint64 total = 0;

    _audioStream->consumeAudioBuffer(data, len);

    total = len;

    return total;
}

qint64 WrapAudioStream::writeData(const char *data, qint64 len)
{
    Q_UNUSED(data);
    Q_UNUSED(len);

    return 0;
}

qint64 WrapAudioStream::bytesAvailable() const
{
//    return m_buffer.size() + QIODevice::bytesAvailable();
    return QIODevice::bytesAvailable();
}

AudioTest::AudioTest(osg::AudioStream *audioStream, QAudioFormat format)
    :   m_device(QAudioDeviceInfo::defaultOutputDevice())
    ,   m_generator(0)
    ,   m_audioOutput(0)
    ,   m_output(0)
    ,   m_buffer(BufferSize, 0)
    ,   _audioStream(audioStream)
    ,   m_format(format)
{
      initializeAudio();
}

void AudioTest::initializeAudio()
{

    m_pullMode = true;

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(m_format)) {
        qWarning() << "Default format not supported - trying to use nearest";
        m_format = info.nearestFormat(m_format);
    }

    m_generator = new WrapAudioStream(_audioStream, this);

    createAudioOutput();
}

void AudioTest::createAudioOutput()
{
    delete m_audioOutput;
    m_audioOutput = 0;
    m_audioOutput = new QAudioOutput(m_device, m_format, this);
    connect(m_audioOutput, SIGNAL(notify()), SLOT(notified()));
    connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
    m_generator->start();
    m_audioOutput->start(m_generator);
}

void AudioTest::pause()
{
    m_audioOutput->suspend();
}

void AudioTest::resume()
{
    m_audioOutput->resume();
}

AudioTest::~AudioTest()
{

}

void AudioTest::notified()
{
//    qWarning() << "bytesFree = " << m_audioOutput->bytesFree()
//               << ", " << "elapsedUSecs = " << m_audioOutput->elapsedUSecs()
//               << ", " << "processedUSecs = " << m_audioOutput->processedUSecs();
}

void AudioTest::stateChanged(QAudio::State state)
{
//    qWarning() << "state = " << state;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions