Jump to content
  • Advertisement
Sign in to follow this  
EvilProgrammer

OpenGL Best way to do spheres

This topic is 5121 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

I want to render a lot of spheres, but I'm not sure if the sphere quadric object is up to the job. I'm using them for now, but in the future I want to be able to have direct control over the texture coordinates, as well as use multitexturing and such. So I thought I would generate a sphere mesh and use a vertex array to render it. The trouble with this is the spheres need to be of varying size. I had a couple solutions to this. The first was to use glScalef, but I know that this messes with your normals and you don't get the proper lighting you want. My second idea was to set up a copy of my array of vertex floats, multiply each one by the proper amount, and feed that into the opengl vertex array. The problem with this is, of course, I have to send in a new array every time I want to render one sphere, and this doesn't seem to be very efficient, besides the fact that it prevents me from being able to compile the array. So is there a nice way for me to use my sphere mesh? Or are quadric objects more powerful than I believe? (I've searched all over for information on them, but it seems you can't affect their texture coordinates)

Share this post


Link to post
Share on other sites
Advertisement
Go for the vertexarray, and write a small vertexshader that scales the sphere. If you just change the vertexposition the normals ofcourse won't change.

Share this post


Link to post
Share on other sites
That looks nice but tesselation is working fine for me, I'm just looking for the most efficient way to render the mesh multiple times per frame with varying radii. I was hoping there was a simpler solution to this than using a vertex shader.

Share this post


Link to post
Share on other sites
There are simpler solutions, but running the vertices through a shader will be loads faster than scaling and renormalizing on the CPU.

Share this post


Link to post
Share on other sites
Quote:
Original post by tok_junior
There are simpler solutions, but running the vertices through a shader will be loads faster than scaling and renormalizing on the CPU.


Excuse me? Who talked about CPU? The fixed pipeline runs on the GPU, you know.

Share this post


Link to post
Share on other sites
Oh yeah, sorry, i was under the impression glScalef did the actual scaling, instead of applying a scale-transform to the current matrix.

Share this post


Link to post
Share on other sites
Quote:
Original post by tok_junior
There are simpler solutions, but running the vertices through a shader will be loads faster than scaling and renormalizing on the CPU.

And you actualy don't need renormalizing if you setup your data right. The vertex program for this is so simple...

Share this post


Link to post
Share on other sites
Quote:
Original post by _DarkWIng_
Quote:
Original post by tok_junior
There are simpler solutions, but running the vertices through a shader will be loads faster than scaling and renormalizing on the CPU.

And you actualy don't need renormalizing if you setup your data right. The vertex program for this is so simple...


If it doesn't use the MV matrix for scaling, I suppose the vp would use a uniform variable as a scale factor. But that's not as flexible as using the matrix. Most times,the order of matrix operations is important. Or do you mean something else?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!