nmm02003's picture

Rendering multiple objects

Hi All,

I have coded a mesh viewer that loads a particular file type (.mat) with vertex, normal and face information. This .mat file is created in Matlab and exported out so I can import it into my mesh viewer that is written in Visual Basic NET using OpenTK.

At the moment my mesh viewer creates a VBO and loads the data from the .mat file to the VBO, and then starts rendering the information. It works pretty nice even for data sets that contain over 1 million vertices. The issue is that I can only load one mesh at a time.

What I want to do now is be able to load multiple meshes into the viewer and translate/rotate them individually. I'm not quite sure how to do this. I've tried searching OpenTK forum for this with no luck. If anyone can point me in the right direction I should be able to figure it out.


Comment viewing options

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

Dirty: Just generate multiple VBO identifier, upload your 1.mat to the first VBO, 2.mat into 2nd, etc. and when drawing loop through them.
Clean: http://en.wikipedia.org/wiki/Scene_graph

nmm02003's picture

Thanks Inertia. I have my multiple VBO working now.

I've been working on trackball rotation and have it working quite nicely for translating and rotating the world coordinates. This requires that I track the 3D origin and calculate the corresponding 2D screen coordinates. I do this by using the glu.project method. One of the inputs to this is the modelview matrix. I tried giving glu.project the actual modelview matrix and it only works if the user doesn't rotate the scene, i.e. if the rotation matrix is identity. So I ended up giving glu.project the transformation matrix rather that the actual modelview matrix and it seems to calculate the screen coordinates well. This is because my world transformation matrix is Rotation * Translation, so where ever i translate the world origin to, everything rotates about the origin, so in this case i can see that rotations don't really effect anything.

Now I'm trying to implement this for each of the vbo's, i.e. to local coordinate systems. Not as straight forward for me as with the world. for each vbo i have their respective rotation and translation matrix in relation to the world. If I multiply translation_world * translation_vbo I get the global translation, same as for the rotation. But now here each vbo is transformed according to Translation_world * Rotation_world when it comes to rotating the world. When I press shift on the keyboard I locally transform the vbo.

My issue is that using glu.project isn't giving me the correct viewport 2D mouse coordinates. I know why, because now i'm sending the rotation values along with translation, and that's because if say i have one VBO translated +10 in the x direction and i rotate the world then the VBO swings on a 10 unit arm around the origin, so in effect visually its origins 2D screen coordinates are changing but glu.project is giving me coordinates in negative or way off the size of my viewport? It only gives me correct viewport mouse coordinates if i don't rotate the world, i.e. that world rotation matrix is identity. I would expect that if I translate the vbo + 10 units and and rotate the world 90 degrees so that the vbo is directly in front of my world origin that the viewport mouse coordinates would be close to my world origin viewport mouse position, that is directly in the middle of my viewport, but this is not the case.

I have my world transformation matrix, which I assume is my viewmatrix, and my vbo transformation matrix in relation to the world origin. Any help in pushing me in the right direction for getting the 2D viewport mouse position of the vbo origin would be greatly appreciated. I'm going into my second week of research and trying different things out with no success.

Inertia's picture

The view matrix defines transformation of the camera more here

Please use the search function for your projection problem, there's quite a few topics on that already. When in doubt the solutions using Matrix4 are better than anything using Glu.

nmm02003's picture

Hi All,

I'm trying to find a way to clear buffer data in a VBO. I generate multiple buffers using Gl.GenBuffers and then delete them using GL.DeleteBuffers:

GL.GenBuffers(1, verticesBufferId(j))
GL.GenBuffers(1, trianglesBufferId(j))
GL.DeleteBuffers(1, verticesBufferId(j))
GL.DeleteBuffers(1, trianglesBufferId(j))

I notice then that OpenGL assigned an integer pointer for each buffer in sequential order starting from 1 to number of buffers. Later in the code I bind the buffer and pass it data data using:


Then I bind the buffer to 0 (zero) to release it.

Now I want to clear the buffer and data within it altogether but I'm not quite sure the best way to do this. I don't want to send the buffer 0 as data because then the buffer still exists even though it has no data, I really want to delete the buffer altogether. Whatever I try to do, when I call GenBuffers to generate more buffers the integer pointer numbering continues. So lets say the first time I called GenBuffers and wanted to create 10 buffers to then pass data to, it generates integer pointers numbered 1-10. Then when I want to create more buffers, say 5, GenBuffers generates integer pointers numbered 11-15. This makes me think that buffers 1-10 are still in existence with data in them (holding onto valuable memory). I can't seem to find a command that will clear all the buffers (and all data within) so when I call GenBuffers the numbering starts from 1 again.

Any help in this would be greatly appreciated.