# OpenGL Complete Geosphere

## Recommended Posts

I've managed to cobble up a Geosphere creation algorithm, mostly from the OpenGL Programming Guide.

And it looks like [url="http://www.gamedev.net/topic/116312-request-for-help-texture-mapping-a-subdivided-icosahedron/"]this[/url] link wil give me the UV coordinates. However, from the sounds of it, it could be improved.

Google says maybe a cubemap might be best for geosphere/icosahedron texturing. Not quite sure how to apply a cubemap. Could hack it out on a cube pretty easy, but a geosphere? Lost. If anyone's got a ready tutorial, it would be appreciated. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

And, indexing an icosahedron. Need to know how to automatically generate indices for a subdivided icosahedron - Or maybe just for a triangle subdivided in four.

[code]
float X = 0.525731112119133606F ;
float Z = 0.850650808352039932F ;
Vector3F vp ;
vertices = new Vertex[ 12 ] {
new Vertex( vp = new Vector3F( -X, 0, Z ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( X, 0, Z ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( -X, 0, -Z ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( X, 0, -Z ), vp, Vector2F.Zero ),

new Vertex( vp = new Vector3F( 0, Z, X ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( 0, Z, -X ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( 0, -Z, X ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( 0, -Z, -Z ), vp, Vector2F.Zero ),

new Vertex( vp = new Vector3F( Z, X, 0 ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( -Z, X, 0 ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( Z, -X, 0 ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( -Z, -X, 0 ), vp, Vector2F.Zero ),
} ;

indices = new short[ 60 ] {
1, 4, 0, 4, 9, 0, 4, 5, 9, 8, 5, 4, 1, 8, 4,
1, 10, 8, 10, 3, 8, 8, 3, 5, 3, 2, 5, 3, 7, 2,
3, 10, 7, 10, 6, 7, 6, 11, 7, 6, 0, 11, 6, 1, 0,
10, 1, 6, 11, 0, 9, 2, 11, 9, 5, 2, 9, 11, 2, 7
} ;

for (int i = 0 ; i < indices.Length ; i += 3 )
{
Vector3F one = Vector3F.Zero, two = Vector3F.Zero, normal ;
for ( int j = 0; j < 3 ; ++j )
{
one[j] =
vertices[ indices[ i + 0 ] ].VertexPosition[ j ] -
vertices[ indices[ i + 1 ] ].VertexPosition[ j ] ;
two[j] =
vertices[ indices[ i + 1 ] ].VertexPosition[ j ] -
vertices[ indices[ i + 2 ] ].VertexPosition[ j ] ;
}
normal = Vector3F.Cross( one.Normalized( ), two.Normalized( ) ) ;

vertices[ indices[ i ] ].VertexNormal = normal ;
}
[/code]

Thanks.

##### Share on other sites
*Poke*?

I can probably do the indices and division by graphing it, now that I have graph paper.

##### Share on other sites
All I have left is figuring out how to calculate the UV coordinates.

Shouldn't be too hard.

##### Share on other sites
I'm not sure but perhaps this help

[url="http://iquilezles.org/www/articles/patchedsphere/patchedsphere.htm"]http://iquilezles.org/www/articles/patchedsphere/patchedsphere.htm[/url]

##### Share on other sites
[quote name='pabloreda' timestamp='1339726864' post='4949397']
I'm not sure but perhaps this help

[url="http://iquilezles.org/www/articles/patchedsphere/patchedsphere.htm"]http://iquilezles.or...tchedsphere.htm[/url]
[/quote]
Sorry, that's not a geosphere. But I think I've got it pretty well worked out.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978709
• ### Similar Content

• A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

-What I'm using:
C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.
-Questions
Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• 21
• 14
• 12
• 10
• 12