|
@@ -1,152 +1,152 @@
|
|
|
-package eu.tankernn.gameEngine.loader.textures;
|
|
|
-
|
|
|
-import java.io.InputStream;
|
|
|
-import java.nio.ByteBuffer;
|
|
|
-
|
|
|
-import org.lwjgl.opengl.EXTTextureFilterAnisotropic;
|
|
|
-import org.lwjgl.opengl.GL11;
|
|
|
-import org.lwjgl.opengl.GL12;
|
|
|
-import org.lwjgl.opengl.GL13;
|
|
|
-import org.lwjgl.opengl.GL14;
|
|
|
-import org.lwjgl.opengl.GL30;
|
|
|
-import org.lwjgl.opengl.GL32;
|
|
|
-import org.lwjgl.opengl.GLContext;
|
|
|
-
|
|
|
-import de.matthiasmann.twl.utils.PNGDecoder;
|
|
|
-import de.matthiasmann.twl.utils.PNGDecoder.Format;
|
|
|
-import eu.tankernn.gameEngine.util.InternalFile;
|
|
|
-
|
|
|
-public class TextureUtils {
|
|
|
-
|
|
|
- public static int createEmptyCubeMap(int size) {
|
|
|
- int texID = GL11.glGenTextures();
|
|
|
- GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);
|
|
|
- for (int i = 0; i < 6; i++) {
|
|
|
- GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA8, size, size, 0, GL11.GL_RGBA,
|
|
|
- GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
|
|
|
- }
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0);
|
|
|
- return texID;
|
|
|
- }
|
|
|
-
|
|
|
- public static int loadCubeMap(InternalFile[] textureFiles) {
|
|
|
- int texID = GL11.glGenTextures();
|
|
|
- GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
|
|
- GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);
|
|
|
- GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
|
|
- for (int i = 0; i < textureFiles.length; i++) {
|
|
|
- TextureData data = decodeTextureFile(textureFiles[i]);
|
|
|
- GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA, data.getWidth(),
|
|
|
- data.getHeight(), 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data.getBuffer());
|
|
|
- }
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0);
|
|
|
- return texID;
|
|
|
- }
|
|
|
-
|
|
|
- protected static TextureData decodeTextureFile(InternalFile file) {
|
|
|
- int width = 0;
|
|
|
- int height = 0;
|
|
|
- ByteBuffer buffer = null;
|
|
|
- try {
|
|
|
- InputStream in = file.getInputStream();
|
|
|
- PNGDecoder decoder = new PNGDecoder(in);
|
|
|
- width = decoder.getWidth();
|
|
|
- height = decoder.getHeight();
|
|
|
- buffer = ByteBuffer.allocateDirect(4 * width * height);
|
|
|
- decoder.decode(buffer, width * 4, Format.BGRA);
|
|
|
- buffer.flip();
|
|
|
- in.close();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- System.err.println("Tried to load texture " + file.getName() + ", didn't work");
|
|
|
- System.exit(-1);
|
|
|
- }
|
|
|
- return new TextureData(buffer, width, height);
|
|
|
- }
|
|
|
-
|
|
|
- protected static int loadTextureToOpenGL(TextureData data, TextureBuilder builder) {
|
|
|
- int texID = GL11.glGenTextures();
|
|
|
- GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
|
|
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
|
|
|
- GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
|
|
- GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL12.GL_BGRA,
|
|
|
- GL11.GL_UNSIGNED_BYTE, data.getBuffer());
|
|
|
- if (builder.isMipmap()) {
|
|
|
- GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
|
|
- if (builder.isAnisotropic() && GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) {
|
|
|
- GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0);
|
|
|
- GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
|
|
- 4.0f);
|
|
|
- }
|
|
|
- } else if (builder.isNearest()) {
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
|
|
- } else {
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
- }
|
|
|
- if (builder.isClampEdges()) {
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- } else {
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
|
|
- }
|
|
|
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
|
|
- return texID;
|
|
|
- }
|
|
|
-
|
|
|
- public static Texture createTextureAttachment(int width, int height) {
|
|
|
- int texture = GL11.glGenTextures();
|
|
|
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
|
|
- GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE,
|
|
|
- (ByteBuffer) null);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
- GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, texture, 0);
|
|
|
- return new Texture(texture, width, height);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Creates a depth buffer texture attachment.
|
|
|
- *
|
|
|
- * @param width
|
|
|
- * - the width of the texture.
|
|
|
- * @param height
|
|
|
- * - the height of the texture.
|
|
|
- * @return The depth texture object.
|
|
|
- */
|
|
|
- public static Texture createDepthTextureAttachment(int width, int height) {
|
|
|
- int texture = GL11.glGenTextures();
|
|
|
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
|
|
- GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT32, width, height, 0, GL11.GL_DEPTH_COMPONENT,
|
|
|
- GL11.GL_FLOAT, (ByteBuffer) null);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
|
|
- GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, texture, 0);
|
|
|
- return new Texture(texture, width, height);
|
|
|
- }
|
|
|
-
|
|
|
- public static int createDepthBufferAttachment(int width, int height) {
|
|
|
- int depthBuffer = GL30.glGenRenderbuffers();
|
|
|
- GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBuffer);
|
|
|
- GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, width, height);
|
|
|
- GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
|
|
|
- depthBuffer);
|
|
|
- return depthBuffer;
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+package eu.tankernn.gameEngine.loader.textures;
|
|
|
+
|
|
|
+import java.io.InputStream;
|
|
|
+import java.nio.ByteBuffer;
|
|
|
+
|
|
|
+import org.lwjgl.opengl.EXTTextureFilterAnisotropic;
|
|
|
+import org.lwjgl.opengl.GL11;
|
|
|
+import org.lwjgl.opengl.GL12;
|
|
|
+import org.lwjgl.opengl.GL13;
|
|
|
+import org.lwjgl.opengl.GL14;
|
|
|
+import org.lwjgl.opengl.GL30;
|
|
|
+import org.lwjgl.opengl.GL32;
|
|
|
+import org.lwjgl.opengl.GLContext;
|
|
|
+
|
|
|
+import de.matthiasmann.twl.utils.PNGDecoder;
|
|
|
+import de.matthiasmann.twl.utils.PNGDecoder.Format;
|
|
|
+import eu.tankernn.gameEngine.util.InternalFile;
|
|
|
+
|
|
|
+public class TextureUtils {
|
|
|
+
|
|
|
+ public static int createEmptyCubeMap(int size) {
|
|
|
+ int texID = GL11.glGenTextures();
|
|
|
+ GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA8, size, size, 0, GL11.GL_RGBA,
|
|
|
+ GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
|
|
|
+ }
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0);
|
|
|
+ return texID;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int loadCubeMap(InternalFile[] textureFiles) {
|
|
|
+ int texID = GL11.glGenTextures();
|
|
|
+ GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
|
|
+ GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);
|
|
|
+ GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
|
|
+ for (int i = 0; i < textureFiles.length; i++) {
|
|
|
+ TextureData data = decodeTextureFile(textureFiles[i]);
|
|
|
+ GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA, data.getWidth(),
|
|
|
+ data.getHeight(), 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data.getBuffer());
|
|
|
+ }
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0);
|
|
|
+ return texID;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected static TextureData decodeTextureFile(InternalFile file) {
|
|
|
+ int width = 0;
|
|
|
+ int height = 0;
|
|
|
+ ByteBuffer buffer = null;
|
|
|
+ try {
|
|
|
+ InputStream in = file.getInputStream();
|
|
|
+ PNGDecoder decoder = new PNGDecoder(in);
|
|
|
+ width = decoder.getWidth();
|
|
|
+ height = decoder.getHeight();
|
|
|
+ buffer = ByteBuffer.allocateDirect(4 * width * height);
|
|
|
+ decoder.decode(buffer, width * 4, Format.BGRA);
|
|
|
+ buffer.flip();
|
|
|
+ in.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ System.err.println("Tried to load texture " + file.getName() + ", didn't work");
|
|
|
+ System.exit(-1);
|
|
|
+ }
|
|
|
+ return new TextureData(buffer, width, height);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected static int loadTextureToOpenGL(TextureData data, TextureBuilder builder) {
|
|
|
+ int texID = GL11.glGenTextures();
|
|
|
+ GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
|
|
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
|
|
|
+ GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
|
|
+ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL12.GL_BGRA,
|
|
|
+ GL11.GL_UNSIGNED_BYTE, data.getBuffer());
|
|
|
+ if (builder.isMipmap()) {
|
|
|
+ GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
|
|
+ if (builder.isAnisotropic() && GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) {
|
|
|
+ GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0);
|
|
|
+ GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
|
|
+ 4.0f);
|
|
|
+ }
|
|
|
+ } else if (builder.isNearest()) {
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
|
|
+ } else {
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
+ }
|
|
|
+ if (builder.isClampEdges()) {
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ } else {
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
|
|
+ }
|
|
|
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
|
|
+ return texID;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Texture createTextureAttachment(int width, int height) {
|
|
|
+ int texture = GL11.glGenTextures();
|
|
|
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
|
|
+ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE,
|
|
|
+ (ByteBuffer) null);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, texture, 0);
|
|
|
+ return new Texture(texture, width, height);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates a depth buffer texture attachment.
|
|
|
+ *
|
|
|
+ * @param width
|
|
|
+ * - the width of the texture.
|
|
|
+ * @param height
|
|
|
+ * - the height of the texture.
|
|
|
+ * @return The depth texture object.
|
|
|
+ */
|
|
|
+ public static Texture createDepthTextureAttachment(int width, int height) {
|
|
|
+ int texture = GL11.glGenTextures();
|
|
|
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
|
|
+ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT32, width, height, 0, GL11.GL_DEPTH_COMPONENT,
|
|
|
+ GL11.GL_FLOAT, (ByteBuffer) null);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
|
|
+ GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, texture, 0);
|
|
|
+ return new Texture(texture, width, height);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int createDepthBufferAttachment(int width, int height) {
|
|
|
+ int depthBuffer = GL30.glGenRenderbuffers();
|
|
|
+ GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBuffer);
|
|
|
+ GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, width, height);
|
|
|
+ GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
|
|
|
+ depthBuffer);
|
|
|
+ return depthBuffer;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|