• Advertisement
Sign in to follow this  

How can i create a sphere in OpenGL?

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yes, i want to do exactly what my subject is: Wanna create a Sphere middle in my screen... how tha can be possible ?

Share this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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)][s] = x * RADIOUSX;
vy[LAYERS - (l + 1)][s] = y * RADIOUSY;
vz[LAYERS - (l + 1)][s] = z * RADIOUSZ;
}
}


Thanks,
relpats_eht

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement