Skip to content

Commit 5d4be77

Browse files
committed
Version upgrade for LibGDX and LWJGL so that it works on ARM64 macs.
1. Updated LibGDX version from 1.9.8 to 1.12.0 2. Switched from LWJGL2 to LWJGL3 backend 3. Updated controllers API (replaced PovDirection enum with int values) 4. Fixed type casting for camera movement in tile demos 5. Updated Java requirements from 1.6 to 1.8 6. Added proper window resize handling in Game2D class 7. Maintained LWJGL2 support for Swing integration 8. Updated gdx-controllers dependency to the new separate package (2.2.2) 9. Removed deprecated GdxNativesLoader class 10. Improved student script with safer sed command usage To make the application work in IntelliJ IDEA on macOS: 1. Open your project in IntelliJ IDEA 2. Click on "Run" in the top menu, then select "Edit Configurations..." 3. Select your run configuration (or create a new one if needed) 4. In the "VM options" field, add: -XstartOnFirstThread 5. Make sure the "Main class" is set correctly (e.g., ch.hevs.gdx2d.demos.DemoSimpleAnimation) 6. Click "Apply" and then "OK" 7. Run your application using the updated configuration
1 parent 58c1865 commit 5d4be77

16 files changed

Lines changed: 146 additions & 83 deletions

File tree

gdx2d-demoDesktop/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@
4444
<version>${kotlin.version}</version>
4545
<scope>test</scope>
4646
</dependency>
47+
48+
<dependency>
49+
<groupId>com.badlogicgames.gdx</groupId>
50+
<artifactId>gdx-backend-lwjgl3</artifactId>
51+
<version>${libgdx.version}</version>
52+
</dependency>
53+
54+
<!-- For Swing integration with LWJGL2 -->
55+
<dependency>
56+
<groupId>com.badlogicgames.gdx</groupId>
57+
<artifactId>gdx-backend-lwjgl</artifactId>
58+
<version>${libgdx.version}</version>
59+
</dependency>
60+
61+
<!-- For LWJGL2 natives required for Swing integration -->
62+
<dependency>
63+
<groupId>com.badlogicgames.gdx</groupId>
64+
<artifactId>gdx-platform</artifactId>
65+
<version>${libgdx.version}</version>
66+
<classifier>natives-desktop</classifier>
67+
</dependency>
68+
4769
</dependencies>
4870

4971
<build>

gdx2d-demoDesktop/src/main/kotlin/ch/hevs/gdx2d/demos/controllers/DemoControllers.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ch.hevs.gdx2d.demos.controllers
33
import ch.hevs.gdx2d.components.bitmaps.BitmapImage
44
import com.badlogic.gdx.controllers.Controller
55
import com.badlogic.gdx.controllers.Controllers
6-
import com.badlogic.gdx.controllers.PovDirection
76

87
import ch.hevs.gdx2d.desktop.PortableApplication
98
import ch.hevs.gdx2d.desktop.Xbox
@@ -135,8 +134,8 @@ class DemoControllers : PortableApplication(700, 700, false) {
135134
rightSickVal.y = value
136135
}
137136

138-
override fun onControllerPovMoved(controller: Controller, povCode: Int, value: PovDirection) {
139-
Logger.log(TAG, "POV: $value")
137+
override fun onControllerPovMoved(controller: Controller, povCode: Int, value: Int) {
138+
Logger.log(TAG, "POV direction value: $value")
140139
}
141140
}
142141

gdx2d-demoDesktop/src/main/kotlin/ch/hevs/gdx2d/demos/tilemap/advanced/DemoTileAdvanced.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class DemoTileAdvanced : PortableApplication() {
5858

5959
// Camera follows the hero
6060
g.zoom(zoom)
61-
g.moveCamera(hero.position.x, hero.position.y, tiledLayer.width * tiledLayer.tileWidth, tiledLayer.height * tiledLayer.tileHeight)
61+
g.moveCamera(hero.position.x.toFloat(), hero.position.y.toFloat(), (tiledLayer.width * tiledLayer.tileWidth).toFloat(), (tiledLayer.height * tiledLayer.tileHeight).toFloat())
6262

6363
// Render the tilemap
6464
tiledMapRenderer.setView(g.camera)

gdx2d-helloDesktop/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@
3838
<version>${kotlin.version}</version>
3939
<scope>test</scope>
4040
</dependency>
41+
42+
<dependency>
43+
<groupId>com.badlogicgames.gdx</groupId>
44+
<artifactId>gdx-backend-lwjgl3</artifactId>
45+
<version>${libgdx.version}</version>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>com.badlogicgames.gdx</groupId>
50+
<artifactId>gdx-platform</artifactId>
51+
<version>${libgdx.version}</version>
52+
<classifier>natives-desktop</classifier>
53+
</dependency>
4154
</dependencies>
4255

4356
<build>

gdx2d-library/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ The `gdx2d-core` dependencies are:
6565

6666
The `gdx2d-desktop` dependencies are:
6767

68-
* `com.badlogicgames.gdx:gdx-backend-lwjgl:${libgdx.version}`
68+
* `com.badlogicgames.gdx:gdx-backend-lwjgl3:${libgdx.version}`
6969
* `com.badlogicgames.gdx:gdx-platform:${libgdx.version}`
7070
* `com.badlogicgames.gdx:gdx-box2d-platform:${libgdx.version}`
7171
* `com.badlogicgames.gdx:gdx-freetype-platform:${libgdx.version}`
72+
* `com.badlogicgames.gdx:gdx-backend-lwjgl:${libgdx.version}` (for Swing integration)
7273

7374
## Library resources
7475

gdx2d-library/gdx2d-core/src/main/java/ch/hevs/gdx2d/lib/Version.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
public class Version {
77

88
/** Copyright and authors information. */
9-
public final static String COPY = "mui, chn, mei, pim (c) 2012-2016";
9+
public final static String COPY = "mui, chn, mei, pim (c) 2012-2025";
1010

1111
/**
1212
* Current version name of the gdx2d library (major.minor.revision).
1313
*/
14-
public final static String VERSION = "1.2.2";
14+
public final static String VERSION = "1.2.3";
1515

1616
/**
1717
* Indicates if it is a debug or release version.

gdx2d-library/gdx2d-core/src/main/java/ch/hevs/gdx2d/lib/interfaces/ControllersInterface.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ch.hevs.gdx2d.lib.interfaces;
22

33
import com.badlogic.gdx.controllers.Controller;
4-
import com.badlogic.gdx.controllers.PovDirection;
54
import com.badlogic.gdx.math.Vector3;
65

76
/**
@@ -73,9 +72,9 @@ public interface ControllersInterface {
7372
*
7473
* @param controller the corresponding controller
7574
* @param povCode the POV code
76-
* @param value the POV direction
75+
* @param value the POV direction as an integer (removed PovDirection enum for compatibility)
7776
*/
78-
void onControllerPovMoved(Controller controller, int povCode, PovDirection value);
77+
void onControllerPovMoved(Controller controller, int povCode, int value);
7978

8079
/**
8180
* An x-slider on the {@link Controller} moved.

gdx2d-library/gdx2d-desktop/pom.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,43 @@
3737

3838
<dependency>
3939
<groupId>com.badlogicgames.gdx</groupId>
40-
<artifactId>gdx-backend-lwjgl</artifactId>
40+
<artifactId>gdx-backend-lwjgl3</artifactId>
4141
<version>${libgdx.version}</version>
4242
</dependency>
43+
44+
<!-- Default desktop natives -->
4345
<dependency>
4446
<groupId>com.badlogicgames.gdx</groupId>
4547
<artifactId>gdx-platform</artifactId>
4648
<version>${libgdx.version}</version>
4749
<classifier>natives-desktop</classifier>
4850
</dependency>
4951

52+
53+
<!-- Box2D extension -->
5054
<dependency>
51-
<!-- Box2D extension -->
5255
<groupId>com.badlogicgames.gdx</groupId>
5356
<artifactId>gdx-box2d-platform</artifactId>
5457
<classifier>natives-desktop</classifier>
5558
<version>${libgdx.version}</version>
5659
</dependency>
60+
61+
62+
<!-- Box2DLights extension -->
5763
<dependency>
58-
<!-- Box2DLights extension -->
5964
<groupId>com.badlogicgames.gdx</groupId>
6065
<artifactId>gdx-freetype-platform</artifactId>
6166
<version>${libgdx.version}</version>
6267
<classifier>natives-desktop</classifier>
6368
</dependency>
69+
6470
<dependency>
6571
<!-- Controllers extension -->
66-
<groupId>com.badlogicgames.gdx</groupId>
72+
<groupId>com.badlogicgames.gdx-controllers</groupId>
6773
<artifactId>gdx-controllers-desktop</artifactId>
68-
<version>${libgdx.version}</version>
69-
</dependency>
70-
<dependency>
71-
<!-- Controllers extension -->
72-
<groupId>com.badlogicgames.gdx</groupId>
73-
<artifactId>gdx-controllers-platform</artifactId>
74-
<version>${libgdx.version}</version>
75-
<classifier>natives-desktop</classifier>
74+
<version>2.2.2</version>
7675
</dependency>
76+
7777
</dependencies>
7878

7979
<build>

gdx2d-library/gdx2d-desktop/src/main/java/ch/hevs/gdx2d/desktop/Game2D.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
99
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
1010
import com.badlogic.gdx.input.GestureDetector;
11-
import com.badlogic.gdx.utils.GdxNativesLoader;
1211

1312
import ch.hevs.gdx2d.lib.GdxGraphics;
1413
import ch.hevs.gdx2d.lib.Version;
@@ -32,12 +31,6 @@ public class Game2D implements ApplicationListener {
3231

3332
public static GdxGraphics g;
3433

35-
// Force to load native libraries (for Android Proguard)
36-
// FIXME Is this really required?
37-
static {
38-
GdxNativesLoader.load();
39-
}
40-
4134
public OrthographicCamera camera;
4235
protected PortableApplication app;
4336
protected ShapeRenderer shapeRenderer;
@@ -96,6 +89,10 @@ public void render() {
9689
* Called when the screen has been resized.
9790
*/
9891
public void resize(int width, int height) {
92+
// Update camera when window is resized
93+
camera.setToOrtho(false, width, height);
94+
camera.update();
95+
g.setCamera(camera);
9996
}
10097

10198
/**
Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,70 @@
11
package ch.hevs.gdx2d.desktop;
22

33
import com.badlogic.gdx.Files;
4-
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
4+
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
5+
import com.badlogic.gdx.graphics.Color;
56

67
/**
78
* Default configuration for {@code gdx2d} applications running on desktop.
89
*
910
* @author Pierre-André Mudry (mui)
11+
* @version 1.1
1012
*/
1113
public class GdxConfig {
1214

13-
// FIXME: only used for desktop applications, must not be included in the library project
15+
/**
16+
* Get LWJGL configuration with default settings (500x500 window)
17+
*
18+
* @return LWJGL application configuration
19+
*/
20+
public static Lwjgl3ApplicationConfiguration getLwjglConfig() {
21+
return getLwjglConfig(500, 500, false);
22+
}
1423

15-
static public LwjglApplicationConfiguration getLwjglConfig(int width, int height, boolean fullScreen) {
16-
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
17-
config.resizable = false;
18-
config.useGL30 = false;
19-
config.height = height;
20-
config.width = width;
21-
config.fullscreen = fullScreen;
22-
config.title = "Gdx2d desktop application";
23-
config.vSyncEnabled = true; // Ignored under Linux
24-
config.foregroundFPS = 60; // Target value if vSync not working
25-
config.backgroundFPS = config.foregroundFPS;
26-
config.samples = 3; // Multi-sampling enables anti-alias for lines
27-
config.forceExit = false; // Setting true calls system.exit(), with no coming back
24+
/**
25+
* Get LWJGL configuration
26+
* <p/>
27+
* Default resolution available for the windowed mode:
28+
* <ul>
29+
* <li>640 * 480 (4:3)
30+
* <li>800 * 600 (4:3)
31+
* <li>1024 * 768 (4:3)
32+
* <li>1280 * 720 (16:9)
33+
* <li>1366 * 768 (16:9)
34+
* <li>1600 * 900 (16:9)
35+
* <li>1920 * 1080 (16:9)
36+
* </ul>
37+
*
38+
* @param width Window width
39+
* @param height Window height
40+
* @param fullScreen Create a fullscreen window
41+
* @return The configuration for LWJGL
42+
*/
43+
public static Lwjgl3ApplicationConfiguration getLwjglConfig(int width, int height, boolean fullScreen) {
44+
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
45+
config.setResizable(false);
46+
config.useVsync(true);
47+
config.setTitle("Gdx2d desktop application");
2848

29-
final String os = System.getProperty("os.name").toLowerCase();
49+
// Set window size
50+
config.setWindowedMode(width, height);
3051

31-
// Under windows, the icon *must* be the small one
32-
if (os.contains("win")) {
33-
config.addIcon("res/lib/icon16.png", Files.FileType.Internal);
34-
}
52+
if (fullScreen) {
53+
config.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode());
54+
}
3555

36-
config.addIcon("res/lib/icon32.png", Files.FileType.Internal);
37-
config.addIcon("res/lib/icon64.png", Files.FileType.Internal);
56+
// Set up initial background color to black
57+
config.setInitialBackgroundColor(Color.BLACK);
3858

39-
return config;
40-
}
59+
// 4 samples for multi-sampling enables anti-alias for lines
60+
config.setBackBufferConfig(8, 8, 8, 8, 16, 0, 4);
4161

42-
}
62+
// Use OpenGL 2.0 for compatibility (major=2, minor=0)
63+
config.setOpenGLEmulation(Lwjgl3ApplicationConfiguration.GLEmulation.GL20, 2, 0);
64+
65+
// Set window icons
66+
config.setWindowIcon("res/lib/icon16.png", "res/lib/icon32.png", "res/lib/icon64.png");
67+
68+
return config;
69+
}
70+
}

0 commit comments

Comments
 (0)