C++/CLI and VBOs

Hello

I have previously written an application in native c++ in which I used OpenGL and had no trouble using Vertex Buffer Objects to render my data. I wanted to use C# and windows forms to write a GUI for my application and have managed to render a basic system by following this tutorial. This code is placed in a “RenderWindow.dll” and calls to render an application by including “mApplication.dll”. To do this I have written a c++/cli wrapper for my application:



class managedApplication{
//included to show that my c++/cli application just has a pointer to a native application
private:
    nativeApplication *myApplication;
};

managedApplication::managedApplication()
{
    m_app = new nativeApplication();
}

void
managedApplication::Draw()
{
    glClearColor(0.0f, 0.7f, 0.0f, 0.0f);

    glClear( GL_COLOR_BUFFER_BIT );
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glEnable(GL_POINT_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    m_app->Draw();

    glFlush ();
}

All works fine until I want to use VBOs. I have the following in the constructor for my native c++ application:


nativeApplication::nativeApplication(){
    glGenBuffers(1, &testVBO);
    glBindBuffer(GL_ARRAY_BUFFER, testVBO);
    glBufferData(GL_ARRAY_BUFFER, numPoints*2*sizeof(float), 0, GL_DYNAMIC_DRAW);
    float *ptr = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
    float x = 100.0f;
    float y = 100.0f;
    for(uint i = 0; i < numPoints.size(); ++i){
        ptr[i*2] = x;
        ptr[(i*2)+1] = y;
        x += 10.0f;
        y += 10.0f;
    }
    glUnmapBuffer(GL_ARRAY_BUFFER);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

This compiles no problem but when I run it I get the following error:

An unhandled exception of type ‘System.AccessViolationException’ occurred in mApplication.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

This occurs at this line:

glBindBuffer(GL_ARRAY_BUFFER, testVBO);

I’d like to be able to take advantage of VBOs in my rendering but this seems to cause issues and I have not been able to find any help through quite extensive search. I would like to stick with using the standard OpenGL libraries rather than using anything like the Tao framework or the Open Toolkit library so if anyone has a solution to this or pointers that would be great. Thanks in advance for any advice.

glGenBuffers works but glBindBuffer does not?
Still, the first thing to check is to make sure that glBindBuffer has a valid address (if you are getting the function pointers by yourself instead of using GLEW).

Thank you for your reply. I reduced the above constructor to just call glGenBuffers(1, &testVBO) and it produces the same error message. Before the call testVBO is initialised to 0. I am including glew.h and so the problem should not be with the function pointers I think.

The header file is just text. It doesn’t actually do anything.

Read
http://www.opengl.org/wiki/Extension_Loading_Library

Apologies but I am a little confused about what that means I am supposed to do. I have tried calling glewInit() just after I initialise OpenGL but this has had no effect. How do I define the function pointers?

GLEW handles the function definitions.
Some people just include the glew header and they don’t understand why glewInit must be called and they get a crash.

In you case, the next thing to check is that you have the GL version that you require.
For VBO, it is GL 1.5 at minimum.

If that turns out to be ok as well, then I’m out of ideas.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.