Hi there, I’m fairly new to OpenGL and was wondering how I can make a function that takes in 2 arguments to draw a hemisphere. I was going to use glClipPlane with gluSphere but I have certain requirements for this problem:
I’m required to use GN_LINE_LOOP to draw the hemisphere in wire frame, compute a surface normal for each vertex and call glNormal3f() before each glVertex3f() call in order to assign a correct surface normal to each vertex, and change to using GL POLYGON,GL QUADS, or GL QUAD STRIP, thus producing a solid-shaded hemisphere. I’m allowed to use GL TRIANGLES
or GL TRIANGLE STRIP at the pole, or I can just co-locate two vertices in a quad representation.
Thanks in advance!
Hi, I’m not going to solve your problem, your professor wouldn’t approve.
But let’s try to think a little bit about it.
Using the gluSphere is an horrible solution, it’s slow, you don’t have any control on witch technique is used. In real world you need to have full control of what you are sending to the GPU.
Now thinks a little bit about your assignment. The normal of a sphere (or a semi-sphere) are pretty easy, they came from the center, so the normal will be
normal = (currentPoint - center)/module(currentPoint-center)
To find the current point is also pretty easy: a sphere (in the origin) is x^2+y^2 = r^2
so if you switch to polar coordinates
x = r sin (theta) cos (phi)
y = r cos (theta) sin (phi)
z = r cos (theta)
if you make a double for loop on theta and phi you can easily find the point coordinate on the sphere.
Now you only have to iterate in the correct way to send the triangles.
The most easy way is to model your hemisphere in a modeling program (blender). Then export it into a file and import it into a program. Maybe you can preprocess it with a stripper too.
There are plenty of algorithms for drawing full spheres online and you should be able to adapt one of those to a hemisphere easily enough. A hint: what’s the normal for each vertex in a sphere of radius 1? (You should be able to look this up too.)