mirror of
https://github.com/godotengine/gdnative-demos.git
synced 2026-01-04 22:10:30 +03:00
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:
@@ -1,7 +1,7 @@
|
|||||||
# GLFW example using C
|
# GLFW example using C
|
||||||
|
|
||||||
This is a small example using C to create a GDNative script that
|
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:
|
Dependencies:
|
||||||
* You need [Godot headers](https://github.com/godotengine/godot_headers),
|
* You need [Godot headers](https://github.com/godotengine/godot_headers),
|
||||||
@@ -27,11 +27,7 @@ To compile the library on Linux, do
|
|||||||
```
|
```
|
||||||
cd src
|
cd src
|
||||||
clang -std=c11 -fPIC -c -I../godot_headers init.c -o init.os
|
clang -std=c11 -fPIC -c -I../godot_headers init.c -o init.os
|
||||||
clang -shared -lglfw init.os -o ../project/gdnative/linuxbsd/libglfw.so
|
clang -shared -lglfw init.os -o ../project/gdnative/linuxbsd/libglfw_godot.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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This creates the file `libsimple.so` in the `project/gdnative/linuxbsd` directory.
|
This creates the file `libsimple.so` in the `project/gdnative/linuxbsd` directory.
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ opts.Add(EnumVariable("platform", "Compilation platform", "", platform_array))
|
|||||||
opts.Add(EnumVariable("p", "Alias for '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(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_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.
|
# Only support 64-bit systems.
|
||||||
bits = 64
|
bits = 64
|
||||||
@@ -41,7 +41,7 @@ if env["platform"] == "":
|
|||||||
env["target_path"] += env["platform"] + "/"
|
env["target_path"] += env["platform"] + "/"
|
||||||
|
|
||||||
# Process other arguments.
|
# 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["CC"] = "clang"
|
||||||
env["CXX"] = "clang++"
|
env["CXX"] = "clang++"
|
||||||
|
|
||||||
@@ -75,6 +75,9 @@ elif env["platform"] == "windows":
|
|||||||
# Make sure our library includes the Godot headers.
|
# Make sure our library includes the Godot headers.
|
||||||
env.Append(CPPPATH=[".", godot_headers_path])
|
env.Append(CPPPATH=[".", godot_headers_path])
|
||||||
|
|
||||||
|
# Include GLFW.
|
||||||
|
env.Append(LINKFLAGS=["-lglfw"])
|
||||||
|
|
||||||
# Make sure our library looks in the target path for any other
|
# Make sure our library looks in the target path for any other
|
||||||
# libraries it may need. The path needs to be project-relative.
|
# libraries it may need. The path needs to be project-relative.
|
||||||
env.Append(LINKFLAGS=["-Wl,-rpath,gdnative/" + env["platform"]])
|
env.Append(LINKFLAGS=["-Wl,-rpath,gdnative/" + env["platform"]])
|
||||||
|
|||||||
@@ -3,15 +3,16 @@
|
|||||||
singleton=false
|
singleton=false
|
||||||
load_once=true
|
load_once=true
|
||||||
symbol_prefix="godot_"
|
symbol_prefix="godot_"
|
||||||
|
reloadable=true
|
||||||
|
|
||||||
[entry]
|
[entry]
|
||||||
|
|
||||||
X11.64="res://src/libglfw.so"
|
X11.64="res://gdnative/linuxbsd/libglfw_godot.so"
|
||||||
Windows.64=""
|
Windows.64="res://gdnative/windows/libglfw_godot.dll"
|
||||||
OSX.64="res://src/libglfw_godot.dylib"
|
OSX.64="res://gdnative/macos/libglfw_godot.dylib"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
X11.64=[]
|
X11.64=[ ]
|
||||||
Windows.64=[]
|
Windows.64=[ ]
|
||||||
OSX.64=[]
|
OSX.64=[ ]
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
[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]
|
[resource]
|
||||||
|
|
||||||
class_name = "GLFW"
|
class_name = "GLFW"
|
||||||
library = ExtResource( 1 )
|
library = ExtResource( 1 )
|
||||||
_sections_unfolded = [ "Resource" ]
|
_sections_unfolded = [ "Resource" ]
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,21 @@
|
|||||||
importer="texture"
|
importer="texture"
|
||||||
type="StreamTexture"
|
type="StreamTexture"
|
||||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://icon.png"
|
source_file="res://icon.png"
|
||||||
source_md5="86aa1d9e8afaf5ec9cabb7e89945c7a8"
|
|
||||||
|
|
||||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
|
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
|
||||||
dest_md5="3364e3cd572841d7e22cf649a135919e"
|
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
compress/mode=0
|
compress/mode=0
|
||||||
compress/lossy_quality=0.7
|
compress/lossy_quality=0.7
|
||||||
compress/hdr_mode=0
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
compress/normal_map=0
|
compress/normal_map=0
|
||||||
flags/repeat=0
|
flags/repeat=0
|
||||||
flags/filter=true
|
flags/filter=true
|
||||||
@@ -26,6 +27,7 @@ flags/srgb=2
|
|||||||
process/fix_alpha_border=true
|
process/fix_alpha_border=true
|
||||||
process/premult_alpha=true
|
process/premult_alpha=true
|
||||||
process/HDR_as_SRGB=false
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
stream=false
|
stream=false
|
||||||
size_limit=0
|
size_limit=0
|
||||||
detect_3d=true
|
detect_3d=true
|
||||||
|
|||||||
33
c/glfw/project/main.gd
Normal file
33
c/glfw/project/main.gd
Normal 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()
|
||||||
@@ -1,42 +1,6 @@
|
|||||||
[gd_scene load_steps=2 format=2]
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
[sub_resource type="GDScript" id=1]
|
[ext_resource path="res://main.gd" type="Script" 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 )
|
|
||||||
|
|
||||||
|
|
||||||
|
[node name="Main" type="Node"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|||||||
@@ -6,11 +6,18 @@
|
|||||||
; [section] ; section goes between []
|
; [section] ; section goes between []
|
||||||
; param=value ; assign values to parameters
|
; param=value ; assign values to parameters
|
||||||
|
|
||||||
config_version=3
|
config_version=4
|
||||||
|
|
||||||
|
_global_script_classes=[ ]
|
||||||
|
_global_script_class_icons={
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[application]
|
[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"
|
name="GLFWDemo"
|
||||||
main_scene="res://Main.tscn"
|
main_scene="res://Main.tscn"
|
||||||
icon="res://icon.png"
|
icon="res://icon.png"
|
||||||
@@ -18,3 +25,7 @@ icon="res://icon.png"
|
|||||||
[memory]
|
[memory]
|
||||||
|
|
||||||
multithread/thread_rid_pool_prealloc=60
|
multithread/thread_rid_pool_prealloc=60
|
||||||
|
|
||||||
|
[rendering]
|
||||||
|
|
||||||
|
quality/driver/driver_name="GLES2"
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ _global_script_class_icons={
|
|||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Simple GDNative Demo"
|
config/name="Simple GDNative C Demo"
|
||||||
|
config/description="Simple GDNative C Demo"
|
||||||
run/main_scene="res://main.tscn"
|
run/main_scene="res://main.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user