Some problems of using opengl es in qt



  • when I ported my code which is developed by opengl es from windows framework to qt framework, some run errors occured in functions such as "glDrawElements" .
    Are there some differences between qt framework and windows in using buffer objects or kind of "glDrawElements" function ?



  • I'm sure you will have the more appropriate advices when others can see your code and what is wrong with it.



  • when I was using qt with opengl es, in my render code, I used VBO in the way just like in win32 project, the code is the following:

    @
    void DrawMesh()

    {
    #if 1
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    GLuint buf1,buf2;
    glGenBuffers(1,&buf1);
    glBindBuffer(GL_ARRAY_BUFFER,buf1);
    GLfloat a[]={
    0.0f, 0.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f, 1.0f,
    0.0f, 1.0f, 0.0f, 2.0f
    };

    GLushort index[] = {
    0,1,2
    };
    glBufferData(GL_ARRAY_BUFFER,12sizeof(GLfloat),a,GL_STATIC_DRAW);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3,GL_FLOAT,4
    sizeof(GL_FLOAT),0);
    glGenBuffers(1,&buf2);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,buf2);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER,3*sizeof(GLushort),index,GL_STATIC_DRAW);
    glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_SHORT,0);
    glDisableClientState(GL_VERTEX_ARRAY);
    #endif
    }
    @

    when run to "glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_SHORT,0);" error occured "Unhandled exception at 0x0239faec in hellogl_es2.exe: 0xC0000005: Access violation reading location 0x00000000. "
    I want to know why this happened?

    here if I remove VBO parts, no error occured, how to use VBO in QT?



  • Hej,

    I am not sure if that helps you with your problem but I had a similar problem when using VBOs in the QGLWidget on Windows. It worked fine on the Mac ;)

    Anyway seems like you have to get the function pointers to some OpenGL calls before you can use them.

    Here are some snippets from my code

    In the header:
    @#ifdef WIN32
    #include <windows.h>
    #include <GL/gl.h>

    #include "OGL/glext.h"

    extern PFNGLGENBUFFERSPROC glGenBuffers;
    extern PFNGLBINDBUFFERPROC glBindBuffer;
    extern PFNGLDELETEBUFFERSPROC glDeleteBuffers;
    extern PFNGLBUFFERDATAPROC glBufferData;
    #endif
    @

    and when initializing OpenGL do that (UIWidgetScene is my subclass of QGLWidget

    @void UIWidgetScene::initializeGL()
    {
    #ifdef WIN32
    // get the pointer to the GL functions
    glGenBuffers = (PFNGLGENBUFFERSPROC) wglGetProcAddress("glGenBuffers");
    glBindBuffer = (PFNGLBINDBUFFERPROC) wglGetProcAddress("glBindBuffer");
    glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) wglGetProcAddress("glDeleteBuffers");
    glBufferData = (PFNGLBUFFERDATAPROC) wglGetProcAddress("glBufferData");
    _canVBO = (NULL != glGenBuffers) && (NULL != glBindBuffer) && (NULL != glDeleteBuffers) && (NULL != glBufferData);
    #else
    // Mac supports VBO out of the box, GET A MAC!!!!
    _canVBO = true;
    #endif

    ..... do the other OpenGL stuff .....

    @

    Hope that helps,
    Oli



  • but error occured that "PFNGLGENBUFFERSPROC , PFNGLBINDBUFFERPROC , PFNGLDELETEBUFFERSPROC , PFNGLBUFFERDATAPROC not defined" , I searched in the network, it said that these defines in gl/glext.h , so I download opengl files including glext.h , put it into "C:\Program Files\Microsoft Visual Studio 9.0\VC\include\gl" , but it doesn't work



  • Well, I'didn't put the glext.h in the path you did!
    I just placed it in the subdirectory "OGL" in my project root!

    I am not sure why they aren't defined.

    I have the first snippet of code at the top of my header file before including any other files.


Log in to reply
 

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