我一直在寻找几个小时来找到一个在JOGL中绘制纹理球体的好方法。我需要的只是朝正确的方向发展,或者某些代码适用于某人。到目前为止,我所能找到的是helloTexture(虽然它有效,但显然不是球体),是否有办法将其转换为球体,或者我应该在其他地方尝试运气?在JOGL中渲染纹理球体
回答
我写这个给你,这是未经测试,因为我修改了它与GL_TRIANGLES
工作,试图让我知道
radius
是球体半径,rings
是水平切片,sectors
垂直那些
private void createGeometry(float radius, short rings, short sectors) {
float R = 1f/(float)(rings - 1);
float S = 1f/(float)(sectors - 1);
short r, s;
float x, y, z;
points = new float[rings * sectors * 3];
normals = new float[rings * sectors * 3];
texcoords = new float[rings * sectors * 2];
int t = 0, v = 0, n = 0;
for(r = 0; r < rings; r++) {
for(s = 0; s < sectors; s++) {
x = (float) (Math.cos(2 * Math.PI * s * S) * Math.sin(Math.PI * r * R));
y = (float) Math.sin(-Math.PI/2 + Math.PI * r * R);
z = (float) (Math.sin(2 * Math.PI * s * S) * Math.sin(Math.PI * r * R));
texcoords[t++] = s * S;
texcoords[t++] = r * R;
points[v++] = x * radius;
points[v++] = y * radius;
points[v++] = z * radius;
normals[n++] = x;
normals[n++] = y;
normals[n++] = z;
}
}
int counter = 0;
indices = new short[rings * sectors * 6];
for(r = 0; r < rings - 1; r++){
for(s = 0; s < sectors-1; s++) {
indices[counter++] = (short) (r * sectors + s);
indices[counter++] = (short) (r * sectors + (s + 1));
indices[counter++] = (short) ((r + 1) * sectors + (s + 1));
indices[counter++] = (short) ((r + 1) * sectors + (s + 1));
indices[counter++] = (short) (r * sectors + (s + 1));
indices[counter++] = (short) ((r + 1) * sectors + s);
}
}
}
我会如何显示这样的东西?在点,法线和textcoords之前放置了一个float []后,我才开始工作。不过谢谢你。 –
是的,基本上在我的示例中,您可以将'points'和'texcoords'放在'vertexData'里面。 'indexData'内的'indices'。目前跳过“法线”,除非您执行照明,否则不需要这些。相应地修改顶点属性参数,因为现在你的位置是3而不是2;) – elect
我还没有理解。对不起,我吮吸这个...我如何把点和texcoors?我试着把它们放在这里:'private float [] vertexData = new float [] {texcoords,points }; private short [] indexData = new short [] { indicantly };',但这只是给了我一个蓝屏。对不起,如果我错过了一些非常明显的东西... –
- 1. 使用JOGL渲染很多纹理vbo使用JOGL
- 2. 渲染纹理
- 3. 在pyopengl中渲染纹理
- 4. 当渲染纹理时,球体显示多边形
- 5. 用于渲染3d球体的纹理坐标
- 6. FBO:在绘制渲染纹理时渲染纹理,错误的纹理映射
- 7. JOGL 2.0,渲染纹理的深度缓冲区
- 8. OpenGL渲染纹理
- 9. Berkelium渲染纹理
- 10. Three.js渲染纹理
- 11. JOGL颠倒渲染
- 12. '渲染到纹理'和多遍渲染
- 13. JOGL - 多纹理
- 14. Android纹理球体
- 15. 纹理球体C#
- 16. 在SVG/Canvas中渲染球体
- 17. OpenGL ES 2球体渲染
- 18. three.js不会渲染球体
- 19. LWJGL中的纹理球体
- 20. 在OpenGL ES中渲染纹理
- 21. 在directx中渲染多个纹理11
- 22. 在Three.js中穿孔渲染到纹理
- 23. 在Delphi中使用OpenGL渲染纹理
- 24. 使用C#在Direct X中将纹理渲染到纹理中
- 25. OpenGL - 渲染成纹理
- 26. Opengl GLSL渲染纹理
- 27. 渲染纹理问题
- 28. WebGL纹理渲染部分
- 29. 的DirectX纹理渲染incorretly
- 30. LWJGL纹理不渲染
你可以建立。只需添加更多的顶点以形成一个球体并在这些顶点之间绘制三角形。如果你不知道如何建议你先找一个关于绘制三角形的教程,并试着理解它是如何工作的。从这里走向球体或任何其他形状只是绘制更多三角形的问题。 – Thomas
看看这个答案。应该是同样的原则。只是编码在C + +:http://stackoverflow.com/questions/7687148/drawing-sphere-in-opengl-without-using-glusphere – flakes
更好不@flkes,使用不赞成的'GL_QUADS' – elect