Jump to content
  • Advertisement
Sign in to follow this  
Chon-Ji

3D Sphere

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

Yo! I'm new here and to OpenGL programming ^_^ Could anyone here help me how to create a plain shiny sphere? I've downloaded the Dragging Example from this site, I'm trying to replicate that but for some unknown reason the sphere looks kind of crooked on the sides. Is it possible for me to create a nicely shaped 3d sphere? thanks

Share this post


Link to post
Share on other sites
Advertisement
If you mean that the sphere looks facetted instead of ideally round at the silhouette: OpenGL (but D3D also) does work with flat faces, so in fact it always will show edges. However, if you really want, you could increase the resolution of the sphere, so that the faces become so small that they cover approximately a single pixel of the screen (that is the way subdivision surfaces appear to be smooth). But be aware that this way may really introduce many many faces.

BTW: The sphere is facetted in front also, but due to rendering tricks (i.e. interpolation of normals) it _appears_ smooth to the viewer.

Share this post


Link to post
Share on other sites
wohooo!, I followed the tutorial from the redbook and just as you said, applying some normalization smoothen the sphere quite nicely. Though I still have another problem, I'm trying to make it interactive, for instance, it will change color whenever a user hits a key. It changes color alright but the problem is with the buffering of the screen. It loads kinda slow, making it look like a slide presentation. I know the transisiton could be much smoother and subtle than this, since I've seen similar examples that could change color smoothly. Or is it because I have too many computations invloved in the normalization, that it take so much time to load?

Share this post


Link to post
Share on other sites
Yes, I've tried using that but as I've said it ended up with rough edges on the sides. I'm trying to make the sphere look as smooth as possible, and so far I'm only able to do that by normalizing the vectors. And another thing, when I'm rendering a sphere using gluSphere or glutSolidSphere there were always some grids visible, if I could do away with those then I might go back to using these predefined functions.

Share this post


Link to post
Share on other sites
Maybe you misunderstand the concept of smooth shading? Computing averaged normals for the vertices, and switching on normal interpolation in OGL, does _not_ help against creases in the silhouette of models (I interpret your term "rough edges" that you mean that straight line segments are visible). The aforementioned method does not change anything on the geometry of the model, it only changes how the surface is lit.

Share this post


Link to post
Share on other sites
The smoothest possible spheres would be obtained through either OpenGL quadrics (Lesson 18 on NeHe I believe) or through generating all the vertex and normal data manually and storing them either in a display list, vertex/normal arrays, vertex buffer object, etc. These techniques are all on NeHe.

Share this post


Link to post
Share on other sites
Let me be a little bit nit-picking:

Quote:
Original post by DaedalusOwnsYou
The smoothest possible spheres would be obtained through either OpenGL quadrics (Lesson 18 on NeHe I believe) or through generating all the vertex and normal data manually and storing them either in a display list, vertex/normal arrays, vertex buffer object, etc. These techniques are all on NeHe.

"The smoothest possible spheres" in its nit-picking sense are independent of the shape of the faces in use. One could not reach a better approximation than the resolution of the monitor is permitting. And at that resolution one could not distinguish the shapes of faces. Look e.g. at Pixar's way of sub-division surfaces (keyword "Gary's Game").

However, under a given fixed and in the above sense "unoptimal" resolution, using quads may be noticed as the calmest looking method of rendering spheres. However, I assume that mathematically seen an approximation with tris would be more optimal since the maximum and mean distance to the ideal shape are lesser than as using quads, aren't they? And additionally, using tris in offset raster may introduce a similar calmness to the human eye than using quads does, but I don't know any subjective tests about that.

Share this post


Link to post
Share on other sites
I just followed the example on chpater 2 of opengl redbook and the output looks alright. I have this another problem though with regards to the lighting

http://i2.photobucket.com/albums/y29/Chon-Ji/sphere.jpg

I hope you notice that the sphere on the left looks a bit more like a star wars death star because of that shiny surface unlike the sphere on the right which is nicely lit.

On the left sphere here's what I used for the lighting

//light settings - white light
GLfloat light_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 5.0, 4.0, -4.0, 2.0 };

/*enables light*/

//material settings - blue
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.0,0.0,1.0);

On the right sphere
//light settings - blue light
GLfloat light_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
GLfloat light_diffuse[] = { 0.0, 0.0, 1.0, 1.0 };
GLfloat light_specular[] = { 0.0, 0.0, 1.0, 1.0 };
GLfloat light_position[] = { 5.0, 4.0, -4.0, 2.0 };

/*enables light*/

To sum it up, on the left sphere I used a white light and set the material properties to be blue. For the right sphere I merely used a blue light which produced a better result. I dunno what's causing that big shiny surface, if you use other colors (for the sphere) such as white then it becomes more noticeable. I tried changing the light properties as well as setting other material properties but that didn't help.





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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!