Results 1 to 4 of 4

Thread: opengl header and qt

  1. #1
    Join Date
    Nov 2012
    Posts
    38
    Thanks
    3

    Default opengl header and qt

    hello.
    I'm using an opengl header (gl.h) that is used in Opencl and other library, under windows 7 and i find in my win system, all works fine.
    The problem is that when i add the #include <QtOpenGL\qglwidget> i get these warnings(i get 50 warnings but i show only 2):
    1>C:\Open\trunk\externalIncludes\gl.h(506): warning C4005: 'GL_FOG_COORD_SRC' : macro redefinition
    1> C:\Qt\5.1.0\msvc2012_64_opengl\include\QtGui/qopenglext.h(361) : see previous definition of 'GL_FOG_COORD_SRC'
    1>C:\Open\trunk\externalIncludes\gl.h(507): warning C4005: 'GL_FOG_COORD' : macro redefinition.

    I saw the code and qglwidget add another opengl header , probably this is the problem

    There is a method for cancel these warnings?
    I must use another qt opengl header in all my project?
    What's qt opengl header i should use?

    thanks.

  2. #2
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: opengl header and qt

    omit gl.h. you don't need it when you add qglwidget. if you still need it, then paste your complete code, I will debug it.

  3. #3
    Join Date
    Nov 2012
    Posts
    38
    Thanks
    3

    Default Re: opengl header and qt

    thanks.
    The problem is that i have a my little opengl engine implementation with a textures management that uses gl.h, i must replace gl.h with an other header?
    I wish use my opengl code for various reasons
    this is my relevant code:
    Qt Code:
    1. #pragma once
    2. #include <QtOpenGL\qglwidget>
    3. #include <vector>
    4. #include "ViewBase.h"
    5. #include "Renderer.h"
    6. #include "texture.h"
    7. #include "Controller.h"
    8. #include "View.h"
    9. #include "qmdisubwindow.h"
    10. namespace OPEN
    11. {
    12.  
    13. class CGlWidgetImage : public QGLWidget , public CView< CModel, CController>
    14. {
    15. Q_OBJECT;
    16. public:
    17. CGlWidgetImage();
    18. CGlWidgetImage(const QGLFormat format);
    19. ~CGlWidgetImage(void);
    20. void Init();
    21. void update(CModelBase* pModel, int id);
    22. void mousePressEvent(QMouseEvent* pMouse);
    23. void mouseReleaseEvent(QMouseEvent* pMouse);
    24. void mouseMoveEvent(QMouseEvent* pMouse);
    25. void setMdi(QMdiArea* pMdi );
    26. signals:
    27. void MousePressed(QMouseEvent* pMouse);
    28. void MouseRelased(QMouseEvent* pMouse);
    29. void MouseMoved(QMouseEvent* pMouse);
    30. private:
    31. void init_cl();
    32. ptrRenderer m_ptrRenderer;
    33. ptrTexture m_ptrTexImg;
    34. bool m_b ;
    35. public slots:
    36. void OnIdleOpenGl ();
    37. void setTexture();
    38. protected:
    39. void paintGL();
    40. void initializeGL();
    41. QMdiArea* m_pMdi;
    42. };
    43.  
    44. typedef std::shared_ptr<CGlWidgetImage> ptrGlWidgetImage;
    45. }
    To copy to clipboard, switch view to plain text mode 
    in #include "texture.h" i have
    Qt Code:
    1. #pragma once
    2. #include "graphicslib.h"
    3. #include "OpenObject.h"
    4. #include <gl.h>//----------> problem
    5. using namespace std;
    6. namespace OPEN{
    7. class GRAPHICS_ITEM CTexture : public COpenObject
    8. {
    9. OPEN_DECLARE_RTTI;
    10. STREAM_DECLARATION(CTexture);
    11. public:
    12.  
    13. CTexture(){m_ID = 0;};
    14. CTexture(const std::string& strFileInRes, bool bMipmap, GLint magFilter, GLint minFilter, GLint wrapS, GLint wrapT);
    15. ~CTexture();
    16. bool LoadTexture();
    17. GLuint m_ID;
    18. bool UpdateTexture(string strFile);
    19. void LoadTextureNew(string strFile);
    20. private:
    21. std::string m_strFile;
    22. bool m_bMipmap;
    23. GLint m_magFilter;
    24. GLint m_minFilter;
    25. GLint m_wrapS;
    26. GLint m_wrapT;
    27. };
    28. typedef shared_ptr<CTexture> ptrTexture;
    29. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: opengl header and qt

    Unfortunately, I cannot see your code! don't know why the browser does not load it.

    Anyway, try what I say first. When you add header like gl.h and glew.h, it is very important to keep the order in which you call them. If you mistakenly call a wrong one after another, that may result in errors. In my successful program, I have included the headers as following:
    Qt Code:
    1. #include <GL/glew.h>
    2. #include <GL/gl.h>
    3. #include <GL/glext.h>
    4. #include "glwidget.h"
    To copy to clipboard, switch view to plain text mode 

    try to include
    #include<QGLFunctions>
    in glwidget.h as well. That may help recognize all standard C++ opengl function without using the QT version of it.

    I remember I also had the problem with QT, conflicting standard GLEW library functions with its own, to mix standard functions with QT function, I need to set a flag. If you set this flag, then you can use both version combined. I understand that you cannot use only standard function as you need QT UI . So, if you want to jump from both, use this:

    Qt Code:
    1. initializeGLFunctions();
    2. glewInit();
    To copy to clipboard, switch view to plain text mode 

    and remember to keep the order of headers like this, when using glew:
    Qt Code:
    1. #include <GL/glew.h>
    2. #include <GL/glut.h>
    3. #include <GL/gl.h>
    To copy to clipboard, switch view to plain text mode 

    if you still cannot resolve your case, let the community know.

    Cheers,

Similar Threads

  1. converting GLUT/OpenGL to Qt/OpenGL - displaying issue
    By yoti13 in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2012, 00:45
  2. Generated UI header incorrectly includes class header?
    By droneone in forum Qt Programming
    Replies: 7
    Last Post: 14th June 2012, 14:48
  3. Qt Creator Using alternate openGL library/header files in QT Creator
    By Willybood in forum Qt Tools
    Replies: 2
    Last Post: 24th May 2011, 09:06
  4. QStandardItem's header item and header label
    By feverzsj in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 19:57
  5. How to customize horizontal header (diagonal header view)
    By vairamuthu.g in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 15:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.