diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java
index cff7421..1abd537 100644
--- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java
+++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/LWJGLInitializer.java
@@ -15,13 +15,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
package ru.windcorp.progressia.client.graphics.backend;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.system.MemoryUtil.*;
+import java.io.IOException;
+
+import org.lwjgl.glfw.GLFWImage;
import org.lwjgl.opengl.GL;
import com.google.common.eventbus.Subscribe;
@@ -30,6 +33,12 @@ import ru.windcorp.progressia.Progressia;
import ru.windcorp.progressia.client.graphics.GUI;
import ru.windcorp.progressia.client.graphics.input.FrameResizeEvent;
import ru.windcorp.progressia.client.graphics.input.InputEvent;
+import ru.windcorp.progressia.client.graphics.texture.TextureDataEditor;
+import ru.windcorp.progressia.client.graphics.texture.TextureLoader;
+import ru.windcorp.progressia.client.graphics.texture.TextureSettings;
+import ru.windcorp.progressia.common.resource.Resource;
+import ru.windcorp.progressia.common.resource.ResourceManager;
+import ru.windcorp.progressia.common.util.crash.CrashReports;
class LWJGLInitializer {
@@ -63,15 +72,21 @@ class LWJGLInitializer {
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE);
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
-
- long handle = glfwCreateWindow(800, 600, Progressia.getName() + " " + Progressia.getFullerVersion(), NULL, NULL);
+
+ long handle = glfwCreateWindow(
+ 800,
+ 600,
+ Progressia.getName() + " " + Progressia.getFullerVersion(),
+ NULL,
+ NULL
+ );
// TODO Check that handle != NULL
GraphicsBackend.setWindowHandle(handle);
glfwMakeContextCurrent(handle);
- glfwSwapInterval(0); // TODO: remove after config system is added
+ glfwSwapInterval(0); // TODO: remove after config system is added
}
private static void positionWindow() {
@@ -80,8 +95,25 @@ class LWJGLInitializer {
}
private static void createWindowIcons() {
- // TODO Auto-generated method stub
+ final String prefix = "assets/icons/";
+ String[] sizes = ResourceManager.getResource(prefix + "logoSizes.txt").readAsString().split(" ");
+
+ try (GLFWImage.Buffer buffer = GLFWImage.malloc(sizes.length)) {
+ for (int i = 0; i < sizes.length; ++i) {
+ Resource resource = ResourceManager.getResource(prefix + "logo" + sizes[i].trim() + ".png");
+ TextureDataEditor icon = TextureLoader.loadPixels(resource, new TextureSettings(false, true));
+
+ buffer.position(i)
+ .width(icon.getContentWidth())
+ .height(icon.getContentHeight())
+ .pixels(icon.getData().getData());
+ }
+
+ glfwSetWindowIcon(GraphicsBackend.getWindowHandle(), buffer);
+ } catch (IOException e) {
+ throw CrashReports.report(e, "Could not load window icons");
+ }
}
private static void initializeOpenGL() {
@@ -113,19 +145,19 @@ class LWJGLInitializer {
glfwSetScrollCallback(handle, InputHandler::handleWheelScroll);
GraphicsInterface.subscribeToInputEvents(new Object() {
-
+
@Subscribe
public void onFrameResized(FrameResizeEvent event) {
GUI.invalidateEverything();
}
-
+
@Subscribe
public void onInputEvent(InputEvent event) {
GUI.dispatchInput(event);
}
-
+
});
-
+
}
}
diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifontLoader.java b/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifontLoader.java
index 9ead1db..0bac647 100644
--- a/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifontLoader.java
+++ b/src/main/java/ru/windcorp/progressia/client/graphics/font/GNUUnifontLoader.java
@@ -45,7 +45,7 @@ public class GNUUnifontLoader {
private static final AtlasGroup ATLAS_GROUP_GNU_UNIFONT = new AtlasGroup("GNUUnifont", 1 << 12);
- private static final TextureSettings TEXTURE_SETTINGS = new TextureSettings(false);
+ private static final TextureSettings TEXTURE_SETTINGS = new TextureSettings(false, false);
private static final int BITS_PER_HEX_DIGIT = 4;
private static final int PREFIX_LENGTH = "0000:".length();
diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/Atlases.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/Atlases.java
index 94ed270..2a0e99a 100644
--- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/Atlases.java
+++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/Atlases.java
@@ -163,7 +163,7 @@ public class Atlases {
}
}
- private static final TextureSettings SETTINGS = new TextureSettings(false);
+ private static final TextureSettings SETTINGS = new TextureSettings(false, false);
private static final Map LOADED = new HashMap<>();
private static final Multimap ATLASES = MultimapBuilder.hashKeys().arrayListValues().build();
diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTextures.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTextures.java
index 12db086..757a772 100644
--- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTextures.java
+++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/SimpleTextures.java
@@ -28,7 +28,7 @@ import ru.windcorp.progressia.common.util.crash.CrashReports;
public class SimpleTextures {
- private static final TextureSettings SETTINGS = new TextureSettings(false);
+ private static final TextureSettings SETTINGS = new TextureSettings(false, false);
private static final Map TEXTURES = new HashMap<>();
diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureData.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureData.java
index 0453984..6b1f7d6 100644
--- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureData.java
+++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureData.java
@@ -23,7 +23,7 @@ import static org.lwjgl.opengl.GL12.*;
import java.nio.ByteBuffer;
-class TextureData {
+public class TextureData {
private final ByteBuffer data;
diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureLoader.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureLoader.java
index 1ce3998..a5a7fab 100644
--- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureLoader.java
+++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureLoader.java
@@ -41,9 +41,17 @@ public class TextureLoader {
int width = readResult.getWidth();
int height = readResult.getHeight();
+
+ int bufferWidth;
+ int bufferHeight;
- int bufferWidth = BinUtil.roundToGreaterPowerOf2(width);
- int bufferHeight = BinUtil.roundToGreaterPowerOf2(height);
+ if (settings.allocateExactBuffer()) {
+ bufferWidth = width;
+ bufferHeight = height;
+ } else {
+ bufferWidth = BinUtil.roundToGreaterPowerOf2(width);
+ bufferHeight = BinUtil.roundToGreaterPowerOf2(height);
+ }
WritableRaster raster = TextureUtil.createRaster(
bufferWidth,
diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureSettings.java b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureSettings.java
index 3dd43a4..d4e61c9 100644
--- a/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureSettings.java
+++ b/src/main/java/ru/windcorp/progressia/client/graphics/texture/TextureSettings.java
@@ -21,13 +21,19 @@ package ru.windcorp.progressia.client.graphics.texture;
public class TextureSettings {
private final boolean isFiltered;
+ private final boolean allocateExactBuffer;
- public TextureSettings(boolean isFiltered) {
+ public TextureSettings(boolean isFiltered, boolean allocateExactBuffer) {
this.isFiltered = isFiltered;
+ this.allocateExactBuffer = allocateExactBuffer;
}
public boolean isFiltered() {
return isFiltered;
}
+
+ public boolean allocateExactBuffer() {
+ return allocateExactBuffer;
+ }
}
diff --git a/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRenderRegistry.java b/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRenderRegistry.java
index 60b7bf6..f694980 100644
--- a/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRenderRegistry.java
+++ b/src/main/java/ru/windcorp/progressia/client/world/entity/EntityRenderRegistry.java
@@ -42,7 +42,7 @@ public class EntityRenderRegistry extends NamespacedInstanceRegistry