Update pom to support profiles + Remove idea project

This commit is contained in:
Florian RICHER 2024-10-13 19:13:12 +02:00
parent 888c438b55
commit c4bd9d2558
15 changed files with 494 additions and 272 deletions

4
.gitignore vendored
View file

@ -1,3 +1,5 @@
.direnv
.mvn
target
target
.idea/
*.iml

8
.idea/.gitignore vendored
View file

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View file

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="vulkan_java" />
</profile>
</annotationProcessing>
</component>
</project>

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

View file

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK" />
</project>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/vulkan_java.iml" filepath="$PROJECT_DIR$/vulkan_java.iml" />
</modules>
</component>
</project>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

136
pom.xml
View file

@ -8,90 +8,59 @@
<version>1.0-SNAPSHOT</version>
<name>vulkan_java</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<url>https://mrdev023.fr</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>22</maven.compiler.release>
<lwjgl.version>3.2.3</lwjgl.version>
<maven.compiler.release>21</maven.compiler.release>
<lwjgl.version>3.3.4</lwjgl.version>
<joml.version>1.10.8</joml.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- Optionally: parameterized tests support -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
<classifier>natives-windows</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
<classifier>natives-macos</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
<classifier>natives-linux</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<version>${lwjgl.version}</version>
<classifier>natives-windows</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<version>${lwjgl.version}</version>
<classifier>natives-macos</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<version>${lwjgl.version}</version>
<classifier>natives-linux</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-vulkan</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.joml</groupId>
<artifactId>joml</artifactId>
<version>${joml.version}</version>
</dependency>
<!-- Natives -->
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
<classifier>${native.target}</classifier>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<version>${lwjgl.version}</version>
<classifier>${native.target}</classifier>
<scope>runtime</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.lwjgl</groupId>-->
<!-- <artifactId>lwjgl-vulkan</artifactId>-->
<!-- <version>${lwjgl.version}</version>-->
<!-- <classifier>${native.target}</classifier>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
</dependencies>
<build>
@ -127,11 +96,6 @@
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.1</version>
@ -139,4 +103,40 @@
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>windows-profile</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<native.target>natives-windows</native.target>
</properties>
</profile>
<profile>
<id>linux-profile</id>
<activation>
<os>
<family>Linux</family>
</os>
</activation>
<properties>
<native.target>natives-linux</native.target>
</properties>
</profile>
<profile>
<id>OSX-profile</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<native.target>natives-macos</native.target>
</properties>
</profile>
</profiles>
</project>

View file

@ -1,108 +1,16 @@
package fr.mrdev023.vulkan_java;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.system.*;
import fr.mrdev023.vulkan_java.window.Display;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
/**
* Hello world!
*/
public class App {
// The window handle
private long window;
public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
init();
loop();
// Free the window callbacks and destroy the window
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
// Terminate GLFW and free the error callback
glfwTerminate();
glfwSetErrorCallback(null).free();
}
private void init() {
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable
// Create the window
window = glfwCreateWindow(300, 300, "Hello World!", NULL, NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
});
// Get the thread stack and push a new frame
try ( MemoryStack stack = stackPush() ) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Center the window
glfwSetWindowPos(
window,
(vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2
);
} // the stack frame is popped automatically
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1);
// Make the window visible
glfwShowWindow(window);
}
private void loop() {
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while ( !glfwWindowShouldClose(window) ) {
// Replace by clear framebuffer on vulkan
glfwSwapBuffers(window); // swap the color buffers
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
}
}
public static void main(String[] args) {
new App().run();
Display.create("My first application", 800, 600);
while (!Display.isCloseRequested()) {
Display.updateEvent();
Display.updateFrame();
}
Display.destroy();
}
}

View file

@ -0,0 +1,124 @@
package fr.mrdev023.vulkan_java.window;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.system.MemoryUtil.*;
import java.nio.*;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
public class Display {
private static DisplayMode displayMode;
private static String TITLE = "";
private static long window;
private static boolean hasResized = false;
public static void create(String title, int width, int height) {
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");
TITLE = title;
displayMode = new DisplayMode(width, height);
window = glfwCreateWindow(displayMode.getWidth(), displayMode.getHeight(), TITLE, NULL, NULL);
}
public static void setMouseGrabbed(boolean a) {
if (a) {
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
} else {
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
}
public static void setVSync(boolean a) {
if (a) glfwSwapInterval(1);
else glfwSwapInterval(0);
}
public static void setSample(int sample) {
glfwWindowHint(GLFW_SAMPLES, sample);
}
public static void setResizable(boolean a) {
if (a) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
}
public static void setTitle(String title) {
TITLE = title;
glfwSetWindowTitle(window, TITLE);
}
public static String getTitle() {
return TITLE;
}
public static boolean wasResized() {
IntBuffer w = BufferUtils.createIntBuffer(1);
IntBuffer h = BufferUtils.createIntBuffer(1);
glfwGetWindowSize(window, w, h);
int width = w.get(0);
int height = h.get(0);
if (Display.getDisplayMode().getWidth() != width || Display.getDisplayMode().getHeight() != height || hasResized) {
setDisplayMode(new DisplayMode(width, height));
hasResized = false;
return true;
} else {
return false;
}
}
public static void printMonitorsInfo() {
PointerBuffer monitors = glfwGetMonitors();
GLFWVidMode m;
if (monitors == null) {
System.out.println("No monitor detected !");
return;
}
for (int i = 0; i < monitors.capacity(); i++) {
m = glfwGetVideoMode(monitors.get(i));
System.out.println(glfwGetMonitorName(monitors.get(i)) + "(" + i + ") : " + m.width() + "x" + m.height() + ":" + m.refreshRate() + "Hz");
}
}
public static boolean isCloseRequested() {
return glfwWindowShouldClose(window);
}
public static void createContext() {
glfwMakeContextCurrent(window);
}
public static void updateEvent() {
glfwPollEvents();
}
public static void updateFrame() {
glfwSwapBuffers(window);
}
public static DisplayMode getDisplayMode() {
return displayMode;
}
public static void setDisplayMode(DisplayMode displayMode) {
if (Display.displayMode == null || displayMode == null) return;
Display.displayMode.setDisplayMode(displayMode);
hasResized = true;
}
public static void destroy() {
glfwDestroyWindow(window);
glfwTerminate();
}
public static long getWindow() {
return window;
}
}

View file

@ -0,0 +1,51 @@
package fr.mrdev023.vulkan_java.window;
import static org.lwjgl.glfw.GLFW.*;
public class DisplayMode {
private int width = 0, height = 0;
private boolean fullscreen = false;
public DisplayMode(int width, int height) {
this.width = width;
this.height = height;
}
public void setDisplayMode(DisplayMode displayMode) {
this.width = displayMode.getWidth();
this.height = displayMode.getHeight();
this.fullscreen = displayMode.isFullscreen();
setDisplayMode();
}
public void setDisplayMode() {
glfwSetWindowSize(Display.getWindow(), width, height);
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public boolean isFullscreen() {
return fullscreen;
}
public void setFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
setDisplayMode();
}
}

View file

@ -0,0 +1,239 @@
package fr.mrdev023.vulkan_java.window;
import static org.lwjgl.glfw.GLFW.*;
import java.util.*;
import java.util.Map.*;
import org.joml.Vector2f;
import org.lwjgl.glfw.*;
public class Input {
public static GLFWScrollCallback scroll;
public static GLFWCursorPosCallback mousePos;
private static Vector2f mousePosition = new Vector2f();
private static Vector2f dMouse = new Vector2f();
private static Vector2f previousDMouse = new Vector2f();
public static final int NONE = 0, PRESSED = 1, RELEASED = 2, REPEATED = 3, UP = 4, DOWN = 5,
NBRE_KEY = 0x15D, NBRE_BUTTON = 10,
MOUSE_OFFSET = NBRE_KEY + 1, MOUSE_WHEEL_OFFSET = MOUSE_OFFSET + 1;
private static HashMap<Integer, Integer> state = new HashMap<Integer, Integer>();
private static double ywheel = 0;
public static void init() {
glfwSetScrollCallback(Display.getWindow(), scroll = new GLFWScrollCallback() {
public void invoke(long window, double xoffset, double yoffset) {
scroll(window, xoffset, yoffset);
}
});
glfwSetCursorPosCallback(Display.getWindow(), mousePos = new GLFWCursorPosCallback() {
public void invoke(long window, double xpos, double ypos) {
mousepos(window, xpos, ypos);
}
});
for (int i = 0; i < NBRE_KEY; i++) {
state.put(i, NONE);
}
for (int i = 0; i < NBRE_BUTTON; i++) {
state.put(i + MOUSE_OFFSET, NONE);
}
state.put(MOUSE_WHEEL_OFFSET, NONE);
}
public static void update() {
for (Entry<Integer, Integer> set : state.entrySet()) {
int i = set.getKey();
int st = set.getValue();
if (i > -1 && i < NBRE_KEY) {
if (glfwGetKey(Display.getWindow(), i) == 0 && st == NONE) continue;
if (glfwGetKey(Display.getWindow(), i) == 1 && st == NONE) {
state.replace(i, PRESSED);
} else if (glfwGetKey(Display.getWindow(), i) == 1 && st == PRESSED) {
state.replace(i, REPEATED);
} else if (glfwGetKey(Display.getWindow(), i) == 0 && (st == PRESSED || st == REPEATED)) {
state.replace(i, RELEASED);
} else if (glfwGetKey(Display.getWindow(), i) == 0 && st == RELEASED) {
state.replace(i, NONE);
}
} else if (i >= MOUSE_OFFSET && i < MOUSE_OFFSET + NBRE_BUTTON) {
if (glfwGetMouseButton(Display.getWindow(), i - MOUSE_OFFSET) == 0 && st == NONE) continue;
if (glfwGetMouseButton(Display.getWindow(), i - MOUSE_OFFSET) == 1 && st == NONE) {
state.replace(i, PRESSED);
} else if (glfwGetMouseButton(Display.getWindow(), i - MOUSE_OFFSET) == 1 && st == PRESSED) {
state.replace(i, REPEATED);
} else if (glfwGetMouseButton(Display.getWindow(), i - MOUSE_OFFSET) == 0 && (st == PRESSED || st == REPEATED)) {
state.replace(i, RELEASED);
} else if (glfwGetMouseButton(Display.getWindow(), i - MOUSE_OFFSET) == 0 && st == RELEASED) {
state.replace(i, NONE);
}
}
}
int st = state.get(MOUSE_WHEEL_OFFSET);
if (ywheel > 0 && (st == NONE || st == UP)) {
state.replace(MOUSE_WHEEL_OFFSET, UP);
} else if (ywheel < 0 && (st == NONE || st == DOWN)) {
state.replace(MOUSE_WHEEL_OFFSET, DOWN);
} else if (ywheel == 0 && (st == DOWN || st == UP)) {
state.replace(MOUSE_WHEEL_OFFSET, NONE);
}
ywheel = 0;
if (dMouse.equals(previousDMouse)) {
dMouse = new Vector2f();
} else {
previousDMouse = dMouse;
}
}
public static void destroy() {
mousePos.free();
scroll.free();
}
public static void scroll(long window, double xoffset, double yoffset) {
ywheel = yoffset;
}
public static void mousepos(long window, double xpos, double ypos) {
dMouse.x = (float) (xpos - mousePosition.x);
dMouse.y = (float) (ypos - mousePosition.y);
mousePosition.x = (float) xpos;
mousePosition.y = (float) ypos;
}
public static boolean isButtonDown(int button) {
return state.get(button + MOUSE_OFFSET) == PRESSED;
}
public static boolean isButtonUp(int button) {
return state.get(button + MOUSE_OFFSET) == RELEASED;
}
public static boolean isButton(int button) {
return state.get(button + MOUSE_OFFSET) == PRESSED || state.get(button + MOUSE_OFFSET) == REPEATED;
}
public static int isButtonState(int button) {
return state.get(button + MOUSE_OFFSET);
}
public static boolean isKeyDown(int key) {
return state.get(key) == PRESSED;
}
public static boolean isKeyUp(int key) {
return state.get(key) == RELEASED;
}
public static boolean isKey(int key) {
return state.get(key) == PRESSED || state.get(key) == REPEATED;
}
public static int isKeyState(int key) {
return state.get(key);
}
public static int isMouseWheelState() {
return state.get(MOUSE_WHEEL_OFFSET);
}
public static boolean isMouseWheelUp() {
return state.get(MOUSE_WHEEL_OFFSET) == UP;
}
public static boolean isMouseWheelDown() {
return state.get(MOUSE_WHEEL_OFFSET) == DOWN;
}
public static GLFWScrollCallback getScroll() {
return scroll;
}
public static void setScroll(GLFWScrollCallback scroll) {
Input.scroll = scroll;
}
public static GLFWCursorPosCallback getMousePos() {
return mousePos;
}
public static void setMousePos(GLFWCursorPosCallback mousePos) {
Input.mousePos = mousePos;
}
public static Vector2f getMousePosition() {
return mousePosition;
}
public static void setMousePosition(Vector2f mousePosition) {
Input.mousePosition = mousePosition;
}
public static Vector2f getDMouse() {
return dMouse;
}
public static void setDMouse(Vector2f dMouse) {
Input.dMouse = dMouse;
}
public static HashMap<Integer, Integer> getState() {
return state;
}
public static void setState(HashMap<Integer, Integer> state) {
Input.state = state;
}
public static double getYwheel() {
return ywheel;
}
public static void setYwheel(double ywheel) {
Input.ywheel = ywheel;
}
public static int getNone() {
return NONE;
}
public static int getPressed() {
return PRESSED;
}
public static int getReleased() {
return RELEASED;
}
public static int getRepeated() {
return REPEATED;
}
public static int getUp() {
return UP;
}
public static int getDown() {
return DOWN;
}
public static int getNbreKey() {
return NBRE_KEY;
}
public static int getNbreButton() {
return NBRE_BUTTON;
}
public static int getMouseOffset() {
return MOUSE_OFFSET;
}
public static int getMouseWheelOffset() {
return MOUSE_WHEEL_OFFSET;
}
}

View file

@ -1,19 +0,0 @@
package fr.mrdev023.vulkan_java;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/**
* Unit test for simple App.
*/
public class AppTest {
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}
}

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<excludeFolder url="file://$MODULE_DIR$/.direnv" />
<excludeFolder url="file://$MODULE_DIR$/.mvn" />
</content>
</component>
</module>