Archived

This topic is now archived and is closed to further replies.

TheMatrixXXX

spheres without glu

Recommended Posts

thx for your answers
i used the skydome tut to create a sphere but when i render it with GL_TRIANLGE_STRIP ogl fills the triangles white
is there a way to disable this to get the wireframe mode?

thx
--=[[TheMatrixXXX]]=--

thx to invective for the create link, its very useful

Share this post


Link to post
Share on other sites
This is a very cool piece of code, I adapted from the source that invective pointed to here and I am very pleased with the results, however...

How do I generate texture mapping coordinates from this calculated sphere? Any ideas...

I am using the code from source3.c as my basis. I am rendering the sphere by using GL_TRIANGLES mode and rendering as follows:


      
glBegin( GL_TRIANGLES );
for (i=0; i<NumFacets; i++)
{
glVertex3f( Facets[i].p1.x * Size, Facets[i].p1.y * Size, Facets[i].p1.z * Size );
glVertex3f( Facets[i].p2.x * Size, Facets[i].p2.y * Size, Facets[i].p2.z * Size );
glVertex3f( Facets[i].p3.x * Size, Facets[i].p3.y * Size, Facets[i].p3.z * Size );
}
glEnd();


Which appears to be correct, as the sphere shows up very nicely, but I can't seem to figure out the proper way to generate my texture mapping coordinates.


[edited by - oeginc on June 12, 2002 6:22:58 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by TheMatrixXXX
check out www.spheregames.com
in the skydome tut they describe how to calculate the sphere texture coords.
maybe it help



I''ve tried that, that''s actually the tutorial that I started with originally.. When implementing the texture mapping using their routines, the texture looks all funky and has Squares of textures... Hard to explain w/o showing you, but either way, it doesn''t match the way these sphere are being generated or something cause it looks really bad.


Share this post


Link to post
Share on other sites
quote:
Original post by invective
Did you try using spherical texture mapping on the mesh to generate coordinates? Note that if you are making a unit sphere, then the normal at each vertex is exactly equal to the vertex itself.


I believe I''m doing it correctly... I''ve tried both sources of sphere mapping I could find..


  
// Create our texture mapping coordinates

p->u = (float)(atan2( p->x, p->z ) / (PI * 2)) + 0.5f;
p->v = (float)(asinf( p->y ) / PI) + 0.5f;

-and this way-

// Create our texture mapping coordinates

p->u = (asinf( p->x ) / PI) + 0.5f;
p->v = (asinf( p->y ) / PI) + 0.5f;


And I end up with pretty much the same thing either way, which looks like this

NOTE: The squares on the side of the sphere...

Share this post


Link to post
Share on other sites
I posted my version in this thread. It uses recursion to tesselate an octohedron(?). Probably not as fast as the other functions, but very understandable =) It''s also useful for normal triangle tesselation too(just take out the calls to normalize).

Share this post


Link to post
Share on other sites
I replyed earlier to a similar post you can actully have openGL generate the Texture cordinates for you automaticlly not sure on a ny performance hit this is how i do it if you look up the OpenGL red book it will detail all the options for the comands but this is how i do it

Sphere is my quadric object
texture5[0] is my texture and it''s assocaited filter

gluQuadricOrientation (Sphere,GLU_OUTSIDE);
gluQuadricTexture (Sphere,GL_TRUE);
glBindTexture(GL_TEXTURE_2D, texture5[0]);
glTexGenf(GL_S, GL_OBJECT_PLANE, GL_OBJECT_LINEAR );
glTexGenf(GL_T, GL_OBJECT_PLANE, GL_OBJECT_LINEAR );

this is used to wrapp one large texture around a huge sphere you do get some deformation at the poles of the sphere

Share this post


Link to post
Share on other sites