I'm trying to find a way to draw a wire sphere using LWJGL (Light Weight Java Game Library), a derived from openGL. I have seen that using GLUT I could use the function glutWireSphere(double, int, int)
, but what about LWJGL? is there any way to do that similarly? Not all people want to use GLUT. I was looking for that but I haven't found anything yet. Thanks in advance.
Asked
Active
Viewed 1,921 times
1

Max Collao
- 91
- 1
- 12
-
2LWJGL doesn't include methods for drawing / building complex models. You have no choice but to build the model yourself, or load it from a 3D model editor. You could also use an external library to do this, if you don't want to do the math yourself. As for making it wireframe, you can just render a normal model after calling glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); – Vincent May 01 '15 at 17:22
-
you can construct the sphere relatively easy with just 2 `for`s using spherical to cartesian coordinate conversion, or by [Sphere triangulation via subdivision](http://stackoverflow.com/a/29139125/2521214) if you want better visual quality – Spektre May 02 '15 at 08:25
1 Answers
0
Well, as Vincent said, it seems that there's no way to do that as simple as with glut. But we can do that with more code. Spektre contributed a way in his comment. This is a way I found to do that using the sphere's parametric equation:
public void myWireSphere(float r, int nParal, int nMerid){
float x,y,z,i,j;
for (j=0;j<Math.PI; j+=Math.PI/(nParal+1)){
glBegin(GL_LINE_LOOP);
y=(float) (r*Math.cos(j));
for(i=0; i<2*Math.PI; i+=Math.PI/60){
x=(float) (r*Math.cos(i)*Math.sin(j));
z=(float) (r*Math.sin(i)*Math.sin(j));
glVertex3f(x,y,z);
}
glEnd();
}
for(j=0; j<Math.PI; j+=Math.PI/nMerid){
glBegin(GL_LINE_LOOP);
for(i=0; i<2*Math.PI; i+=Math.PI/60){
x=(float) (r*Math.sin(i)*Math.cos(j));
y=(float) (r*Math.cos(i));
z=(float) (r*Math.sin(j)*Math.sin(i));
glVertex3f(x,y,z);
}
glEnd();
}
}
Well, it's good enough. You can view better this 3D graphic if you add glRotatef(). For example, you can run the code (in the main loop) this way:
float radius=50
glRotatef(30,1f,0f,0f);
myWireSphere(radius, 10, 10);
Hope this will be helpful for those with the same problem.

Max Collao
- 91
- 1
- 12