PDA

View Full Version : opengl header and qt



giugio
17th August 2013, 07:34
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.

saman_artorious
17th August 2013, 07:59
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.

giugio
17th August 2013, 08:42
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:


#pragma once
#include <QtOpenGL\qglwidget>
#include <vector>
#include "ViewBase.h"
#include "Renderer.h"
#include "texture.h"
#include "Controller.h"
#include "View.h"
#include "qmdisubwindow.h"
namespace OPEN
{

class CGlWidgetImage : public QGLWidget , public CView< CModel, CController>
{
Q_OBJECT;
public:
CGlWidgetImage();
CGlWidgetImage(const QGLFormat format);
~CGlWidgetImage(void);
void Init();
void update(CModelBase* pModel, int id);
void mousePressEvent(QMouseEvent* pMouse);
void mouseReleaseEvent(QMouseEvent* pMouse);
void mouseMoveEvent(QMouseEvent* pMouse);
void setMdi(QMdiArea* pMdi );
signals:
void MousePressed(QMouseEvent* pMouse);
void MouseRelased(QMouseEvent* pMouse);
void MouseMoved(QMouseEvent* pMouse);
private:
void init_cl();
ptrRenderer m_ptrRenderer;
ptrTexture m_ptrTexImg;
bool m_b ;
public slots:
void OnIdleOpenGl ();
void setTexture();
protected:
void paintGL();
void initializeGL();
QMdiArea* m_pMdi;
};

typedef std::shared_ptr<CGlWidgetImage> ptrGlWidgetImage;
}

in #include "texture.h" i have



#pragma once
#include "graphicslib.h"
#include "OpenObject.h"
#include <gl.h>//----------> problem
using namespace std;
namespace OPEN{
class GRAPHICS_ITEM CTexture : public COpenObject
{
OPEN_DECLARE_RTTI;
STREAM_DECLARATION(CTexture);
public:

CTexture(){m_ID = 0;};
CTexture(const std::string& strFileInRes, bool bMipmap, GLint magFilter, GLint minFilter, GLint wrapS, GLint wrapT);
~CTexture();
bool LoadTexture();
GLuint m_ID;
bool UpdateTexture(string strFile);
void LoadTextureNew(string strFile);
private:
std::string m_strFile;
bool m_bMipmap;
GLint m_magFilter;
GLint m_minFilter;
GLint m_wrapS;
GLint m_wrapT;
};
typedef shared_ptr<CTexture> ptrTexture;
}

saman_artorious
19th August 2013, 15:29
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:


#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include "glwidget.h"


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:



initializeGLFunctions();
glewInit();


and remember to keep the order of headers like this, when using glew:


#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/gl.h>


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

Cheers,