JOGL 中的纹理二次曲面
我无法对 glu Quadric (gluSphere) 进行纹理处理: 我得到的不是纹理,而是纹理的平均颜色。
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glEnable(GL.GL_TEXTURE_GEN_S);
gl.glEnable(GL.GL_TEXTURE_GEN_T);
sunTexture = TextureIO.newTexture(new File("sun.jpg"),false);
float[] rgba = {1f, 1f, 1f};
gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, rgba, 0);
gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, rgba, 0);
gl.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 0.5f);
sunTexture.enable();
sunTexture.bind();
GLUquadric sun = glu.gluNewQuadric();
glu.gluQuadricTexture(sun, true);
glu.gluSphere(sun, 5, DETAIL, DETAIL);
sunTexture.disable();
I can't manage to texture a glu Quadric (gluSphere):
What i get instead of the texture, is an average color of the texture.
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glEnable(GL.GL_TEXTURE_GEN_S);
gl.glEnable(GL.GL_TEXTURE_GEN_T);
sunTexture = TextureIO.newTexture(new File("sun.jpg"),false);
float[] rgba = {1f, 1f, 1f};
gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, rgba, 0);
gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, rgba, 0);
gl.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 0.5f);
sunTexture.enable();
sunTexture.bind();
GLUquadric sun = glu.gluNewQuadric();
glu.gluQuadricTexture(sun, true);
glu.gluSphere(sun, 5, DETAIL, DETAIL);
sunTexture.disable();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于GLU自己生成纹理坐标并将它们作为glTexCoord传输,我认为不需要启用texcoord生成(GL_TEXTURE_GEN_S/T)。我想 GLU 生成的 texCoords 会被 texgen 中的 texCoords 覆盖。
我还看到,您向 glMaterial 提交了一个包含三个浮点数的数组,它需要 RGBA(4 个浮点数)。但由于我使用 C++,我可能错了,这在 JoGL 中有效。
As GLU generates texture coordinates itsself and transmits them as glTexCoord, I think, there is no need to enable texcoord generation (GL_TEXTURE_GEN_S/T). I suppose the GLU-generated texCoords get overwritten with the ones from texgen.
I also see, that you submit an array of three floats to glMaterial, which expects RGBA (4 floats). But since I work with C++, I maybe wrong and this works in JoGL.
我发现了问题:
我已经设定了
gl.glFrustum(-20, 20, -20, 20, 0.1, 400);
设置后
gl.glFrustum(-20, 20, -20, 20, 1, 400);
看起来不错。
I found the problem:
i had set
gl.glFrustum(-20, 20, -20, 20, 0.1, 400);
after setting
gl.glFrustum(-20, 20, -20, 20, 1, 400);
it appears ok.