Finish refactoring GLFW demo and update to Godot 3.2.2

Untested on macOS and Windows, and GCC isn't working.
This commit is contained in:
Aaron Franke
2020-08-31 01:55:04 -04:00
parent b17be55a06
commit 9f12378931
9 changed files with 71 additions and 61 deletions

View File

@@ -1,7 +1,7 @@
# GLFW example using C
This is a small example using C to create a GDNative script that
exposes a smaaaaall part of the GLFW API.
exposes a very small part of the GLFW API.
Dependencies:
* You need [Godot headers](https://github.com/godotengine/godot_headers),
@@ -27,11 +27,7 @@ To compile the library on Linux, do
```
cd src
clang -std=c11 -fPIC -c -I../godot_headers init.c -o init.os
clang -shared -lglfw init.os -o ../project/gdnative/linuxbsd/libglfw.so
# Or use GCC.
gcc -std=c11 -fPIC -c -I../godot_headers init.c -o init.os
gcc -shared init.os -o ../project/gdnative/linuxbsd/libglfw.so -lglfw
clang -shared -lglfw init.os -o ../project/gdnative/linuxbsd/libglfw_godot.so
```
This creates the file `libsimple.so` in the `project/gdnative/linuxbsd` directory.

View File

@@ -17,7 +17,7 @@ opts.Add(EnumVariable("platform", "Compilation platform", "", platform_array))
opts.Add(EnumVariable("p", "Alias for 'platform'", "", platform_array))
opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no"))
opts.Add(PathVariable("target_path", "The path where the lib is installed.", "project/gdnative/"))
opts.Add(PathVariable("target_name", "The library name.", "libglfw", PathVariable.PathAccept))
opts.Add(PathVariable("target_name", "The library name.", "libglfw_godot", PathVariable.PathAccept))
# Only support 64-bit systems.
bits = 64
@@ -41,7 +41,7 @@ if env["platform"] == "":
env["target_path"] += env["platform"] + "/"
# Process other arguments.
if env["use_llvm"]:
if True or env["use_llvm"]: # TODO: GCC doesn't work for some reason.
env["CC"] = "clang"
env["CXX"] = "clang++"
@@ -75,6 +75,9 @@ elif env["platform"] == "windows":
# Make sure our library includes the Godot headers.
env.Append(CPPPATH=[".", godot_headers_path])
# Include GLFW.
env.Append(LINKFLAGS=["-lglfw"])
# Make sure our library looks in the target path for any other
# libraries it may need. The path needs to be project-relative.
env.Append(LINKFLAGS=["-Wl,-rpath,gdnative/" + env["platform"]])

View File

@@ -3,15 +3,16 @@
singleton=false
load_once=true
symbol_prefix="godot_"
reloadable=true
[entry]
X11.64="res://src/libglfw.so"
Windows.64=""
OSX.64="res://src/libglfw_godot.dylib"
X11.64="res://gdnative/linuxbsd/libglfw_godot.so"
Windows.64="res://gdnative/windows/libglfw_godot.dll"
OSX.64="res://gdnative/macos/libglfw_godot.dylib"
[dependencies]
X11.64=[]
Windows.64=[]
OSX.64=[]
X11.64=[ ]
Windows.64=[ ]
OSX.64=[ ]

View File

@@ -1,10 +1,9 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://GLFW.gdnlib" type="GDNativeLibrary" id=1]
[ext_resource path="res://gdnative/glfw.gdnlib" type="GDNativeLibrary" id=1]
[resource]
class_name = "GLFW"
library = ExtResource( 1 )
_sections_unfolded = [ "Resource" ]

View File

@@ -3,20 +3,21 @@
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
source_md5="86aa1d9e8afaf5ec9cabb7e89945c7a8"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
dest_md5="3364e3cd572841d7e22cf649a135919e"
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
@@ -26,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=true
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true

33
c/glfw/project/main.gd Normal file
View File

@@ -0,0 +1,33 @@
extends Node
# Load the GLFW library.
onready var window = preload("res://gdnative/glfw.gdns").new()
func _ready():
# Create a 400x400 px window.
window.create(400, 400, "Hello from Godot!")
# Connect the "closed" signal.
window.connect("closed", self, "on_window_close")
func on_window_close():
# The window emits a signal when the users requests
# to close it. So let's close it :D
window.close()
func _process(_delta):
# If the window is still open, poll for events
# on every frame.
if not window.is_closed():
window.poll_events()
func _notification(what):
match what:
NOTIFICATION_PREDELETE:
# If the game closes, the window should close
# as well. `window.close()` works when
# window already is closed.
window.close()

View File

@@ -1,42 +1,6 @@
[gd_scene load_steps=2 format=2]
[sub_resource type="GDScript" id=1]
script/source = "extends Node2D
# load the GLFW library
onready var window = preload(\"res://GLFW.gdns\").new()
func _ready():
# create a 200x200 px window
window.create(200, 200, \"Hello from Godot!\")
# connect the \"closed\" signal
window.connect(\"closed\", self, \"on_window_close\")
func on_window_close():
# the window emits a signal when the users requests
# to close it. So let's close it :D
window.close()
func _process(delta):
# If the window is still open, poll for events
# on every frame
if not window.is_closed():
window.poll_events()
func _notification(what):
match what:
NOTIFICATION_PREDELETE:
# if the game closes, the window should close
# as well. window.close() works when
# window already is closed
window.close()
"
[node name="Node2D" type="Node2D" index="0"]
script = SubResource( 1 )
[ext_resource path="res://main.gd" type="Script" id=1]
[node name="Main" type="Node"]
script = ExtResource( 1 )

View File

@@ -6,11 +6,18 @@
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=3
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
run/main_scene="res://Main.tscn"
config/name="GLFW GDNative C Demo"
config/description="GLFW GDNative C Demo"
run/main_scene="res://main.tscn"
name="GLFWDemo"
main_scene="res://Main.tscn"
icon="res://icon.png"
@@ -18,3 +25,7 @@ icon="res://icon.png"
[memory]
multithread/thread_rid_pool_prealloc=60
[rendering]
quality/driver/driver_name="GLES2"

View File

@@ -15,7 +15,8 @@ _global_script_class_icons={
[application]
config/name="Simple GDNative Demo"
config/name="Simple GDNative C Demo"
config/description="Simple GDNative C Demo"
run/main_scene="res://main.tscn"
config/icon="res://icon.png"