diff --git a/c/glfw/README.md b/c/glfw/README.md index b8f14c2..ad55c8d 100644 --- a/c/glfw/README.md +++ b/c/glfw/README.md @@ -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. diff --git a/c/glfw/SConstruct b/c/glfw/SConstruct index 7d4511c..296e7b8 100644 --- a/c/glfw/SConstruct +++ b/c/glfw/SConstruct @@ -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"]]) diff --git a/c/glfw/project/gdnative/glfw.gdnlib b/c/glfw/project/gdnative/glfw.gdnlib index 9cf23e7..52e4389 100644 --- a/c/glfw/project/gdnative/glfw.gdnlib +++ b/c/glfw/project/gdnative/glfw.gdnlib @@ -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=[ ] diff --git a/c/glfw/project/gdnative/glfw.gdns b/c/glfw/project/gdnative/glfw.gdns index b82cd75..adaf020 100644 --- a/c/glfw/project/gdnative/glfw.gdns +++ b/c/glfw/project/gdnative/glfw.gdns @@ -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" ] - diff --git a/c/glfw/project/icon.png.import b/c/glfw/project/icon.png.import index b4bba91..2125c6b 100644 --- a/c/glfw/project/icon.png.import +++ b/c/glfw/project/icon.png.import @@ -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 diff --git a/c/glfw/project/main.gd b/c/glfw/project/main.gd new file mode 100644 index 0000000..f74f26b --- /dev/null +++ b/c/glfw/project/main.gd @@ -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() diff --git a/c/glfw/project/main.tscn b/c/glfw/project/main.tscn index 0211a1b..7cb0d2e 100644 --- a/c/glfw/project/main.tscn +++ b/c/glfw/project/main.tscn @@ -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 ) diff --git a/c/glfw/project/project.godot b/c/glfw/project/project.godot index 7bdeb5e..3c097be 100644 --- a/c/glfw/project/project.godot +++ b/c/glfw/project/project.godot @@ -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" diff --git a/c/simple/project/project.godot b/c/simple/project/project.godot index a43f6a0..b6fd4a4 100644 --- a/c/simple/project/project.godot +++ b/c/simple/project/project.godot @@ -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"