Jump to content
  • Advertisement
Sign in to follow this  
sunburntfish

OpenGL Issues with VBOs and c++/cli

This topic is 2553 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.[/quote]


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.

Share this post


Link to post
Share on other sites
Advertisement

Check for errors with glGetError after your OpenGL calls and check so that the mapped pointer is valid.


I reduced the above constructor to just call glGenBuffers and I receive the same error message as before (System.AccessViolationException) when I call glGetError().


Share this post


Link to post
Share on other sites
glGenBuffers isn't in opengl32.dll. You must load it dynamically with wglGetProcAddress, and then use the obtained function pointer to call it. (The same goes for glMapBuffer etc.)
If you're already doing that, make sure you have a valid current context and check return codes during initialization. Also, check the OpenGL version of your context and validate function pointers to make sure everything you try to use is supported.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!