Difference between revisions of "Tutorial - Setup Horde with Qt4"
From Horde3D Wiki
(updated the tutorial) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{| border="0" | {| border="0" | ||
− | | {{ContentBlock | + | | {{ContentBlock|color=white |
− | |content= | + | |content=Before you start you should read QtOpenGL tutorial: http://doc.trolltech.com/4.6/opengl-hellogl.html (Substitute correct version of your Qt distribution). |
− | + | ||
+ | Horde3D library should be already installed for build scripts to succeed. | ||
{{CppSourceCode| | {{CppSourceCode| | ||
− | description= | + | description= GLWidget.h| |
code= | code= | ||
<source lang="cpp" line="1"> | <source lang="cpp" line="1"> | ||
+ | #ifndef GL_WIDGET_H | ||
+ | #define GL_WIDGET_H | ||
− | + | #include <QtOpenGL> | |
− | + | #include <horde3d/Horde3D.h> | |
− | + | #include <horde3d/Horde3DUtils.h> | |
− | |||
− | #include <QtOpenGL | ||
− | |||
− | #include <Horde3D.h> | ||
− | #include <Horde3DUtils.h> | ||
− | + | class GLWidget : public QGLWidget { | |
− | class GLWidget : public QGLWidget{ | ||
Q_OBJECT | Q_OBJECT | ||
− | |||
public: | public: | ||
− | GLWidget( | + | GLWidget(); |
~GLWidget(); | ~GLWidget(); | ||
− | QSize minimumSizeHint() const; | + | |
− | QSize sizeHint() const; | + | QSize minimumSizeHint() const { |
+ | return QSize(640, 480); | ||
+ | } | ||
+ | QSize sizeHint() const { | ||
+ | return QSize(640, 480); | ||
+ | } | ||
protected: | protected: | ||
void initializeGL(); | void initializeGL(); | ||
void paintGL(); | void paintGL(); | ||
− | void resizeGL(int width,int height | + | void resizeGL(int width, int height); |
− | |||
− | |||
− | |||
private: | private: | ||
− | + | H3DRes mCam; | |
}; | }; | ||
− | + | #endif // GL_WIDGET_H | |
− | |||
− | #endif // | ||
</source> | </source> | ||
}} | }} | ||
− | + | {{CppSourceCode|width=1024| | |
− | {{CppSourceCode| | + | description= GLWidget.cpp| |
− | description= | ||
code= | code= | ||
<source lang="cpp" line="1"> | <source lang="cpp" line="1"> | ||
+ | #include "GLWidget.h" | ||
+ | #include <stdexcept> | ||
− | + | GLWidget::GLWidget() : QGLWidget() { } | |
− | |||
− | |||
− | |||
− | GLWidget::GLWidget( | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | } | ||
− | + | GLWidget::~GLWidget() { | |
− | + | h3dutDumpMessages(); | |
+ | h3dRelease(); | ||
} | } | ||
− | void GLWidget::initializeGL(){ | + | void GLWidget::initializeGL() { |
− | if(! | + | if (!h3dInit()) { |
− | + | h3dutDumpMessages(); | |
− | + | throw std::runtime_error("Could not initialize renderer"); | |
} | } | ||
− | + | H3DRes pipeline = h3dAddResource( | |
− | + | H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0); | |
− | + | H3DRes knight = h3dAddResource( | |
− | + | H3DResTypes::SceneGraph , "models/knight/knight.scene.xml", 0); | |
− | + | h3dutLoadResourcesFromDisk("Content"); | |
− | + | H3DNode node = h3dAddNodes(H3DRootNode, knight); | |
− | + | h3dSetNodeTransform(node, 0,0,0, 0,0,0, 1,1,1); | |
− | + | mCam = h3dAddCameraNode(H3DRootNode, "cam", pipeline); | |
− | + | h3dSetNodeTransform(mCam, 0,40,-40, 23,-166,0, 1,1,1); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | void GLWidget:: | + | void GLWidget::paintGL() { |
− | + | h3dRender(mCam); | |
− | |||
} | } | ||
− | void GLWidget:: | + | void GLWidget::resizeGL(int width, int height) { |
− | + | h3dSetupViewport(0, 0, width, height, true); | |
− | + | h3dSetupCameraView( | |
− | + | mCam, 45.0f, static_cast<float>(width)/height, 0.1f, 1000.0f); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
</source> | </source> | ||
}} | }} | ||
− | |||
{{CppSourceCode| | {{CppSourceCode| | ||
description= main.cpp| | description= main.cpp| | ||
code= | code= | ||
<source lang="cpp" line="1"> | <source lang="cpp" line="1"> | ||
+ | #include "GLWidget.h" | ||
+ | #include <QApplication> | ||
− | + | int main(int argc, char* argv[]) { | |
− | |||
− | |||
− | int main(int argc, char* argv[]) | ||
− | { | ||
QApplication app(argc, argv); | QApplication app(argc, argv); | ||
− | GLWidget | + | GLWidget glw; |
− | + | glw.show(); | |
− | |||
− | |||
return app.exec(); | return app.exec(); | ||
} | } | ||
</source> | </source> | ||
}} | }} | ||
− | + | QMake project file: | |
{{CppSourceCode| | {{CppSourceCode| | ||
− | description= | + | description= h3d_qt4.pro| |
code= | code= | ||
<source lang="cpp" line="1"> | <source lang="cpp" line="1"> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
TEMPLATE = app | TEMPLATE = app | ||
− | TARGET = | + | TARGET = h3d_qt4 |
− | DEPENDPATH += . | + | DEPENDPATH += . |
− | INCLUDEPATH += . | + | INCLUDEPATH += . |
− | LIBS += | + | LIBS += -lHorde3D -lHorde3DUtils |
− | |||
QT += opengl | QT += opengl | ||
# Input | # Input | ||
− | HEADERS += | + | HEADERS += GLWidget.h |
− | SOURCES += main.cpp | + | SOURCES += GLWidget.cpp main.cpp</source> |
+ | }} | ||
+ | '''Note''': [http://www.horde3d.org/wiki/index.php5?title=Building_Horde3D#Linkage_order_for_your_application Linkage order for your application] | ||
+ | |||
+ | CMake project file: | ||
+ | {{CppSourceCode| | ||
+ | description= CMakeLists.txt| | ||
+ | code= | ||
+ | <source lang="cpp" line="1"> | ||
+ | PROJECT(H3D_QT4) | ||
+ | |||
+ | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) | ||
+ | CMAKE_POLICY(VERSION 2.6) | ||
+ | # Debug, all warnings. | ||
+ | ADD_DEFINITIONS(-g -Wall) | ||
+ | # Find Qt4. | ||
+ | INCLUDE(FindQt4) | ||
+ | FIND_PACKAGE(Qt4 REQUIRED) | ||
+ | SET(QT_USE_QTOPENGL TRUE) | ||
+ | INCLUDE(${QT_USE_FILE}) | ||
+ | INCLUDE_DIRECTORIES(${QT_INCLUDES} | ||
+ | /usr/local/include | ||
+ | /usr/include) | ||
+ | # Headers with Q_OBJECT macro. | ||
+ | SET( | ||
+ | H3D_QT4_MOC_HDR | ||
+ | GLWidget.h | ||
+ | ) | ||
+ | QT4_WRAP_CPP(H3D_QT4_MOC_SRC ${H3D_QT4_MOC_HDR}) | ||
+ | # Sources. | ||
+ | SET( | ||
+ | H3D_QT4_SRC | ||
+ | GLWidget.cpp | ||
+ | main.cpp | ||
+ | ) | ||
+ | ADD_EXECUTABLE(h3d_qt4 ${H3D_QT4_MOC_SRC} ${H3D_QT4_SRC}) | ||
+ | TARGET_LINK_LIBRARIES(h3d_qt4 Horde3D Horde3DUtils ${QT_LIBRARIES}) | ||
</source> | </source> | ||
}} | }} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}} | }} | ||
+ | [http://kornerr.alfamoon.com/images/h3d_qt4.png The result should look like this] | ||
|} | |} | ||
[[category: Tutorials]] | [[category: Tutorials]] |
Latest revision as of 03:59, 10 February 2010
|