opengl help


does anybody know how to use opengl for c++.

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.

Last edited on
I think this guy NeGe or whatever has some good tutorials.

Lazy Foo has some good tutorials, but instead of GLUT use something better such as SDL/SFML for input.

EDIT - It's NeHe.
Last edited on by Fredbill30
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")

This guy has a very good introduction/tutorial:

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.
Last edited on
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.

any hints.
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.
Disch wrote:

vertexes is a proper plural form of vertex:
That's bizarre! It sounds so odd!

Edit: I didn't know that vertex is the term for the highest point of the skull either. Every day's a school day.
Last edited on
example lets say i have a 5x5x5 array

only the middle is 1s

0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0

and it is the same for all 5 in the z dimension.

so for the first voxel which is one is (1,1,0) so the 8 points for this voxel would be

(0,0,0) (2,2,0) (2,0,0) (0,2,0)
(0,0,1) (2,2,1) (2,0,1) (0,2,1)

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.

You can't just use a draw function and be all good. You need to actually LEARN it.
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 ( in which case you would display them with the sf::Window.Display() function.
Last edited on
I think glVertex3f is a opengl function.
You are correct, GLUT prefixes it's functions with 'glut' doesn't it?
Last edited on
Yea. I admit though openGL feels weird for C/++ style programming.

Once I get into it a lot I'm almost certain I'll write a wrapper for it, same with SDL.
Last edited on by Fredbill30
glVertex3f is also a deprecated function that you shouldn't use. As are glBegin/glEnd.

Drawing in OpenGL involves filling a memory buffer with vertex data, then instructing OpenGL to use that memory buffer to draw polygons.

It is not really straightforward.
Last edited on
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

i placed it where i think it should be
i don't know if it is the correct place to put it.

Topic archived. No new replies allowed.