使用OpenGL在Java中在3d空间中绘制图像的最简单方法是什么?

时间:2015-05-28 01:33:13

标签: java opengl

我在这样画的OpenGL程序中有一面墙:

public void draw() {

    if(!door){
    glBegin(GL_QUADS);
    glVertex3f(posx, 0f, posz);
    glVertex3f(posx, y, posz);
    glVertex3f(posx+x, y, posz);
    glVertex3f(posx+x, 0f, posz);
    }
    else{
    glBegin(GL_QUADS);
    glVertex3f(posx, 0f, posz);
    glVertex3f(posx, y, posz);
    glVertex3f(posx+x/3, y, posz);
    glVertex3f(posx+x/3, 0, posz);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(posx+x/3, y, posz);
    glVertex3f(posx+2*x/3, y, posz);
    glVertex3f(posx+2*x/3, 3*y/4, posz);
    glVertex3f(posx+x/3, 3*y/4, posz);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(posx+2*x/3, y, posz);
    glVertex3f(posx+x, y, posz);
    glVertex3f(posx+x, 0, posz);
    glVertex3f(posx+2*x/3, 0, posz);
    }
    glEnd();
}

在墙上绘制图像的最简单方法是什么?

1 个答案:

答案 0 :(得分:0)

经过大量的搜索,我终于找到了答案。这适用于3d空间。我希望这可以帮助那里的人!

public void drawLetterOnZYWall(Texture letter,zyWall wall) {


    glBindTexture(GL_TEXTURE_2D, letter.getTextureID());

    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glTexCoord2f(1, 0);
    glVertex3f(wall.getPosX()+0.01f, WALL_HEIGHT, wall.getPosZ());
    glTexCoord2f(0, 0);
    glVertex3f(wall.getPosX()+0.01f, WALL_HEIGHT, wall.getPosZ() + wall.getWidth()/10);
    glTexCoord2f(0, 1);
    glVertex3f(wall.getPosX()+0.01f, (float)WALL_HEIGHT*((float)8/(float)10), wall.getPosZ() + wall.getWidth()/10);
    glTexCoord2f(1, 1);
    glVertex3f(wall.getPosX()+0.01f, (float)WALL_HEIGHT*((float)8/(float)10), wall.getPosZ());

    glTexCoord2f(1, 0);
    glVertex3f(wall.getPosX()-0.01f, WALL_HEIGHT, wall.getPosZ());
    glTexCoord2f(0, 0);
    glVertex3f(wall.getPosX()-0.01f, WALL_HEIGHT, wall.getPosZ() + wall.getWidth()/10);
    glTexCoord2f(0, 1);
    glVertex3f(wall.getPosX() - 0.01f, (float)WALL_HEIGHT*((float)8/(float)10), wall.getPosZ() + wall.getWidth()/10);
    glTexCoord2f(1, 1);
    glVertex3f(wall.getPosX()-0.01f, (float)WALL_HEIGHT*((float)8/(float)10), wall.getPosZ());

    glEnd();
    glDisable(GL_TEXTURE_2D);
}