How can i create a sphere in OpenGL?

Started by
6 comments, last by Quicky 19 years ago
Yes, i want to do exactly what my subject is: Wanna create a Sphere middle in my screen... how tha can be possible ?
"I'm a programmer honey, but you can't beat me" Loaning from the Hurriganes - Roadrunner
Advertisement
gluSphere perhaps?
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
You can use the function digitaldelusion suggested, or you can create your own sphere function for lots more fun. The built in functions for 3D geometry work alright, but they don't always do what you want for things like textures. That's why I recommend building your own. And the best part is, a sphere function with variable resoltuion for the amount of faces doubles as a prism and cube function!

So consider building your own. Think about what you need to do. Specify a radius and a resolution (number of faces), apply a little trig, and you'll be on your way. Then you can add great things like texture coordinates (should be trivial) and vertex normal calculations. I'm getting excited just think about it.

Have fun!
Without order nothing can exist - without chaos nothing can evolve.
ummm... i think i didn't get it...


how can i tell the program, where to put that sphere?

how can i tell the program how big that sphere will be

how can i decide the color of that sphere?


Thank you for answers

and sorry i dont get it
"I'm a programmer honey, but you can't beat me" Loaning from the Hurriganes - Roadrunner
If you look at the function Digital suggested (there's a link in his response), parameter 2 is the radius and parameters 3 and 4 are the vertical/horizontal slices. Just call that function and you're fine.

You're posting in the nehe forums, so I assume you have an opengl project up and running. If you don't, you need to visit nehe's site and get one up and running. Start out but getting a simple triangle drawn and move up from there. If you've already done this, then just call gluSphere as suggested.

And don't appologize for not understanding. It's not something you're doing intentionally, it just takes a minute for some of this stuff to click.

Good Luck!
Without order nothing can exist - without chaos nothing can evolve.
I have figured out the code to generate a dome, and I was wondering if anyone would tell me what I would have to change in my calculations to make a sphere (I know opengl can do it for you, but whats the fun in that?) (PI2 means PI*2)

for (l = 0; l<LAYERS; l++) {    y = sin(l * HALFPI / LAYERS);    w = cos(l * HALFPI / LAYERS);    for(s = 0; s<SLICES; s++) {        x = sin(PI + s * PI2 / SLICES) * w;        z = cos(PI + s * PI2 / SLICES) * w;        vx[LAYERS - (l + 1)] = x * RADIOUSX;<br>        vy[LAYERS - (l + 1)] = y * RADIOUSY;<br>        vz[LAYERS - (l + 1)] = z * RADIOUSZ;<br>    }<br>}</pre><br><br>Thanks,<br>relpats_eht
- relpats_eht
try searching for how to build icosahedron. subdivided icosahedron is much better than tesselated quads.

the easiest way is by using glut and glu func. for details and documentation, look for glut and glu spec at opengl.org
Yes, i have done that before, and another things with OpenGL, i have done 3D-shapes and all between that, non-working camera (sounds funny), but that sphere creation sounds more complicated than, for example a 3D-Cube... but i'll get that any time possible
"I'm a programmer honey, but you can't beat me" Loaning from the Hurriganes - Roadrunner

This topic is closed to new replies.

Advertisement