【问题标题】:How to texture the different planes in JOGL如何在 JOGL 中对不同的平面进行纹理处理
【发布时间】:2015-11-22 14:11:24
【问题描述】:

我在 JOGL 中创建了 6 个平面作为一个房间,现在我想用不同的图像对它们进行纹理处理,那么如何在每个平面上执行此操作?还有有什么推荐的纹理图片资源可以用来装饰房间吗?

谢谢。

public void render(GL2 gl) {
  gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT);
  gl.glLoadIdentity();
  camera.view(glu);                 // Orientate the camera
  doLight(gl);                      // Place the light

doLight2(gl);

if (axes.getSwitchedOn()) 
  axes.display(gl, glut);

if (objectsOn) {                  // Render the objects
  gl.glPushMatrix();
  //Making the room.
    double planeParam = animationScene.getParam(animationScene.PLANE_PARAM);
    //red x, blue z, green y.
    gl.glTranslated(planeParam,0,0);
    //Base
   plane.renderDisplayList(gl);
   //Back wall
    gl.glTranslated(0,25,-25);
    gl.glRotated(90, 1, 0, 0);
    plane.renderDisplayList(gl);
    //Right wall
    gl.glTranslated(25,25,0);
    gl.glRotated(90, 0, 0, 1);
    plane.renderDisplayList(gl);
    //Front wall
    gl.glTranslated(25,25,0);
    gl.glRotated(90, 0, 0, 1);
    plane.renderDisplayList(gl);
    //Roof 
    gl.glTranslated(0,25,-25);
    gl.glRotated(90, 1, 0, 0);
    plane.renderDisplayList(gl);

    //Left wall 
    gl.glTranslated(25,25,0);
    gl.glRotated(90, 0, 0, 1);
    plane.renderDisplayList(gl);


  gl.glPopMatrix();


}

【问题讨论】:

  • 你不应该使用任何显示列表,这个功能在许多驱动程序(甚至一些旧驱动程序)中是半损坏的。而是使用已编译的顶点数组或静态 VBO。

标签: opengl 3d textures jogl texture-mapping


【解决方案1】:

您可以使用 TextureIO(推荐)或 AWTTextureIO 从图像文件创建纹理。

您可以使用包含所有纹理的单个图像并将它们作为单个纹理进行管理,或者您可以为每个纹理使用一个图像。

您必须在使用之前绑定纹理(请参阅 Texture.bind() 或 glBindTexture)。

您必须为顶点分配一些纹理坐标。如果您使用立即模式,请使用 glTexCoord。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 2015-12-28
    • 2013-12-23
    • 2015-07-14
    • 2023-03-09
    相关资源
    最近更新 更多