ssarangi's picture

Problem with VBO Rendering - memory corruption

Hi All,
I have been trying to render a mesh using VBO's however, it crashes saying internally the memory has been corrupted. I have worked with VBO's in C and they had worked fine so there is definitely something I am missing here. I have been working for hours on this to no avail. I would really appreciate the help if someone could take a quick look at the code I am posting.

Using an immediate mode technique works and its commented out right now just below the VBO code. The main code for this is in the mesh.cs file with the render method.

The link for the code is here : http://www.megaupload.com/?d=M61HDK7J

I would again... really really appreciate any help with this.

Thanks,

Satyajit

Ps: The filename should be changed from buddha_res4.ply to buddha.ply


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ssarangi's picture

The filename which is being loaded should be changed from buddha_res4.ply to buddha.ply

the Fiddler's picture

In Mesh.cs:

  1. vertex_vbo remains 0. Check your create_vbo() method: you store the VBO id in a local vertex_VBO, which goes out of scope when the method returns. You need to use the vertex_vbo field instead.
  2. attach_vbo() should also bind your element array (you are missing a GL.BindBuffer(BufferTarget.ElementArrayBuffer, index_vbo) call)
  3. render() should call attach_vbo() before GL.DrawElements().
ssarangi's picture

Thanks a lot Fiddler. That works... Thanks for pointing out the structure vs class difference for Vector3f methods.

However, I have a general question which might be due to my ignorance but somehow C# doesn't allow me to write extension methods for structures ( i.e. say for the current Vector3 implementation of OpenTK).

The way I was doing it was to use something like this...

publlic static vector_methods(this Vector3 v)
{
// Do Something
}

Is this allowed for structures or does it work only with classes ?

Thanks.....

Satyajit

Ps: I really think OpenTK is a very comfortable API to work with... :)

the Fiddler's picture

This should work:

public static class MathExtensions
{
    public static Vector3 DoSomething(this Vector3 v)
    {
        // Do something on v
        return v;
    }
}

I've been using this pattern extensively, it's very useful.

The only limitation is that you have to return a new Vector3 instance (or "v"). Any changes you make to "v" above won't be reflected back to the original structure by default (your changes affect a copy, not the original structure - that's another difference between value types and classes).