【发布时间】:2016-08-28 07:51:04
【问题描述】:
我正在尝试在屏幕上渲染一个带纹理的四边形,作为我的新游戏的开始菜单按钮。但是当渲染它只是渲染为白色四边形时,我在互联网上搜索了好几天,我还没有找到一个解决问题的答案。
我的纹理是 wood.png,它位于项目资源文件夹内的“res”文件夹中。这是一个 128 * 128 像素的图像。
渲染纹理的代码如下:
public static void renderTexture(Texture texture, float width, float height, float x, float y) {
texture.bind();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
texture.bind();
glTranslatef(x, y, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(width, 0);
glTexCoord2f(1, 1);
glVertex2f(width, height);
glTexCoord2f(0, 1);
glVertex2f(0, height);
glLoadIdentity();
glEnd();
glDisable(GL_BLEND);
}
我用来加载纹理的代码是:
public static Texture loadTexture(String fileName){
try {
Texture texture = TextureLoader.getTexture("PNG",Class.class.getResourceAsStream("/res/"+fileName+".png"));
return texture;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
我有一个存储private static Texture startTex = Loader.loadTexture("wood"); 的静态纹理,我通过以下方式渲染每一帧:
RenderSystem.renderTexture(startTex, 200, 200, 0, 0);
【问题讨论】: