[Mobile] Update LibGDX to 1.10.0, Update Mobile Dev to LWJGL3

refer here for LibGDX Migration/Changes: https://libgdx.com/news/2021/04/the-ultimate-migration-guide
This commit is contained in:
Anthony Calosa
2021-04-19 21:41:34 +08:00
parent 539c94f36f
commit a5e8b88e32
6 changed files with 25 additions and 25 deletions

View File

@@ -87,7 +87,7 @@
<dependency> <dependency>
<groupId>com.badlogicgames.gdx</groupId> <groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-backend-android</artifactId> <artifactId>gdx-backend-android</artifactId>
<version>1.9.13</version> <version>1.10.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -68,7 +68,7 @@
<dependency> <dependency>
<groupId>com.badlogicgames.gdx</groupId> <groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-backend-robovm</artifactId> <artifactId>gdx-backend-robovm</artifactId>
<version>1.9.13</version> <version>1.10.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -59,19 +59,19 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.badlogicgames.gdx</groupId> <groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-backend-lwjgl</artifactId> <artifactId>gdx-backend-lwjgl3</artifactId>
<version>1.9.13</version> <version>1.10.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.badlogicgames.gdx</groupId> <groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-platform</artifactId> <artifactId>gdx-platform</artifactId>
<version>1.9.13</version> <version>1.10.0</version>
<classifier>natives-desktop</classifier> <classifier>natives-desktop</classifier>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.badlogicgames.gdx</groupId> <groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-freetype-platform</artifactId> <artifactId>gdx-freetype-platform</artifactId>
<version>1.9.13</version> <version>1.10.0</version>
<classifier>natives-desktop</classifier> <classifier>natives-desktop</classifier>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli --> <!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->

View File

@@ -9,6 +9,7 @@ import java.io.OutputStream;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import com.badlogic.gdx.graphics.glutils.HdpiMode;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.DefaultParser;
@@ -17,9 +18,9 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl.LwjglClipboard; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Clipboard;
import forge.Forge; import forge.Forge;
import forge.assets.AssetsDownloader; import forge.assets.AssetsDownloader;
@@ -85,8 +86,8 @@ public class Main {
// Fullscreen width and height for desktop mode (desktopMode = true) // Fullscreen width and height for desktop mode (desktopMode = true)
// Can be specified inside the file fullscreen_resolution.ini to override default (in the format WxH, e.g. 1920x1080) // Can be specified inside the file fullscreen_resolution.ini to override default (in the format WxH, e.g. 1920x1080)
int desktopScreenWidth = LwjglApplicationConfiguration.getDesktopDisplayMode().width; int desktopScreenWidth = Lwjgl3ApplicationConfiguration.getDisplayMode().width;
int desktopScreenHeight = LwjglApplicationConfiguration.getDesktopDisplayMode().height; int desktopScreenHeight = Lwjgl3ApplicationConfiguration.getDisplayMode().height;
boolean fullscreenFlag = true; boolean fullscreenFlag = true;
if (FileUtil.doesFileExist(desktopModeAssetsDir + "screen_resolution.ini")) { if (FileUtil.doesFileExist(desktopModeAssetsDir + "screen_resolution.ini")) {
res = FileUtil.readFileToString(desktopModeAssetsDir + "screen_resolution.ini").split("x"); res = FileUtil.readFileToString(desktopModeAssetsDir + "screen_resolution.ini").split("x");
@@ -97,17 +98,18 @@ public class Main {
} }
} }
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.resizable = false; config.setResizable(false);
config.width = desktopMode ? desktopScreenWidth : screenWidth; config.setWindowedMode(desktopMode ? desktopScreenWidth : screenWidth, desktopMode ? desktopScreenHeight : screenHeight);
config.height = desktopMode ? desktopScreenHeight : screenHeight; if (desktopMode && fullscreenFlag)
config.fullscreen = desktopMode && fullscreenFlag; config.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode());
config.title = "Forge"; config.setTitle("Forge");
config.useHDPI = desktopMode; // enable HiDPI on Mac OS if (desktopMode)
config.setHdpiMode(HdpiMode.Logical);
ForgePreferences prefs = FModel.getPreferences(); ForgePreferences prefs = FModel.getPreferences();
boolean propertyConfig = prefs != null && prefs.getPrefBoolean(ForgePreferences.FPref.UI_NETPLAY_COMPAT); boolean propertyConfig = prefs != null && prefs.getPrefBoolean(ForgePreferences.FPref.UI_NETPLAY_COMPAT);
new LwjglApplication(Forge.getApp(new LwjglClipboard(), new DesktopAdapter(switchOrientationFile),//todo get totalRAM && isTabletDevice new Lwjgl3Application(Forge.getApp(new Lwjgl3Clipboard(), new DesktopAdapter(switchOrientationFile),//todo get totalRAM && isTabletDevice
desktopMode ? desktopModeAssetsDir : assetsDir, propertyConfig, false, 0, false, 0, "", ""), config); desktopMode ? desktopModeAssetsDir : assetsDir, propertyConfig, false, 0, false, 0, "", ""), config);
} }

View File

@@ -48,12 +48,12 @@
<dependency> <dependency>
<groupId>com.badlogicgames.gdx</groupId> <groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx</artifactId> <artifactId>gdx</artifactId>
<version>1.9.13</version> <version>1.10.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.badlogicgames.gdx</groupId> <groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-freetype</artifactId> <artifactId>gdx-freetype</artifactId>
<version>1.9.13</version> <version>1.10.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -681,12 +681,11 @@ public class Graphics {
batch.draw(image, adjustX(x), adjustY(y, h), w, h); batch.draw(image, adjustX(x), adjustY(y, h), w, h);
} else { } else {
batch.end(); batch.end();
shaderOutline.begin(); shaderOutline.bind();
shaderOutline.setUniformf("u_viewportInverse", new Vector2(1f / w, 1f / h)); shaderOutline.setUniformf("u_viewportInverse", new Vector2(1f / w, 1f / h));
shaderOutline.setUniformf("u_offset", 3f); shaderOutline.setUniformf("u_offset", 3f);
shaderOutline.setUniformf("u_step", Math.min(1f, w / 70f)); shaderOutline.setUniformf("u_step", Math.min(1f, w / 70f));
shaderOutline.setUniformf("u_color", new Vector3(glowColor.r, glowColor.g, glowColor.b)); shaderOutline.setUniformf("u_color", new Vector3(glowColor.r, glowColor.g, glowColor.b));
shaderOutline.end();
batch.setShader(shaderOutline); batch.setShader(shaderOutline);
batch.begin(); batch.begin();
//glow //glow
@@ -705,12 +704,11 @@ public class Graphics {
batch.draw(image, adjustX(x), adjustY(yBox, h), w, h); batch.draw(image, adjustX(x), adjustY(yBox, h), w, h);
} else { } else {
batch.end(); batch.end();
shaderOutline.begin(); shaderOutline.bind();
shaderOutline.setUniformf("u_viewportInverse", new Vector2(1f / w, 1f / h)); shaderOutline.setUniformf("u_viewportInverse", new Vector2(1f / w, 1f / h));
shaderOutline.setUniformf("u_offset", 3f); shaderOutline.setUniformf("u_offset", 3f);
shaderOutline.setUniformf("u_step", Math.min(1f, w / 70f)); shaderOutline.setUniformf("u_step", Math.min(1f, w / 70f));
shaderOutline.setUniformf("u_color", new Vector3(glowColor.r, glowColor.g, glowColor.b)); shaderOutline.setUniformf("u_color", new Vector3(glowColor.r, glowColor.g, glowColor.b));
shaderOutline.end();
batch.setShader(shaderOutline); batch.setShader(shaderOutline);
batch.begin(); batch.begin();
//glow //glow