如何在没有 glutWireSphere() 的情况下在 openGL 中创建线球?

How to create a wiresphere in openGL without glutWireSphere()?

我正在尝试找到一种使用 LWJGL(轻量级 Java 游戏库)绘制线球的方法,它是从 openGL 派生的。我已经看到使用 GLUT 我可以使用函数 glutWireSphere(double, int, int),但是 LWJGL 呢?有什么办法可以做到这一点?并非所有人都想使用 GLUT。我一直在寻找那个,但我还没有找到任何东西。提前致谢。

好吧,正如文森特所说,似乎没有办法像过剩那样简单地做到这一点。但是我们可以用更多的代码来做到这一点。 Spektre 在他的评论中贡献了一种方式。这是我发现使用球体参数方程的一种方法:

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();
    }
}

嗯,已经够好了。如果添加 glRotatef(),您可以更好地查看此 3D 图形。例如,您可以这样 运行 代码(在主循环中):

float radius=50
glRotatef(30,1f,0f,0f);
myWireSphere(radius, 10, 10);

希望对遇到同样问题的人有所帮助。