Java、LWJGL、Slick2D を使用してレイキャスターを作成しています。問題は、このバイト配列から正しく描画する方法がわからないことです。
これが、テクスチャをカラーバッファに入れる方法です。これは機能します。すべての RGB 値は、テクスチャ内の値と同じです。
public java.awt.Color[] colorBuffer;
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
c = new java.awt.Color(image.getRGB(x, y));
colorBuffer[y * Width + x] = c;}}
スクリーンバッファを作成してピクセルを割り当てる方法は次のとおりです。
static byte[] buffer;
static int screenTexture;
public static void main() {
buffer = new byte[Display.Height * Display.Width];
screenTexture = GL11.glGenTextures();
texture = new Sprite(new Vector2f(0, 0), "src/Content/Textures/tex1.bmp");
}
// in the raycasting algorithm:
buffer[y * Display.Width + x] = (byte) texture.colorBuffer[texY * texture.Width + texX].getRed();
buffer[y * Display.Width + x + 1] = (byte) texture.colorBuffer[texY * texture.Width + texX].getGreen();
buffer[y * Display.Width + x + 2] = (byte) texture.colorBuffer[texY * texture.Width + texX].getBlue();
buffer[y * Display.Width + x + 3] = (byte) texture.colorBuffer[texY * texture.Width + texX].getAlpha();
バッファを描画する方法は次のとおりです。
org.newdawn.slick.Color.white.bind();
ByteBuffer b = BufferUtils.createByteBuffer(buffer.length * 4); // times four due to every pixel having RGBA.
for (int a = 0; a < buffer.length; a++) {
b.put(a, buffer[a]);
}
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 2);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, Display.Width / 4, Display.Height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, b);
GL11.glBegin(GL11.GL_QUADS);
{
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(0, 0);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(Display.Width, 0);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(Display.Width, Display.Height);
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(0, Display.Height);
}
GL11.glEnd();
ここで、赤、緑、青の 3 本の垂直線であるテクスチャを作成するとします。赤を白に、他を真っ黒にするだけでなく、遠くにあるほどテクスチャにいくつかの色を追加します。
これがどのように見えるかの画像です。ペイント ファイルは元のテクスチャで、右のウィンドウはレイキャスターです。
この問題を解決する方法を知っている人はいますか?