Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ out/
.gradle/
.idea/
cmake-build-*/
run/
**/run/
bin/
.vscode/
.settings/
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.6
0.4.7
4 changes: 4 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
plugins {
id("java-gradle-plugin")
`kotlin-dsl`
}

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import org.apache.tools.ant.taskdefs.condition.Os

plugins {
id("application")
id("java-library")
}

group = "com.labymedia"

fun lwjglClassifier(): String {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return "natives-windows"
} else if (Os.isFamily(Os.FAMILY_MAC)) {
return "natives-macos"
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
return "natives-linux"
} else {
throw UnsupportedOperationException("This OS is not supported")
}
}

repositories {
mavenCentral()
}

dependencies {
implementation(group = "org.lwjgl", name = "lwjgl", version = "3.2.2")
runtimeOnly(group = "org.lwjgl", name = "lwjgl", version = "3.2.2", classifier = lwjglClassifier())

implementation(group = "org.lwjgl", name = "lwjgl-opengl", version = "3.2.2")
runtimeOnly(group = "org.lwjgl", name = "lwjgl-opengl", version = "3.2.2", classifier = lwjglClassifier())

implementation(group = "org.lwjgl", name = "lwjgl-glfw", version = "3.2.2")
runtimeOnly(group = "org.lwjgl", name = "lwjgl-glfw", version = "3.2.2", classifier = lwjglClassifier())

implementation(project(":ultralight-java-base"))
implementation(project(":ultralight-java-databind"))
implementation(project(":ultralight-java-gpu"))
implementation(project(":ultralight-java-glfw-opengl-util"))

if (project.path != ":example:example-base") {
implementation(project(":example:example-base"))
}
}

fun getBitName(): String {
return if (System.getProperty("os.arch", "?").contains("64") ||
System.getProperty("sun.arch.data.model", "?").contains("64")
) {
"64"
} else {
"32"
}
}

fun ultralightOsIdentifier(): String {
return when {
Os.isFamily(Os.FAMILY_WINDOWS) -> {
"win-x${getBitName()}"
}
Os.isFamily(Os.FAMILY_MAC) -> {
"mac-x${getBitName()}"
}
Os.isFamily(Os.FAMILY_UNIX) -> {
"linux-x${getBitName()}"
}
else -> {
throw UnsupportedOperationException("This OS is not supported")
}
}
}

val runDir = file ("run")
if (!runDir.exists() && !runDir.mkdirs()) {
throw GradleException ("Failed to create run directory")
}


tasks.create("copyResources", Copy::class){
println(File(project(":ultralight-java-native").buildDir, "cmake-gen-${ultralightOsIdentifier()}/ultralight-${ultralightOsIdentifier()}/bin"))
from(File(project(":ultralight-java-native").buildDir, "cmake-gen-${ultralightOsIdentifier()}/ultralight-${ultralightOsIdentifier()}/bin"))
include( "**/*.dll", "**/*.so", "**/*.dylib", "resources/*")
into(runDir)
}

tasks.getByName("run", JavaExec::class){
workingDir = runDir
dependsOn("copyResources")
}
3 changes: 3 additions & 0 deletions example/example-base/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("ultralight-java.example-conventions")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Ultralight Java - Java wrapper for the Ultralight web engine
* Copyright (C) 2020 - 2021 LabyMedia and contributors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package com.labymedia.ultralight.example.base;

import com.labymedia.ultralight.UltralightJava;
import com.labymedia.ultralight.UltralightLoadException;
import com.labymedia.ultralight.gpu.UltralightGPUDriverNativeUtil;
import org.lwjgl.glfw.GLFW;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public abstract class UltralightExampleBase {

private final UltralightExampleConfiguration ultralightExampleConfiguration;

public UltralightExampleBase() {
try {

this.ultralightExampleConfiguration = new UltralightExampleConfiguration();
this.setupNatives();

this.configure(this.ultralightExampleConfiguration);

// Example resources
extractResources();
this.begin();
} catch (UltralightLoadException exception) {
//Process will end here. Just wrapped in a RuntimeException so no example has to create a constructor
throw new RuntimeException(exception);
}
}

private void setupNatives() throws UltralightLoadException {
// Get a directory to put natives into
Path nativesDir = Paths.get(".");

// Get the existing native library path
String libraryPath = System.getProperty("java.library.path");
if (libraryPath != null) {
// There is a path set already, append our natives dir
libraryPath += File.pathSeparator + nativesDir.toAbsolutePath().toString();
} else {
// There is no path set, make our natives dir the current path
libraryPath = nativesDir.toAbsolutePath().toString();
}

// Set the path back
System.setProperty("java.library.path", libraryPath);

// Extract the natives
//
// This only extracts the native library for ultralight-java-base, but not the other Ultralight libraries.
// It is your task to get them into the run directory, possibly by extracting them on your own.
UltralightJava.extractNativeLibrary(nativesDir);

// Load the native libraries from the given directory. This method makes sure everything is loaded in the
// correct order. If you want to manually load all natives, either don't use this function or pass 'false' as
// the second parameter.
UltralightJava.load(nativesDir);
UltralightGPUDriverNativeUtil.extractAndLoadNativeLibraries(nativesDir);

}

public void configure(UltralightExampleConfiguration ultralightExampleConfiguration) {
}

public void begin() {
}

/**
* Helper function to set up the run directory with jar resources.
*/
private void extractResources() {
try {
for (String path : this.ultralightExampleConfiguration.getResourcesToExtract()) {
Files.copy(
UltralightExampleBase.class.getResourceAsStream("/" + path),
Paths.get("./" + path),
StandardCopyOption.REPLACE_EXISTING
);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Ultralight Java - Java wrapper for the Ultralight web engine
* Copyright (C) 2020 - 2021 LabyMedia and contributors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package com.labymedia.ultralight.example.base;

import java.util.Collection;
import java.util.HashSet;

public class UltralightExampleConfiguration {

private final Collection<String> resourcesToExtract;

public UltralightExampleConfiguration() {
this.resourcesToExtract = new HashSet<>();
}

public UltralightExampleConfiguration extractResource(String path) {
this.resourcesToExtract.add(path);
return this;
}

protected Collection<String> getResourcesToExtract() {
return this.resourcesToExtract;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void run() {
int frameCount = 0;

// Create the drawing helper, used to keep state for drawing the rotating triangle
OpenGLDrawer drawer = new OpenGLDrawer();
// OpenGLDrawer drawer = new OpenGLDrawer();

// Keep running until a window close is requested
while (!glfwWindowShouldClose(window)) {
Expand All @@ -248,7 +248,7 @@ public void run() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Draw the triangle and then Ultralight on top of it
drawer.draw();
// drawer.draw();
webController.render();

// Super bad implementation of FPS display...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ public static void main(String[] args) throws UltralightLoadException {
// This only extracts the native library for ultralight-java-base, but not the other Ultralight libraries.
// It is your task to get them into the run directory, possibly by extracting them on your own.
UltralightJava.extractNativeLibrary(nativesDir);
try {
UltralightGPUDriverNativeUtil.extractAndLoadNativeLibraries(nativesDir);
} catch (IOException exception) {
throw new RuntimeException(exception);
}

UltralightGPUDriverNativeUtil.load(nativesDir);
// Load the native libraries from the given directory. This method makes sure everything is loaded in the
// correct order. If you want to manually load all natives, either don't use this function or pass 'false' as
// the second parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.labymedia.ultralight.lwjgl3.opengl.input.InputAdapter;
import com.labymedia.ultralight.lwjgl3.opengl.listener.ExampleLoadListener;
import com.labymedia.ultralight.lwjgl3.opengl.listener.ExampleViewListener;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL30;

import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
Expand Down Expand Up @@ -70,7 +71,7 @@ public WebController(CursorAdapter cursorManager, long window) {
new UltralightConfig()
.forceRepaint(false)
.resourcePath("./resources/")
.fontHinting(FontHinting.NORMAL)
.fontHinting(FontHinting.SMOOTH)
);
this.platform.usePlatformFontLoader();
this.platform.setFileSystem(new ExampleFileSystem());
Expand All @@ -79,7 +80,7 @@ public WebController(CursorAdapter cursorManager, long window) {
}

public void initGPUDriver() {
this.driver = new UltralightOpenGLGPUDriverNative(this.window, false);
this.driver = new UltralightOpenGLGPUDriverNative(this.window, false, GLFW.Functions.GetProcAddress);

this.platform.setGPUDriver(this.driver);
this.renderer = UltralightRenderer.create();
Expand All @@ -91,7 +92,6 @@ public void initGPUDriver() {
.initialDeviceScale(1.0)
.isTransparent(true)
);
view.setDeviceScale(100);
this.viewListener = new ExampleViewListener(cursorManager);
this.view.setViewListener(viewListener);
this.loadListener = new ExampleLoadListener(view);
Expand Down
7 changes: 7 additions & 0 deletions example/lwjgl3-opengl/simple/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("ultralight-java.example-conventions")
}

application {
mainClassName = "com.labymedia.ultralight.example.simple.SimpleUltralightExample"
}
Loading