
Simple Objects
Posted Monday, 6 April, 2009 - 14:04 by Soundbomber inAs an aside to my post on Cut Outs, as an alternative to using C.S.G to model my holes/cut-outs, I could also model the geometry using a model editor, thus hard coding the cut-outs into the model. My problem is this, so far to successfully model a 3d object, i have had to create individual vertices for EVERY triangle that makes up that model, so for example a cube-instead of only requiring 8 vertices, would require 6 faces*2 triangles*3 vertices=36 vertices. When I use the minimum of 8 vertices I only see certain facets of the cube shape.
Any ideas as where I am going wrong?


Comments
Re: Simple Objects
What model editor are you using? Look for "convex subpolygons" or something like that, to break down your concave and multi-contour filled polygon. It's a whole plethora of algorithms to do this "tesselation".
Also, you should be able to use VBOs (Vertex Buffer Objects, look for them on opentk.com) to "share" vertices between different primitives (triangles or polygons). It's called "indexed mode" or similar.
Re: Simple Objects
The image above is just a simple cube created using DeleD 3D editor. I am already using VBOs.
Here is a sphere using the same program.
Re: Simple Objects
From the looks, this seems like an error in the element buffer. Do you calculate that manually, or is it created by the editor? Also, make sure the editor is exporting triangles not quads (I've been burnt by that before).
Re: Simple Objects
I calculate the buffers myself and the editor is exporting triangles not quads.
Re: Simple Objects
The vertices look correct (you can verify with
DrawArraysandBeginMode.Points), which leaves the elememt buffer as the most probable source for the error. In fact, the second image looks exactly like what I got when I miscalculated the element buffer for a skydome, recently.It's difficult to tell what the exact problem is without code, but this is the most likely explanation. Even an off-by-1 error will result in a rendering like this.
Re: Simple Objects
Here is my render code. I would be grateful if someone would care to check it out for integrity.
Re: Simple Objects
Since you have an index buffer, use GL.DrawElements instead of GL.DrawArrays.
Re: Simple Objects
Moreover, you want to call
BufferDataonce only, at the point where you load the model. To draw the models, you need to:DrawArraysif you don't have an element buffer,DrawElementsif you have one.As Inertia pointed out, the last point is throwing your rendering off.
Note that if you do not want to use an element buffer, you'll have to issue every vertex multiple times (which carries a speed penalty).
Re: Simple Objects
Ok, tried the following without success:
nothing appears to get rendered.
Re: Simple Objects
I felt in the same error just few days ago. Since I'm very newbie in OpenGL programming, I think you have to specify just a
InetPtr.Zeroinstead of the entire indices array, because you've already loaded indices in your VBO.Can read more here: http://www.opentk.com/node/732
Fiddler and/or Inertia will tell more about it, I think ;-)