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.