I have a 3D array representing the 3D model i want to render. it consists of ones and zeros, the ones represent the part of the model and zero represents not part of the model.
each array element represents a voxel.
any one know how to render it using opengl a opengl tutorial would also be nice.
NeHe's tutorials, last I read, were terribly outdated. I do not recommend them. (In fact I checked the page again and it lists them as "Legacy tutorials")
I have a 3D array representing the 3D model i want to render. it consists of ones and zeros, the ones represent the part of the model and zero represents not part of the model.
That's not really how meshes work. They operate on vertexes. IE, to draw a cube, you have to supply 8 coordinates... one for each corner of the cube.
You'll have to convert (or recreate) your mesh from voxel based to vertex based if you want to render it.
is there anyway i can display or plot the points in my 3d array to display it visually, i was thinking once the array is fully finished i would convert it to mesh using marching cubes algorithm.
i just need a temporary visualization of the 3d array.
If you don't care about it being optimized, the easiest way would be to just create 8 points per voxel. If the voxel is '1' in your 3d array, add those points to a list. If it's '0', throw them away.
Then once you have the assembled list, you can pass that to OpenGL to draw.
It'll work as a temporary solution, but I wouldn't recommend it for long-term usage because it will create a lot of unnecessary vertexes and will draw a lot of polygons that will never be seen.
so its basically adding and subtracting one from each and all.
so the formula would be for z=0
point 1 = (x-1,y-1,z)
point 2 = (x+1,y+1,z)
point 3= (x+1,y-1),z)
point 4= (x-1,y+1, z)
point 5 - 8 = same as above but add z+1 to all
but the problem is that the coordinate in the array represent the location of the centre of the voxel so i cant do x-1 else that would give the point of another voxel not corner of the voxel
so how about instead of adding and subtracting 1, add and subtract 0.5
would this work.
also what opengl draw function can i use and how do i use it with the list of points i have.
It's never just one function to display stuff with OpenGL. IMO GLUT uses really weird syntax for a C\C++ style library, you have to define each point of your shape with function glVertex3f. The number in bold tells GLUT how many dimensions the shape has and the italicized letter tells it what data type the points are defined in, in that case it would be three dimensions because of the '3' and it would know to treat the numbers as floating point integers because of the 'f'. Each collection of points that define an individual shape have to be (bracketed?) between the glBegin() and glEnd() functions. Remember that OpenGL is just a standard to talk to the hardware, in order to actually see your shapes you need to use yet another library such as SFML (http://www.sfml-dev.org/) in which case you would display them with the sf::Window.Display() function.
As it is only temporary I like glvertex3f and glbegin they work really well as i tested it.
i have a question for people who know glbegin and glend
its regarding glutMainLoop
i don't know where to put it.
below is my pseudocode for my program
glutinit functions
while loop loop through all frames in the webcam
segment image
detect corner in image
calibrate camera using corners
find projection points of 3d points
build 3d array from the projection poins
loop through the array to get x,y,z values of elements which are 1
pass the list to drawscene
glut handler functions glutdisplay, glutkeyboard, glutreshape
end loop
show original image
show segmented image
end while loop
using final 3d array implement marching cubes
which gives new list of vectors made up of triangle points connecting
render that aswell
pass vector to drawscene
call glut handler functions display, keypress, reshape
glutmainloop
i placed it where i think it should be
i don't know if it is the correct place to put it.