Habe jetzt eine CubeMap Klasse erstellt. Ich habe nach dem Tutorial auch alles richtig gemacht(denke ich zumindest), aber es wird nichts angezeigt. Ich glaube nicht, dass es an der Cubemap liegt, denn wenn ich das mache, wird auch nichts angezeigt:
#version 140
uniform samplerCube u_cubemapTexture;
in vec3 v_reflect;
out vec4 fragColor;
void main()
{
fragColor = vec4(0, 0, 0, 1);//texture(u_cubemapTexture, v_reflect);
}
Trotzdem mal die CubeMap-Klasse für das Bild:
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.imageio.ImageIO;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.opengl.GL12.*;
public class CubeMap {
public int id;
public CubeMap(String path) throws IOException{
this(ImageIO.read(CubeMap.class.getClassLoader().getResourceAsStream(path)));
}
public CubeMap(BufferedImage image){
glActiveTexture(GL_TEXTURE0);
id = glGenTextures();
int w = image.getWidth(), h = image.getHeight();
loadSide(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, image.getSubimage(w/4, h/3, w/4, h/3));
loadSide(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, image.getSubimage(3*w/4, h/3, w/4, h/3));
loadSide(GL_TEXTURE_CUBE_MAP_POSITIVE_X, image.getSubimage(2*w/4, h/3, w/4, h/3));
loadSide(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, image.getSubimage(0, h/3, w/4, h/3));
loadSide(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, image.getSubimage(w/4, 0, w/4, h/3));
loadSide(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, image.getSubimage(w/4, 2*(h/3), w/4, h/3));
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
private void loadSide(int target,
BufferedImage bi) {
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
byte[] data = (byte[]) bi.getRaster().getDataElements(0, 0, bi.getWidth(), bi.getHeight(), null);
ByteBuffer image = ByteBuffer.allocateDirect(bi.getColorModel().getPixelSize() / 8 * bi.getWidth() * bi.getHeight());
image.put(data);
image.rewind();
glTexImage2D(target, 0, GL11.GL_RGBA, bi.getWidth(), bi.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image);
}
}
Das Zeichnen ist gleich geblieben, bis auf das glBindTexture.