1
現在、& lwjglのゲームで作業しています。私のメインメニューでは、背景画像を描画しようとしています。何らかの理由で、私が使用するテクスチャの読み込みと描画のテクニックにかかわらず、イメージは完全にねじれてしまいます。LWJGLねじ込みテクスチャ
これは何が起こるかです:
そして、これはそれが見えるようになっているものである:
これはテクスチャをロードするための私のコードです:
private int loadTexture(String imgName) {
try {
BufferedImage img = ImageIO.read(JarStreamLoader.load(imgName));
ByteBuffer buffer = BufferUtils.createByteBuffer(img.getWidth() * img.getHeight() * 3);
for (int x = 0; x < img.getWidth(); x++) {
for (int y = 0; y < img.getHeight(); y++) {
Color color = new Color(img.getRGB(x, y));
buffer.put((byte) color.getRed());
buffer.put((byte) color.getGreen());
buffer.put((byte) color.getBlue());
}
}
buffer.flip();
int textureId = glGenTextures();
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img.getWidth(), img.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return textureId;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
それは私のレンダリングコード:
public static void drawRect(int x, int y, int width, int height, Color color) {
glColor4f(color.getRed()/255, color.getGreen()/255, color.getBlue()/255, 1.0F);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2d(x, y);
glTexCoord2f(0.0f, 1.0F);
glVertex2d(x, y + height);
glTexCoord2f(1.0F, 1.0F);
glVertex2d(x + width, y + height);
glTexCoord2f(1.0F, 0.0f);
glVertex2d(x + width, y);
glEnd();
}
どのようなアイデアですか?
感謝、それは今完全に働いています:) – Twometer