Best way to do spheres

Started by
12 comments, last by mikeman 19 years, 6 months ago
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)
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.
You might find this helpful.
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.
Just use glScalef and glEnable(GL_NORMALIZE) to take care of the normals.
There are simpler solutions, but running the vertices through a shader will be loads faster than scaling and renormalizing on the CPU.
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.
Oh yeah, sorry, i was under the impression glScalef did the actual scaling, instead of applying a scale-transform to the current matrix.
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...
You should never let your fears become the boundaries of your dreams.
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?

This topic is closed to new replies.

Advertisement