Browse Source

Texture size and dimensions fix

Tankernn 8 years ago
parent
commit
b669e8ffde

+ 39 - 39
src/main/java/eu/tankernn/gameEngine/environmentMap/EnvironmentMapRenderer.java

@@ -1,39 +1,39 @@
-package eu.tankernn.gameEngine.environmentMap;
-
-import org.lwjgl.opengl.Display;
-import org.lwjgl.opengl.GL11;
-import org.lwjgl.opengl.GL13;
-import org.lwjgl.opengl.GL14;
-import org.lwjgl.opengl.GL30;
-import org.lwjgl.util.vector.Vector3f;
-
-import eu.tankernn.gameEngine.loader.textures.Texture;
-import eu.tankernn.gameEngine.renderEngine.MasterRenderer;
-import eu.tankernn.gameEngine.renderEngine.Scene;
-
-public class EnvironmentMapRenderer {
-	public static void renderEnvironmentMap(Texture cubeMap, Scene scene, Vector3f center, MasterRenderer renderer) {
-		CubeMapCamera camera = new CubeMapCamera(center);
-		
-		int fbo = GL30.glGenFramebuffers();
-		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
-		GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0);
-		
-		int depthBuffer = GL30.glGenRenderbuffers();
-		GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBuffer);
-		GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, cubeMap.getWidth(), cubeMap.getHeight());
-		GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthBuffer);
-		GL11.glViewport(0, 0, cubeMap.size, cubeMap.size);
-		
-		for (int i = 0; i < 6; i++) {
-			GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubeMap.textureId, 0);
-			
-			camera.switchToFace(i);
-			
-			renderer.renderLowQualityScene(scene, camera);
-		}
-		
-		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
-		GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
-	}
-}
+package eu.tankernn.gameEngine.environmentMap;
+
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL13;
+import org.lwjgl.opengl.GL14;
+import org.lwjgl.opengl.GL30;
+import org.lwjgl.util.vector.Vector3f;
+
+import eu.tankernn.gameEngine.loader.textures.Texture;
+import eu.tankernn.gameEngine.renderEngine.MasterRenderer;
+import eu.tankernn.gameEngine.renderEngine.Scene;
+
+public class EnvironmentMapRenderer {
+	public static void renderEnvironmentMap(Texture cubeMap, Scene scene, Vector3f center, MasterRenderer renderer) {
+		CubeMapCamera camera = new CubeMapCamera(center);
+		
+		int fbo = GL30.glGenFramebuffers();
+		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
+		GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0);
+		
+		int depthBuffer = GL30.glGenRenderbuffers();
+		GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBuffer);
+		GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, cubeMap.getWidth(), cubeMap.getHeight());
+		GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthBuffer);
+		GL11.glViewport(0, 0, cubeMap.getWidth(), cubeMap.getHeight());
+		
+		for (int i = 0; i < 6; i++) {
+			GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubeMap.textureId, 0);
+			
+			camera.switchToFace(i);
+			
+			renderer.renderLowQualityScene(scene, camera);
+		}
+		
+		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
+		GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
+	}
+}

+ 64 - 58
src/main/java/eu/tankernn/gameEngine/loader/textures/Texture.java

@@ -1,58 +1,64 @@
-package eu.tankernn.gameEngine.loader.textures;
-
-import org.lwjgl.opengl.GL11;
-import org.lwjgl.opengl.GL13;
-import org.lwjgl.util.vector.Vector2f;
-
-import eu.tankernn.gameEngine.util.InternalFile;
-
-public class Texture {
-
-	public final int textureId;
-	public final int size;
-	public final Vector2f ratio;
-	private final int type;
-
-	protected Texture(int textureId, int width, int height) {
-		this(textureId, GL11.GL_TEXTURE_2D, width, height);
-	}
-
-	protected Texture(int textureId, int type, int width, int height) {
-		this.textureId = textureId;
-		this.ratio = (Vector2f) new Vector2f(width, height).normalise();
-		this.size = width * height;
-		this.type = type;
-	}
-
-	public void bindToUnit(int unit) {
-		GL13.glActiveTexture(GL13.GL_TEXTURE0 + unit);
-		GL11.glBindTexture(type, textureId);
-	}
-
-	public void delete() {
-		GL11.glDeleteTextures(textureId);
-	}
-
-	public static TextureBuilder newTexture(InternalFile textureFile) {
-		return new TextureBuilder(textureFile);
-	}
-
-	public static Texture newCubeMap(InternalFile[] textureFiles, int size) {
-		int cubeMapId = TextureUtils.loadCubeMap(textureFiles);
-		return new Texture(cubeMapId, GL13.GL_TEXTURE_CUBE_MAP, size);
-	}
-	
-	public static Texture newEmptyCubeMap(int size) {
-		int cubeMapId = TextureUtils.createEmptyCubeMap(size);
-		return new Texture(cubeMapId, GL13.GL_TEXTURE_CUBE_MAP, size);
-	}
-
-	public int getWidth() {
-		return (int) (size * ratio.x);
-	}
-	
-	public int getHeight() {
-		return (int) (size * ratio.y);
-	}
-
-}
+package eu.tankernn.gameEngine.loader.textures;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL13;
+import org.lwjgl.util.vector.Vector2f;
+
+import eu.tankernn.gameEngine.util.InternalFile;
+
+public class Texture {
+
+	public final int textureId;
+	public final Vector2f dimensions;
+	private final int type;
+
+	protected Texture(int textureId, int width, int height) {
+		this(textureId, GL11.GL_TEXTURE_2D, width, height);
+	}
+
+	protected Texture(int textureId, int type, int width, int height) {
+		this.textureId = textureId;
+		this.dimensions = new Vector2f(width, height);
+		this.type = type;
+	}
+
+	public void bindToUnit(int unit) {
+		GL13.glActiveTexture(GL13.GL_TEXTURE0 + unit);
+		GL11.glBindTexture(type, textureId);
+	}
+
+	public void delete() {
+		GL11.glDeleteTextures(textureId);
+	}
+
+	public static TextureBuilder newTexture(InternalFile textureFile) {
+		return new TextureBuilder(textureFile);
+	}
+
+	public static Texture newCubeMap(InternalFile[] textureFiles, int size) {
+		int cubeMapId = TextureUtils.loadCubeMap(textureFiles);
+		return new Texture(cubeMapId, GL13.GL_TEXTURE_CUBE_MAP, size);
+	}
+	
+	public static Texture newEmptyCubeMap(int size) {
+		int cubeMapId = TextureUtils.createEmptyCubeMap(size);
+		return new Texture(cubeMapId, GL13.GL_TEXTURE_CUBE_MAP, size);
+	}
+
+	public int getWidth() {
+		return (int) (dimensions.x);
+	}
+	
+	public int getHeight() {
+		return (int) (dimensions.y);
+	}
+	
+	public int getSize() {
+		return (int) (dimensions.x * dimensions.y);
+	}
+	
+	public Vector2f getRatio() {
+		return (Vector2f) new Vector2f(dimensions).normalise();
+	}
+
+}

+ 39 - 39
src/main/java/eu/tankernn/gameEngine/renderEngine/gui/GuiTexture.java

@@ -1,39 +1,39 @@
-package eu.tankernn.gameEngine.renderEngine.gui;
-
-import org.lwjgl.util.vector.Vector2f;
-
-import eu.tankernn.gameEngine.loader.textures.Texture;
-
-public class GuiTexture {
-	
-	private Texture texture;
-	protected Vector2f position;
-	protected float scale;
-	
-	public GuiTexture(Texture texture, Vector2f position, float scale) {
-		this.texture = texture;
-		this.position = position;
-		this.scale = scale;
-	}
-
-	public Texture getTexture() {
-		return texture;
-	}
-
-	public Vector2f getPosition() {
-		return position;
-	}
-
-	public Vector2f getSize() {
-		return (Vector2f) new Vector2f(texture.ratio).scale(scale);
-	}
-
-	public void setPosition(Vector2f position) {
-		this.position = position;
-	}
-
-	public void setScale(float scale) {
-		this.scale = scale;
-	}
-	
-}
+package eu.tankernn.gameEngine.renderEngine.gui;
+
+import org.lwjgl.util.vector.Vector2f;
+
+import eu.tankernn.gameEngine.loader.textures.Texture;
+
+public class GuiTexture {
+	
+	private Texture texture;
+	protected Vector2f position;
+	protected float scale;
+	
+	public GuiTexture(Texture texture, Vector2f position, float scale) {
+		this.texture = texture;
+		this.position = position;
+		this.scale = scale;
+	}
+
+	public Texture getTexture() {
+		return texture;
+	}
+
+	public Vector2f getPosition() {
+		return position;
+	}
+
+	public Vector2f getSize() {
+		return (Vector2f) new Vector2f(texture.dimensions).scale(scale);
+	}
+
+	public void setPosition(Vector2f position) {
+		this.position = position;
+	}
+
+	public void setScale(float scale) {
+		this.scale = scale;
+	}
+	
+}