I am rendering a Sphere using OpenGL 3.2 (in Java w/ LWJGL3).
I already a working algorithm to generate the sphere vertices (with GL_TRIANGLE_STRIP primitive). However, I have no idea how to set texture coordinates & normals for these vertex.
float angleA, angleB;
float cos, sin;
float r1, r2;
float h1, h2;
for (angleA = -90.0f; angleA < 90.0f; angleA += SPHERE_STEP) {
r1 = (float) Math.cos(angleA * Math.PI / 180.0);
r2 = (float) Math.cos((angleA + SPHERE_STEP) * Math.PI / 180.0);
h1 = (float) Math.sin(angleA * Math.PI / 180.0);
h2 = (float) Math.sin((angleA + SPHERE_STEP) * Math.PI / 180.0);
for (angleB = 0.0f; angleB <= 360.0f; angleB += SPHERE_STEP) {
cos = (float) Math.cos(angleB * Math.PI / 180.0);
sin = -(float) Math.sin(angleB * Math.PI / 180.0);
renderer.addVertex(r2*cos, h2, r2*sin, s1, t1, n1x, n1y, n1z);
renderer.addVertex(r1*cos, h1, r1*sin, s2, t2, n2x, n2y, n2z);
}
}
My problem is that the texture coordinates s1, s2, t1 and t2 are unknown as well as the normals n1x, n1y, n2z, n2x, n2y, n2z (in the two addVertex lines). I don't know either what kind of texture I should use - I just want a ball (like a marble or a soccer ball). The folowwing image shows the way vertices are generated (I don't have 10 reputation...) : http://i.stack.imgur.com/h6B31.png
Does someone have an idea ? If your proposition is totally different, including a new algorithm but has texture coordinates & normals, It's perfect too !