Opengl header



  • 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.



  • Try just doing:

    @
    #include <qopengl.h>
    @

    wherever you need the GL stuff.



  • thanks ZapB
    I tryed, but i get these errors
    1>c:\open\trunk\open\graphics\buffers\vbo.h(34): error C3861: 'glGenBuffers': identifier not found
    1>c:\open\trunk\open\graphics\buffers\vbo.h(35): error C3861: 'glBindBuffer': identifier not found
    1>c:\open\trunk\open\graphics\buffers\vbo.h(46): error C3861: 'glBufferData': identifier not found
    1>c:\open\trunk\open\graphics\buffers\vbo.h(48): error C3861: 'glVertexAttribPointer': identifier not found
    1>c:\open\trunk\open\graphics\buffers\vbo.h(48): error C3861: 'glGetAttribLocation': identifier not found
    1>c:\open\trunk\open\graphics\buffers\vbo.h(49): error C3861: 'glEnableVertexAttribArray': identifier not found
    1>c:\open\trunk\open\graphics\buffers\vbo.h(49): error C3861: 'glGetAttribLocation': identifier not found



  • Hmm, weird. qopengl.h includes GL/gl.h for you along with qopenglext.h which is a slightly augmented copy of GL/glext.h. Those functions should be found in there if you are including qopengl.h.

    Are you using a desktop OpenGL build of Qt or one built against ANGLE? If you are using the binary installers for Qt please ensure that it had "opengl" in the filename. If it did not, then it is built against ANGLE which only provides OpenGL ES 2 compatibility.

    Could you post the source that leads to these errors please?



  • sure:
    [code]
    #pragma once

    #include <VboBufferItem.h>
    #define GLM_SWIZZLE
    #include "../glm/glm.hpp"
    #include "../glm/gtc/type_ptr.hpp"
    #include "VboOptions.h"
    #include <openobject.h>
    #include "Shader.h"

    using namespace OPEN;
    using namespace std;

    namespace OPEN{

    enum vboType{

    ID_POSITION,
    ID_COLOR,
    ID_NORMAL,
    ID_TEXT0
    };
    class CShader;
    class GRAPHICS_ITEM CVBo : public COpenObject
    {
    OPEN_DECLARE_RTTI;
    STREAM_DECLARATION(CVBo);
    public:
    GLuint m_IDvbo;
    virtual vboType GetVboType(){return ID_POSITION;};
    protected:
    void Create(ptrShader pEff, void* pData, const long& DataSize, int nSizeEl, ptrVboOptions ptrOptions)
    {
    glGenBuffers(1, &m_IDvbo);
    glBindBuffer(GL_ARRAY_BUFFER, m_IDvbo);
    int size = DataSize;

    int din = ptrOptions->GetDynamics();

    string str = ptrOptions->GetSemantics();

    GLenum l = ptrOptions->GetType();

    glBufferData(GL_ARRAY_BUFFER, size, (GLvoid*) pData, GL_STATIC_DRAW);
    int lPrec = nSizeEl * sizeof(float);
    glVertexAttribPointer(glGetAttribLocation(pEff->m_headerShader, str.c_str()), nSizeEl, GL_FLOAT, GL_FALSE, lPrec, (void*)0/nOffset/);
    glEnableVertexAttribArray(glGetAttribLocation(pEff->m_headerShader, str.c_str()));

    //glBufferData(GL_ARRAY_BUFFER, pData->getSize(), glm::value_ptr(*pData->getAllData()), GetDynamics());
    //glVertexAttribPointer(glGetAttribLocation(ptrEff->m_headerShader, GetSemantics().c_str()), pData->getSizeElement(), GetType(), GL_FALSE, sizeof(glm::value_ptr(pData->getAllData())), (void)0);
    //glEnableVertexAttribArray(glGetAttribLocation(ptrEff->m_headerShader, GetSemantics().c_str()));

    }

    };
    }

    [/code]

    each gl command like glGenBuffers,glBufferData,glVertexAttribPointer ecc... gives me an error.

    Thanks for your help



  • Please try adding

    @
    #include <qopengl.h>
    @

    as the first include to the above.



  • no, doesn't work
    but i saw my qopengl.h and i see that there isn't any opengl function!
    I'm using qt 5.1 64 bit opengl
    this is my qopengl.h code:
    i make some mistake?

    [code]

    #ifndef QOPENGL_H
    #define QOPENGL_H

    #include <QtCore/qglobal.h>

    #ifndef QT_NO_OPENGL

    // Windows always needs this to ensure that APIENTRY gets defined
    #if defined(Q_OS_WIN)

    include <QtCore/qt_windows.h>

    #endif

    #if defined(QT_OPENGL_ES_2)

    if defined(Q_OS_MAC)

    include <OpenGLES/ES2/gl.h>

    include <OpenGLES/ES2/glext.h>

    typedef void* GLeglImageOES;

    else // "uncontrolled" platforms

    include <GLES2/gl2.h>

    typedef char GLchar;

    include <QtGui/qopengles2ext.h>

    ifndef GL_DOUBLE

    define GL_DOUBLE GL_FLOAT

    endif

    ifndef GLdouble

    typedef GLfloat GLdouble;

    endif

    endif // Q_OS_MAC

    #else

    if defined(Q_OS_MAC)

    include <OpenGL/gl.h>

    if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7

    define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED

    include <OpenGL/gl3.h>

    endif

    include <OpenGL/glext.h>

    else

    define GL_GLEXT_LEGACY // Prevents GL/gl.h form #including system glext.h

    include <GL/gl.h>

    include <QtGui/qopenglext.h>

    endif // Q_OS_MAC

    #endif

    // Desktops, apart from Mac OS X prior to 10.7 can support OpenGL 3
    // and desktops apart from Mac can support OpenGL 4
    #if !defined(QT_OPENGL_ES_2)

    if !defined(Q_OS_MAC) || (defined(Q_OS_MAC) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)

    define QT_OPENGL_3

    define QT_OPENGL_3_2

    endif

    #if !defined(Q_OS_MAC)

    define QT_OPENGL_4

    define QT_OPENGL_4_3

    #endif
    #endif

    QT_BEGIN_NAMESPACE

    // When all else fails we provide sensible fallbacks - this is needed to
    // allow compilation on OS X 10.6
    #if !defined(QT_OPENGL_ES_2)

    // OS X 10.6 doesn't define these which are needed below
    // OS X 10.7 and later defien them in gl3.h
    #ifndef APIENTRY
    #define APIENTRY
    #endif
    #ifndef APIENTRYP
    #define APIENTRYP APIENTRY *
    #endif
    #ifndef GLAPI
    #define GLAPI extern
    #endif

    // This block is copied from glext.h and defines the types needed by
    // a few extension classes.

    #include <stddef.h>
    #ifndef GL_VERSION_2_0
    /* GL type for program/shader text */
    typedef char GLchar;
    #endif

    #ifndef GL_VERSION_1_5
    /* GL types for handling large vertex buffer objects */
    typedef ptrdiff_t GLintptr;
    typedef ptrdiff_t GLsizeiptr;
    #endif

    #ifndef GL_ARB_vertex_buffer_object
    /* GL types for handling large vertex buffer objects */
    typedef ptrdiff_t GLintptrARB;
    typedef ptrdiff_t GLsizeiptrARB;
    #endif

    #ifndef GL_ARB_shader_objects
    /* GL types for program/shader text and shader object handles */
    typedef char GLcharARB;
    typedef unsigned int GLhandleARB;
    #endif

    /* GL type for "half" precision (s10e5) float data in host memory */
    #ifndef GL_ARB_half_float_pixel
    typedef unsigned short GLhalfARB;
    #endif

    #ifndef GL_NV_half_float
    typedef unsigned short GLhalfNV;
    #endif

    #ifndef GLEXT_64_TYPES_DEFINED
    /* This code block is duplicated in glxext.h, so must be protected /
    #define GLEXT_64_TYPES_DEFINED
    /
    Define int32_t, int64_t, and uint64_t types for UST/MSC /
    /
    (as used in the GL_EXT_timer_query extension). /
    #if defined(STDC_VERSION) && STDC_VERSION >= 199901L
    #include <inttypes.h>
    #elif defined(sun) || defined(digital)
    #include <inttypes.h>
    #if defined(STDC)
    #if defined(arch64) || defined(_LP64)
    typedef long int int64_t;
    typedef unsigned long int uint64_t;
    #else
    typedef long long int int64_t;
    typedef unsigned long long int uint64_t;
    #endif /
    arch64 /
    #endif /
    STDC /
    #elif defined( __VMS ) || defined(__sgi)
    #include <inttypes.h>
    #elif defined(SCO) || defined(USLC)
    #include <stdint.h>
    #elif defined(UNIXOS2) || defined(SOL64)
    typedef long int int32_t;
    typedef long long int int64_t;
    typedef unsigned long long int uint64_t;
    #elif defined(_WIN32) && defined(GNUC)
    #include <stdint.h>
    #elif defined(_WIN32)
    typedef __int32 int32_t;
    typedef __int64 int64_t;
    typedef unsigned __int64 uint64_t;
    #else
    /
    Fallback if nothing above works */
    #include <inttypes.h>
    #endif
    #endif

    #ifndef GL_EXT_timer_query
    typedef int64_t GLint64EXT;
    typedef uint64_t GLuint64EXT;
    #endif

    #ifndef GL_ARB_sync
    typedef int64_t GLint64;
    typedef uint64_t GLuint64;
    typedef struct __GLsync *GLsync;
    #endif

    #ifndef GL_ARB_cl_event
    /* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */
    struct _cl_context;
    struct _cl_event;
    #endif

    #ifndef GL_ARB_debug_output
    typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
    #endif

    #ifndef GL_AMD_debug_output
    typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
    #endif

    #ifndef GL_KHR_debug
    typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
    #endif

    #ifndef GL_NV_vdpau_interop
    typedef GLintptr GLvdpauSurfaceNV;
    #endif

    // End of block copied from glext.h
    #endif

    // Types that aren't defined in all system's gl.h files.
    typedef ptrdiff_t qopengl_GLintptr;
    typedef ptrdiff_t qopengl_GLsizeiptr;

    #if defined(APIENTRY) && !defined(QOPENGLF_APIENTRY)

    define QOPENGLF_APIENTRY APIENTRY

    #endif

    ifndef QOPENGLF_APIENTRYP

    ifdef QOPENGLF_APIENTRY

    define QOPENGLF_APIENTRYP QOPENGLF_APIENTRY *

    else

    define QOPENGLF_APIENTRY

    define QOPENGLF_APIENTRYP *

    endif

    endif

    QT_END_NAMESPACE

    #endif // QT_NO_OPENGL

    #endif // QOPENGL_H

    [/code]



  • [quote author="giuseppe500" date="1376743303"]no, doesn't work
    but i saw my qopengl.h and i see that there isn't any opengl function!
    I'm using qt 5.1 64 bit opengl
    this is my qopengl.h code:
    i make some mistake?
    [/quote]

    As I said qopengl.h does include GL/gl.h and qopenglext.h which do contain the function declarations.

    Can you provide a small example (1 or two source files) that reproduce the issue that I can try here please?



  • thanks again ZapB, this is my test:
    gltest.h
    [code]
    #pragma once
    #include <qopengl.h>
    #include <QtOpenGL\qglwidget>

    namespace OPEN
    {

    class CGlTest
    {
    public:
    CGlTest(void){
    GLuint m_IDvbo;
    glGenBuffers(1, &m_IDvbo);
    };
    ~CGlTest(void){};
    };

    }
    [/code]

    gltest.cpp(that is empty

    [code]
    #include "GlTest.h"
    using namespace OPEN;
    [/code]

    [code]
    1>------ Build started: Project: qtgltest, Configuration: Debug x64 ------
    1> GlTest.cpp
    1>c:\open\trunk\open\qtgltest\GlTest.h(13): error C3861: 'glGenBuffers': identifier not found
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    [code]



  • Hi,

    add the following in .pro file @QT += core gui opengl@
    and include whatever you want in your .h files :
    @
    #include <GL/glu.h>
    #include <GL/glut.h>
    #include <GL/freeglut.h>
    @

    It worked for me. Hope this will help you.



  • thanks, but i'm not pratical to qt creator and .pro files, i use vs 2012 with qt addin, what i must do?
    and what sense has this change?

    by.



  • hello , i added this preprocessor macro ;GL_GLEXT_PROTOTYPES and the errors disappear, but i don't know if is correct.
    and another problem:
    I have a gl link error
    error LNK2019: unresolved external symbol glShaderSource referenced in function "public: bool __cdecl OPEN::CShaderProgram::compileShaderFromName....

    where are the opengl libs in qt?
    and what lib i must add?
    thanks.



  • i tryed all the gl lib but don't works!
    help!
    thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.