Horde3D

Next-Generation Graphics Engine
It is currently 10.11.2024, 20:46

All times are UTC + 1 hour




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: 09.09.2008, 01:16 
Offline

Joined: 09.09.2008, 01:03
Posts: 1
Hello,

I was trying to compile the Horde3D-in-QT example here
http://www.horde3d.org/wiki/index.php5? ... e_with_Qt4 but found it did not immediately compile.

So I decided to modify the existing Sample_Chicago example that comes with the distribution to use QT. Please find the results attached. Feel free to use it if you want. Just untar into the distribution's Samples directory and do:

Code:
qmake-qt4      # make the Makefile from the chicagoQt.pro
make            # make the binary
make install    # cp binary to the Samples directory


The FPS variable is not updated correctly though. I use it as a reference to re-paint the page rather than as a display of frames per second. In this context it's a command and not a measurement.

The sample is pretty much left as is, with a replacement main(). I did add an animate function to drive the animation.

I am not a Qt guy at all, this was a learning experience for me both for Qt and Horde3d. I only tested and ran it under Linux (Fedora 8) using Qt 4.3 so I have no idea if it runs elsewhere...

--
Phil.


Attachments:
ChicagoQT.tgz [4.77 KiB]
Downloaded 1129 times
Top
 Profile  
Reply with quote  
PostPosted: 13.09.2008, 03:29 
Offline

Joined: 23.07.2008, 06:25
Posts: 13
Location: Texas/CyberSpace
Hi im the writer of the qt tutorial. I do state that some changes may need to be made to the custom cmake file provided. It was not intended to compile out of the box some changes may have to be made.


Top
 Profile  
Reply with quote  
PostPosted: 08.02.2010, 18:10 
Offline

Joined: 27.09.2008, 07:34
Posts: 35
H3D r211. Qt 4.5.1. Tested on Linux x86 and x86_64. Slackware 13.0 distribution.

The simplest app does not work.

CMakeLists.txt:
Code:
PROJECT(QH)

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(
    QH_MOC_HDR
    GLWidget.h
)
QT4_WRAP_CPP(QH_MOC_SRC ${QH_MOC_HDR})
# Sources.
SET(
    QH_SRC
    GLWidget.cpp
    main.cpp
)
ADD_EXECUTABLE(test ${QH_MOC_SRC} ${QH_SRC})
TARGET_LINK_LIBRARIES(test ${QT_LIBRARIES} Horde3D Horde3DUtils)


GLWidget.cpp:
Code:

#include "GLWidget.h"
#include <stdexcept>

GLWidget::GLWidget() : QGLWidget() {

}

GLWidget::~GLWidget() {

}

void GLWidget::initializeGL() {
    if (!h3dInit()) {
        h3dutDumpMessages();
        throw std::runtime_error("Could not initialize renderer");
    }
}


GLWidget.h:
Code:

#ifndef GL_WIDGET_H
#define GL_WIDGET_H

#include <QtOpenGL>
#include <horde3d/Horde3D.h>
#include <horde3d/Horde3DUtils.h>

class GLWidget : public QGLWidget {
    Q_OBJECT
    public:
        GLWidget();
        ~GLWidget();

        QSize minimumSizeHint() const {
            return QSize(640, 480);
        }
        QSize sizeHint() const {
            return QSize(640, 480);
        }

    protected:
        void initializeGL();
};

#endif // GL_WIDGET_H


main.cpp:
Code:

#include "GLWidget.h"
#include <QApplication>

int main(int argc, char* argv[]) {
    QApplication app(argc, argv);
    GLWidget glw;
    glw.show();
    return app.exec();
}



Full backtrace:
Code:
(gdb) run
Starting program: /home/kornerr/build/qh/test
[Thread debugging using libthread_db enabled]
[New Thread 0x7f563eadc790 (LWP 8774)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f563eadc790 (LWP 8774)]
0x00007f563e4d0c80 in glCreateShader () from /usr/lib64/libGL.so.1
(gdb) bt
#0  0x00007f563e4d0c80 in glCreateShader () from /usr/lib64/libGL.so.1
#1  0x00007f563b546270 in RendererBase::loadShader (this=0x72c3f0,
    vertexShader=0x7f563b59bb38 "uniform mat4 worldMat;\nattribute vec3 vertPos;\nvoid main() {\n\tgl_Position = gl_ModelViewProjectionMatrix * worldMat * vec4( vertPos, 1.0 );\n}\n",
    fragmentShader=0x7f563b59bbc8 "uniform vec4 color;\nvoid main() {\n\tgl_FragColor = color;\n}\n")
    at /home/kornerr/build/horde3d/trunk/Horde3D/Source/Horde3DEngine/egRendererBase.cpp:441
#2  0x00007f563b546669 in RendererBase::createShader (this=0x72c3f0,
    vertexShader=0x7f563b59bb38 "uniform mat4 worldMat;\nattribute vec3 vertPos;\nvoid main() {\n\tgl_Position = gl_ModelViewProjectionMatrix * worldMat * vec4( vertPos, 1.0 );\n}\n",
    fragmentShader=0x7f563b59bbc8 "uniform vec4 color;\nvoid main() {\n\tgl_FragColor = color;\n}\n")
    at /home/kornerr/build/horde3d/trunk/Horde3D/Source/Horde3DEngine/egRendererBase.cpp:522
#3  0x00007f563b55715f in Renderer::createShaderComb (this=0x72c3f0,
    vertexShader=0x7f563b59bb38 "uniform mat4 worldMat;\nattribute vec3 vertPos;\nvoid main() {\n\tgl_Position = gl_ModelViewProjectionMatrix * worldMat * vec4( vertPos, 1.0 );\n}\n",
    fragmentShader=0x7f563b59bbc8 "uniform vec4 color;\nvoid main() {\n\tgl_FragColor = color;\n}\n", sc=@0x72c770)
    at /home/kornerr/build/horde3d/trunk/Horde3D/Source/Horde3DEngine/egRenderer.cpp:235
#4  0x00007f563b557887 in Renderer::init (this=0x72c3f0)
---Type <return> to continue, or q <return> to quit---
    at /home/kornerr/build/horde3d/trunk/Horde3D/Source/Horde3DEngine/egRenderer.cpp:129
#5  0x00007f563b52f322 in Modules::init ()
    at /home/kornerr/build/horde3d/trunk/Horde3D/Source/Horde3DEngine/egModules.cpp:75
#6  0x00007f563b51ed1c in h3dInit ()
    at /home/kornerr/build/horde3d/trunk/Horde3D/Source/Horde3DEngine/egMain.cpp:94
#7  0x0000000000403114 in GLWidget::initializeGL (this=0x7fffd4e9c580)
    at /home/kornerr/cpp/qt/horde3d/GLWidget.cpp:14
#8  0x00007f563e78beb4 in QGLWidget::glInit ()
   from /usr/lib64/qt/lib/libQtOpenGL.so.4
#9  0x00007f563e7bf99c in QGLWidget::resizeEvent ()
   from /usr/lib64/qt/lib/libQtOpenGL.so.4
#10 0x00007f563d8e1f9a in QWidget::event ()
   from /usr/lib64/qt/lib/libQtGui.so.4
#11 0x00007f563e78efa1 in QGLWidget::event ()
   from /usr/lib64/qt/lib/libQtOpenGL.so.4
#12 0x00007f563d890efd in QApplicationPrivate::notify_helper ()
   from /usr/lib64/qt/lib/libQtGui.so.4
#13 0x00007f563d89917a in QApplication::notify ()
   from /usr/lib64/qt/lib/libQtGui.so.4
#14 0x00007f563c167afc in QCoreApplication::notifyInternal ()
   from /usr/lib64/qt/lib/libQtCore.so.4
#15 0x00007f563d8e09b3 in QWidgetPrivate::sendPendingMoveAndResizeEvents ()
   from /usr/lib64/qt/lib/libQtGui.so.4
---Type <return> to continue, or q <return> to quit---
#16 0x00007f563d8e6e53 in QWidgetPrivate::show_helper ()
   from /usr/lib64/qt/lib/libQtGui.so.4
#17 0x00007f563d8e751a in QWidget::setVisible ()
   from /usr/lib64/qt/lib/libQtGui.so.4
#18 0x000000000040348b in QWidget::show (this=0x7fffd4e9c580)
    at /usr/lib64/qt/include/QtGui/qwidget.h:473
#19 0x00000000004033ee in main (argc=1, argv=0x7fffd4e9c6a8)
    at /home/kornerr/cpp/qt/horde3d/main.cpp:8


But I could successfully display Knight model within SDL. What can be the problem?


Top
 Profile  
Reply with quote  
PostPosted: 08.02.2010, 18:34 
Offline

Joined: 27.09.2008, 07:34
Posts: 35
I even called glCreateShader explicitely before h3dInit:
Code:
void GLWidget::initializeGL() {
    std::cout << "abc\n";
    std::cout << glCreateShader(GL_FRAGMENT_SHADER);
    std::cout << "abc\n";
    std::cout << glCreateShader(GL_VERTEX_SHADER);
    std::cout << "abc\n";
    if (!h3dInit()) {
        h3dutDumpMessages();
        throw std::runtime_error("Could not initialize renderer");
    }
}

and that worked fine. Looks like H3D is screwing up the GL context...


Top
 Profile  
Reply with quote  
PostPosted: 08.02.2010, 19:09 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Since the horde editor is running with Qt it should be possible to run the samples too.
Maybe I find some time that night to create a quick sample.


Top
 Profile  
Reply with quote  
PostPosted: 08.02.2010, 21:49 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
kornerr, I've had this error before multiple times, especially it is a real problem when you try to use Horde3D from .NET (because you cannot change the way you link things there).

It is a problem with the order of linking things, try not to link Horde3D from your library but from your main progam - or not after anything else that links to libGL.so (I think it was the latter, don't really remember).

See
viewtopic.php?f=2&t=685&p=4696&hilit=createshader#p4696

(I don't find the thread I initially opened for this issue)

EDIT:
Oh, and the problem is not that Horde3D breaks the OpenGL context - it just (no idea why) does not load all functions.

EDIT2:
viewtopic.php?f=2&t=384


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 00:00 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Volker wrote:
Maybe I find some time that night to create a quick sample.

I currently don't have a linux pc available but under windows the following sample runs fine (place it under the Samples directory of the Horde3D source code package => trunk/Horde3D/Samples/Horde3D_Qt/main.cpp, trunk/Horde3D/Samples/Horde3D_Qt/GLWidget.cpp, trunk/Horde3D/Samples/Horde3D_Qt/GLWidget.h, or adjust the content dir settings according to your directory setup )


Attachments:
File comment: Knight Sample with Qt (tested with version 4.6 under Windows 7 x86 and MSVC2008)
Horde3D_Qt.zip [4.04 KiB]
Downloaded 1095 times
Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 02:35 
Offline

Joined: 27.09.2008, 07:34
Posts: 35
It works fine even without data.
I tried QMake's project file to build my example and that works fine too. Looks like it's related to CMake. Now only to find how...


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 02:48 
Offline

Joined: 27.09.2008, 07:34
Posts: 35
It's really linkage order.
I ran 'make VERBOSE=1' for cmake build where it displayed each command. The last one had -lGL *before* -lHorde3D, so I made sure -lHorde3D *is before* -lGL, and that helped.
That's a lame error really. But I don't know if I can enforce linkage order to CMake.


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 07:01 
Offline

Joined: 27.09.2008, 07:34
Posts: 35
I found out that it's all about replacing this:
TARGET_LINK_LIBRARIES(test ${QT_LIBRARIES} Horde3D Horde3DUtils)
with this
TARGET_LINK_LIBRARIES(test Horde3D Horde3DUtils ${QT_LIBRARIES})

Still, this stupid dependency of -lHorde3D being before -lGL must be delivered to all Horde3D users.

UPD:
I edited wiki page for Linux build instructions:
http://www.horde3d.org/wiki/index.php5? ... ng_Horde3D


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 09:44 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Thanks for investigating this problem further! Can someone explain me why the linker should make a difference in the linkage order? Or is this just a bug of gcc?


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 12:56 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
Volker wrote:
Thanks for investigating this problem further! Can someone explain me why the linker should make a difference in the linkage order? Or is this just a bug of gcc?
Most linkers in the linux/unix world are single pass, meaning that they can't resolve out-of-order or circular references.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 13:31 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
So this is something one has to care about, but we can't avoid, can we?


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 13:54 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
Volker wrote:
So this is something one has to care about, but we can't avoid, can we?
I believe that if you specify your CMake linking in the right order, it will pass that order on to the underlying linker. However, it will take a bit of trial and error to work out exactly what is the right order.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2010, 18:10 
Offline

Joined: 27.09.2008, 07:34
Posts: 35
What's the exact circular reference Horde3D has?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: Bing [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group