Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - QT 5.0.2 + OpenGL
Forum - C/C++ - QT 5.0.2 + OpenGL

Avatar
drinoda (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/04/2013

Segnala al moderatore
Postato alle 13:50
Martedì, 16/04/2013
Salve a tutti, ho appena installato QT + i suoi vari tool (tra cui qt creator) e mi sono messo a provare un esempio in cui si utilizza OpenGL all'interno di QT.
L'esempio in questione è "hellogl" fatto dalla Nokia (https://github.com/openwebos/qt/tree/master/examples/opengl ... e t
Vi ho aggiunto il file mancante (qtlogo.h) e tutto sembra trovarsi :D. Il problema è quando provo ad eseguire il codice, il compilatore mi da il seguente output, con relativi errori, in particolare non mi trova alcune variabili di OpenGL (esempio: GL_SMOOTH).
L'output del compitolatore è:
Codice sorgente - presumibilmente Delphi

  1. 13:33:57: Running steps for project hellogl...
  2. 13:33:57: Configuration unchanged, skipping qmake step.
  3. 13:33:57: Starting: "C:\Qt\Qt5.0.2\Tools\MinGW\bin\mingw32-make.exe"
  4. C:/Qt/Qt5.0.2/5.0.2/mingw47_32/bin/qmake.exe -spec win32-g++ CONFIG+=debug CONFIG+=declarative_debug CONFIG+=qml_debug -o Makefile ../hellogl/hellogl.pro
  5. C:/Qt/Qt5.0.2/Tools/MinGW/bin/mingw32-make -f Makefile.Debug
  6. mingw32-make[1]: Entering directory 'C:/Users/mioutente/Documents/anotherworkspace/build-hellogl-Desktop_Qt_5_0_2_MinGW_32bit-Debug'
  7. g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_NEEDS_QMAIN -I../hellogl -I'../../../../../Qt/Qt5.0.2/5.0.2/mingw47_32/include' -I'../../../../../Qt/Qt5.0.2/5.0.2/mingw47_32/include/QtOpenGL' -I'../../../../../Qt/Qt5.0.2/5.0.2/mingw47_32/include/QtWidgets' -I'../../../../../Qt/Qt5.0.2/5.0.2/mingw47_32/include/QtGui' -I'../../../../../Qt/Qt5.0.2/5.0.2/mingw47_32/include/QtCore' -I'debug' -I'.' -I'../../../../../Qt/Qt5.0.2/5.0.2/mingw47_32/mkspecs/win32-g++' -o debug/glwidget.o ../hellogl/glwidget.cpp
  8. ../hellogl/glwidget.cpp: In member function 'virtual void GLWidget::initializeGL()':
  9. ../hellogl/glwidget.cpp:98:18: error: 'GL_SMOOTH' was not declared in this scope
  10. ../hellogl/glwidget.cpp:98:27: error: 'glShadeModel' was not declared in this scope
  11. ../hellogl/glwidget.cpp:99:14: error: 'GL_LIGHTING' was not declared in this scope
  12. ../hellogl/glwidget.cpp:100:14: error: 'GL_LIGHT0' was not declared in this scope
  13. ../hellogl/glwidget.cpp:103:26: error: 'GL_POSITION' was not declared in this scope
  14. ../hellogl/glwidget.cpp:103:52: error: 'glLightfv' was not declared in this scope
  15. ../hellogl/glwidget.cpp: In member function 'virtual void GLWidget::paintGL()':
  16. ../hellogl/glwidget.cpp:111:20: error: 'glLoadIdentity' was not declared in this scope
  17. ../hellogl/glwidget.cpp:112:33: error: 'glTranslatef' was not declared in this scope
  18. ../hellogl/glwidget.cpp:113:41: error: 'glRotatef' was not declared in this scope
  19. ../hellogl/glwidget.cpp: In member function 'virtual void GLWidget::resizeGL(int, int)':
  20. ../hellogl/glwidget.cpp:126:18: error: 'GL_PROJECTION' was not declared in this scope
  21. ../hellogl/glwidget.cpp:126:31: error: 'glMatrixMode' was not declared in this scope
  22. ../hellogl/glwidget.cpp:127:20: error: 'glLoadIdentity' was not declared in this scope
  23. ../hellogl/glwidget.cpp:131:46: error: 'glOrtho' was not declared in this scope
  24. ../hellogl/glwidget.cpp:133:18: error: 'GL_MODELVIEW' was not declared in this scope
  25. Makefile.Debug:796: recipe for target 'debug/glwidget.o' failed
  26. mingw32-make[1]: *** [debug/glwidget.o] Error 1
  27. mingw32-make[1]: Leaving directory 'C:/Users/mioutente/Documents/anotherworkspace/build-hellogl-Desktop_Qt_5_0_2_MinGW_32bit-Debug'
  28. makefile:34: recipe for target 'debug' failed
  29. mingw32-make: *** [debug] Error 2
  30. 13:34:09: The process "C:\Qt\Qt5.0.2\Tools\MinGW\bin\mingw32-make.exe" exited with code 2.
  31. Error while building/deploying project hellogl (kit: Desktop Qt 5.0.2 MinGW 32bit)
  32. When executing step 'Make'
  33. 13:34:09: Elapsed time: 00:12.



L'header del file in questione è:
Codice sorgente - presumibilmente C++

  1. #ifndef GLWIDGET_H
  2.  #define GLWIDGET_H
  3.  
  4.  #include <QGLWidget>
  5.  
  6.  class QtLogo;
  7.  
  8.  class GLWidget : public QGLWidget
  9.  {
  10.      Q_OBJECT
  11.  
  12.  public:
  13.      GLWidget(QWidget *parent = 0);
  14.      ~GLWidget();
  15.  
  16.      QSize minimumSizeHint() const;
  17.      QSize sizeHint() const;
  18.  
  19.  public slots:
  20.      void setXRotation(int angle);
  21.      void setYRotation(int angle);
  22.      void setZRotation(int angle);
  23.  
  24.  signals:
  25.      void xRotationChanged(int angle);
  26.      void yRotationChanged(int angle);
  27.      void zRotationChanged(int angle);
  28.  
  29.  protected:
  30.      void initializeGL();
  31.      void paintGL();
  32.      void resizeGL(int width, int height);
  33.      void mousePressEvent(QMouseEvent *event);
  34.      void mouseMoveEvent(QMouseEvent *event);
  35.  
  36.  private:
  37.      QtLogo *logo;
  38.      int xRot;
  39.      int yRot;
  40.      int zRot;
  41.      QPoint lastPos;
  42.      QColor qtGreen;
  43.      QColor qtPurple;
  44.  };
  45.  
  46.  #endif



e il suo relativo .cpp è:
Codice sorgente - presumibilmente C++

  1. #include <QtGui>
  2. #include <QtOpenGL>
  3.  
  4. #include <math.h>
  5.  
  6. #include "glwidget.h"
  7. #include "qtlogo.h"
  8.  
  9. #ifndef GL_MULTISAMPLE
  10. #define GL_MULTISAMPLE 0x809D
  11. #endif
  12.  
  13. //! [0]
  14. GLWidget::GLWidget(QWidget *parent)
  15.     : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
  16. {
  17.     logo = 0;
  18.     xRot = 0;
  19.     yRot = 0;
  20.     zRot = 0;
  21.  
  22.     qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
  23.     qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
  24. }
  25. //! [0]
  26.  
  27. //! [1]
  28. GLWidget::~GLWidget()
  29. {
  30. }
  31. //! [1]
  32.  
  33. //! [2]
  34. QSize GLWidget::minimumSizeHint() const
  35. {
  36.     return QSize(50, 50);
  37. }
  38. //! [2]
  39.  
  40. //! [3]
  41. QSize GLWidget::sizeHint() const
  42. //! [3] //! [4]
  43. {
  44.     return QSize(400, 400);
  45. }
  46. //! [4]
  47.  
  48. static void qNormalizeAngle(int &angle)
  49. {
  50.     while (angle < 0)
  51.         angle += 360 * 16;
  52.     while (angle > 360 * 16)
  53.         angle -= 360 * 16;
  54. }
  55.  
  56. //! [5]
  57. void GLWidget::setXRotation(int angle)
  58. {
  59.     qNormalizeAngle(angle);
  60.     if (angle != xRot) {
  61.         xRot = angle;
  62.         emit xRotationChanged(angle);
  63.         updateGL();
  64.     }
  65. }
  66. //! [5]
  67.  
  68. void GLWidget::setYRotation(int angle)
  69. {
  70.     qNormalizeAngle(angle);
  71.     if (angle != yRot) {
  72.         yRot = angle;
  73.         emit yRotationChanged(angle);
  74.         updateGL();
  75.     }
  76. }
  77.  
  78. void GLWidget::setZRotation(int angle)
  79. {
  80.     qNormalizeAngle(angle);
  81.     if (angle != zRot) {
  82.         zRot = angle;
  83.         emit zRotationChanged(angle);
  84.         updateGL();
  85.     }
  86. }
  87.  
  88. //! [6]
  89. void GLWidget::initializeGL()
  90. {
  91.     qglClearColor(qtPurple.dark());
  92.  
  93.     logo = new QtLogo(this, 64);
  94.     logo->setColor(qtGreen.dark());
  95.  
  96.     glEnable(GL_DEPTH_TEST);
  97.     glEnable(GL_CULL_FACE);
  98.     glShadeModel(GL_SMOOTH);
  99.     glEnable(GL_LIGHTING);
  100.     glEnable(GL_LIGHT0);
  101.     glEnable(GL_MULTISAMPLE);
  102.     static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
  103.     glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
  104. }
  105. //! [6]
  106.  
  107. //! [7]
  108. void GLWidget::paintGL()
  109. {
  110.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  111.     glLoadIdentity();
  112.     glTranslatef(0.0, 0.0, -10.0);
  113.     glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
  114.     glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
  115.     glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
  116.     logo->draw();
  117. }
  118. //! [7]
  119.  
  120. //! [8]
  121. void GLWidget::resizeGL(int width, int height)
  122. {
  123.     int side = qMin(width, height);
  124.     glViewport((width - side) / 2, (height - side) / 2, side, side);
  125.  
  126.     glMatrixMode(GL_PROJECTION);
  127.     glLoadIdentity();
  128. #ifdef QT_OPENGL_ES_1
  129.     glOrthof(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
  130. #else
  131.     glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
  132. #endif
  133.     glMatrixMode(GL_MODELVIEW);
  134. }
  135. //! [8]
  136.  
  137. //! [9]
  138. void GLWidget::mousePressEvent(QMouseEvent *event)
  139. {
  140.     lastPos = event->pos();
  141. }
  142. //! [9]
  143.  
  144. //! [10]
  145. void GLWidget::mouseMoveEvent(QMouseEvent *event)
  146. {
  147.     int dx = event->x() - lastPos.x();
  148.     int dy = event->y() - lastPos.y();
  149.  
  150.     if (event->buttons() & Qt::LeftButton) {
  151.         setXRotation(xRot + 8 * dy);
  152.         setYRotation(yRot + 8 * dx);
  153.     } else if (event->buttons() & Qt::RightButton) {
  154.         setXRotation(xRot + 8 * dy);
  155.         setZRotation(zRot + 8 * dx);
  156.     }
  157.     lastPos = event->pos();
  158. }
  159. //! [10]



Nel mio file .pro ho già provato ad aggiungere la riga QT += opengl. Per essere più precisi, attualmente è:
Codice sorgente - presumibilmente Plain Text

  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2013-04-16T12:59:44
  4. #
  5. #-------------------------------------------------
  6. HEADERS = glwidget.h \
  7.                 window.h \
  8.                 qtlogo.h
  9. SOURCES = glwidget.cpp \
  10.                 main.cpp \
  11.                 window.cpp \
  12.                 qtlogo.cpp
  13. QT += opengl



Sono su windows 7 e OpenGL è installato, ho già fatto alcuni test a riguardo.;)
Qualcuno di vuoi sa a cosa potrebbe dipendere questo problema?

Ultima modifica effettuata da drinoda il 16/04/2013 alle 13:53
PM Quote
Avatar
Phi (Member)
Expert


Messaggi: 241
Iscritto: 30/12/2009

Segnala al moderatore
Postato alle 15:25
Martedì, 16/04/2013
A me non risulta nessun errore del genere usando l'esempio con lo stesso nome.
Potresti allegare l'intero progetto ?

PM Quote
Avatar
drinoda (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/04/2013

Segnala al moderatore
Postato alle 15:45
Martedì, 16/04/2013
Certo. Con ulteriori prove, noto che è come se trovasse solo alcuni metodi e alcune variabili di OpenGL.
http://www.mediafire.com/?h31gt0qm28q5379




Ultima modifica effettuata da drinoda il 16/04/2013 alle 15:47
PM Quote
Avatar
Phi (Member)
Expert


Messaggi: 241
Iscritto: 30/12/2009

Segnala al moderatore
Postato alle 13:39
Sabato, 20/04/2013
Non capisco da dove derivino i tuoi problemi.
Provando a compilare i tuoi file l'unico problema che ho riscontrato è stato alla riga 147 di qtlogo.cpp che ho modificato così:
Codice sorgente - presumibilmente C/C++

  1. float const *r = mat.constData();


Ma non centra con i tuoi problemi.

Prova a verificare bene il sistema

PM Quote
Avatar
drinoda (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/04/2013

Segnala al moderatore
Postato alle 1:31
Domenica, 21/04/2013
Forse ho capito quale è il mio problema. Per caso hai una versione compilata manualmente per opengl?
Siccome questo è un esempio che si trova già in QtCreator, lanciandolo mi esce come errore che bisogna avere Qt compilato per opengl desktop.

Penso sia questo il motivo.


PM Quote
Avatar
Phi (Member)
Expert


Messaggi: 241
Iscritto: 30/12/2009

Segnala al moderatore
Postato alle 20:13
Domenica, 21/04/2013
No. Uso i pacchetti disponibili di default sui repository di Ubuntu.
Appena mi capita di usarlo provo anche su Windows.

PM Quote
Avatar
drinoda (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/04/2013

Segnala al moderatore
Postato alle 16:47
Lunedì, 22/04/2013
Ho risolto il problema scaricando il codice sorgente e ricompilandolo con la configurazione -opengl desktop.

A quanto pare, qt utilizza una sorta di "angle" per avere la portabilità con altre librerie come DirectX; quindi per avere a "pieno regime" tutte le funzioni di openGL non basta aggiungere opengl nel file .pro, ma bisogna ricompilarlo per opengl.

Penso sia così, visto che alla fine ho risolto in questo modo ;)

Grazie comunque per il tuo aiuto :D

PM Quote