Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [SOLVED] OpenGL + Qt using CMake
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] OpenGL + Qt using CMake

Scheduled Pinned Locked Moved Installation and Deployment
4 Posts 2 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    api55
    wrote on 26 Nov 2014, 11:26 last edited by
    #1

    I have a Qt project created with a .pro file that I need to migrate it to a CMakeLists. This project uses a simple OpenGL animation to show a 3D model of a hand. I already change it to use CMake, but I encounter 2 problems. (The program compiles but it doesn't run properly)

    1. The memory consumption of the program passes from being 20-50 mb using the .pro file, to 1.3 gb using CMake (Maybe some library being loaded completely or something??)
    2. The program runs incredibly slow (like 1 frame every 5-10 seconds) in contrast with the speed from using the .pro file (approx. 3 frames per second)

    The question is, what I am doing wrong and how can I fix it?

    Here is the .pro file

    @ QT += core gui opengl

    TARGET   = RGBD_3D_Viewer
    TEMPLATE = app
    
    
    SOURCES +=  main.cpp\
                mainwindow.cpp \
                glwidget.cpp \
                glwidget_Camera.cpp \
                glwidget_Comm.cpp \
                glwidget_Extractors.cpp \
                glwidget_Rendering.cpp \
                glwidget_Video.cpp \
                glwidget_UI_Mouse.cpp \
                glwidget_OpenGL.cpp \
                mainwindow_Comm.cpp \
                mainwindow_GUI.cpp \
                model.cpp \
                cameraSet.cpp \
                model_Mesh.cpp \
                model_Skeleton.cpp \
                model_Skin.cpp \
                model_Extra_SkinningStuff.cpp \
                animation.cpp \
                animation_Transform.cpp \
                videoSequence.cpp \
                sequence.cpp \
                mainwindow_UI_Keyboard_Mouse.cpp \
                tracker.cpp \
                mainwindow_FrameNumber.cpp \
                model_Limits.cpp \
                animation_Files_CompleteSequence.cpp \
                mainwindow_MODELS_INFO.cpp \
                modelSET.cpp \
                animation_0_RotAxes_Limits.cpp \
                myMATH.cpp \
                types_Background.cpp \
                model_Extra_VOI.cpp \
                fingertipSet.cpp \
                tracker_OnIndexChange.cpp \
                tracker_wFeatureSet.cpp
    
    HEADERS  += mainwindow.h \
                glwidget.h \
                model.h \
                cameraSet.h \
                animation.h \
                videoSequence.h \
                sequence.h \
                tracker.h \
                mymath.h \
                modelSET.h \
                ui_mainwindow.h \
                featureSet.h \
                typesBackground.h \
                fingertipSet.h
    
    FORMS    += mainwindow.ui
    
    
    
    INCLUDEPATH += /usr/include/eigen3/
    
    INCLUDEPATH += /home/cvg11/projects/development/RGBD_3D_Viewer/glm
    
    
    LIBS += -L/usr/local/lib/
    LIBS += -lopencv_core
    LIBS += -lopencv_highgui
    
    
    QMAKE_CXXFLAGS += -O3
    QMAKE_CXXFLAGS += -frounding-math
    #QMAKE_CXXFLAGS += -std=c++0x@
    

    Here is the CMakeLists.txt file

    @ project(3d_viewer)
    cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

    include_directories(${CMAKE_CURRENT_BINARY_DIR})
    include_directories( ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/glm)
    
    find_package( PkgConfig )
    pkg_check_modules( EIGEN3 REQUIRED eigen3 )
    include_directories( ${EIGEN3_INCLUDE_DIRS} )
    
    # Opencv required
    find_package(OpenCV COMPONENTS core highgui REQUIRED)
    include_directories(${OPENCV_INCLUDE_DIRS})
    link_directories(${OPENCV_LIBRARY_DIRS})
    add_definitions(${OPENCV_DEFINITIONS})
    
    message("\n\nFound OpenCV\n\n")
    
    
    # Qt4 required
    find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
    set(QT_USE_QTOPENGL TRUE)
    include(${QT_USE_FILE})
    add_definitions(${QT_DEFINITIONS})
    
    message("\n\nFound QT4\n\n")
    
    
    INCLUDE_DIRECTORIES(${QT_QTOPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} )
    
    #set the default path for built executables to the "bin" directory
    set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
    #set the default path for built libraries to the "lib" directory
    set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
    
    
    file(GLOB VIEWER_SOURCES src/*.cpp)
    
    file(GLOB VIEWER_INCLUDES include/*.h)
    
    
    # set QT headers
    SET(QT_HEADERS
        include/mainwindow.h
        include/glwidget.h
        )
    
    #set QT forms
    SET(QT_FORMS
        ui/mainwindow.ui
    )
    
    # create moc for QT
    QT4_WRAP_CPP(QT_MOC ${QT_HEADERS})
    
    # process ui
    QT4_WRAP_UI(QT_FORMS_HEADERS ${QT_FORMS})
    
    ADD_EXECUTABLE(3d_viewer ${VIEWER_SOURCES} ${VIEWER_INCLUDES}
        ${QT_HEADERS}
        ${QT_MOC}
        ${QT_FORMS})
    
    TARGET_LINK_LIBRARIES(3d_viewer ${QT_LIBRARIES} ${OpenCV_LIBS} )
    set_property(TARGET 3d_viewer PROPERTY COMPILE_DEFINITIONS QT_SHARED)@
    

    If needed I can give the output when I compile with @make VERBOSE=1@

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 26 Nov 2014, 22:57 last edited by
      #2

      Hi and welcome to devnet,

      From a quick look, I haven't found the equivalent of
      @
      QMAKE_CXXFLAGS += -O3
      QMAKE_CXXFLAGS += -frounding-math
      @

      in your CMakeLists.txt

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        api55
        wrote on 26 Nov 2014, 23:07 last edited by
        #3

        Hi, thanks for the welcome

        I already tried the frounding-math variable, without much success, and by default cmake CXXFLAGS uses -O3 -DNDEBUG at least this is my case. Also, I already tried the -lpthreads flag with -D_REENTRANT that aparently is used by the .pro files (not explicitly)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          api55
          wrote on 27 Nov 2014, 10:53 last edited by
          #4

          After fighting for days with this problem, I found out that it was the -O3 flag. Apparently, Qt is using -O3 -O2 and it is taking the last one, and for the final linking it is using -O1. I changed the flags to use -O2 and everything started to work as fast as it should be and using a normal amount of RAM.

          1 Reply Last reply
          0

          1/4

          26 Nov 2014, 11:26

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved