mirror of
https://github.com/godotengine/gdnative-demos.git
synced 2026-01-01 05:48:13 +03:00
First go at a very very simple example project
This commit is contained in:
6
.gitattributes
vendored
6
.gitattributes
vendored
@@ -1,2 +1,6 @@
|
||||
*.c eol=lf
|
||||
*.cpp eol=lf
|
||||
*.cpp eol=lf
|
||||
*.gd eol=lf
|
||||
*.tscn eol=lf
|
||||
*.cfg eol=lf
|
||||
*.godot eol=lf
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@
|
||||
*.os
|
||||
*.so
|
||||
*.dylib
|
||||
.import
|
||||
.import
|
||||
*.import
|
||||
|
||||
34
c/SimpleDemo/README.md
Normal file
34
c/SimpleDemo/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Simple example using C
|
||||
|
||||
This is a small example using C to create a GDNative script that just showcases some very simple bare bones calls
|
||||
|
||||
## Compiling
|
||||
|
||||
Dependencies:
|
||||
* You need to have the [Godot headers](https://github.com/GodotNativeTools/godot_headers) saved somewhere on your system
|
||||
* clang or any decent C compiler that's C11 or C99 compatible
|
||||
|
||||
To compile the library, do
|
||||
|
||||
cd src
|
||||
clang -std=c11 -fPIC -c -I/PATH/TO/GODOT/HEADERS simple.c -o simple.os
|
||||
clang -shared simple.os -o libsimple.so
|
||||
|
||||
This creates the file `libsimple.so` in your `src` directory.
|
||||
For windows you need to find out what compiler flags need to be used, I don't know which ones. (If you do, feel free to fork and update this project and README)
|
||||
|
||||
On mac:
|
||||
|
||||
cd src
|
||||
clang -std=c11 -fPIC -c -I/PATH/TO/GODOT/HEADERS simple.c -o simple.os -arch i386 -arch x86_64
|
||||
clang -dynamiclib simple.os -o libsimple.dylib -arch i386 -arch x86_64 -framework Cocoa -framework IOKit -framework CoreVideo -Wl,-undefined,dynamic_lookup
|
||||
|
||||
This creates the file 'libsimple.dylib' as a universal binary (or alternatively remove one of the -arch options from both commands if you want to just compile for one architecture).
|
||||
|
||||
## Usage
|
||||
|
||||
Create a new object using `load("res://SIMPLE.gdn").new()`
|
||||
|
||||
This object has following methods you can use:
|
||||
* `get_data()`
|
||||
|
||||
22
c/SimpleDemo/SIMPLE.gdn
Normal file
22
c/SimpleDemo/SIMPLE.gdn
Normal file
@@ -0,0 +1,22 @@
|
||||
[gd_resource type="GDNativeScript" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="GDNativeLibrary" id=1]
|
||||
|
||||
platform/unix = ""
|
||||
platform/x11 = "res://src/libsimple.so"
|
||||
platform/server = ""
|
||||
platform/android = ""
|
||||
platform/blackberry = ""
|
||||
platform/haiku = ""
|
||||
platform/mac = "res://src/libsimple.dylib"
|
||||
platform/ios = ""
|
||||
platform/osx = "res://src/libsimple.dylib"
|
||||
platform/html5 = ""
|
||||
platform/windows = ""
|
||||
platform/uwp = ""
|
||||
|
||||
[resource]
|
||||
|
||||
library = SubResource( 1 )
|
||||
script_name = "SIMPLE"
|
||||
|
||||
99
c/SimpleDemo/default_env.tres
Normal file
99
c/SimpleDemo/default_env.tres
Normal file
@@ -0,0 +1,99 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
radiance_size = 1
|
||||
sky_top_color = Color( 0.301961, 0.403922, 0.909804, 1 )
|
||||
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
|
||||
sky_curve = 0.25
|
||||
sky_energy = 1.0
|
||||
ground_bottom_color = Color( 0.196078, 0.152941, 0.0980392, 1 )
|
||||
ground_horizon_color = Color( 0.329412, 0.211765, 0.0627451, 1 )
|
||||
ground_curve = 0.25
|
||||
ground_energy = 1.0
|
||||
sun_color = Color( 1, 1, 1, 1 )
|
||||
sun_latitude = 35.0
|
||||
sun_longitude = 0.0
|
||||
sun_angle_min = 1.0
|
||||
sun_angle_max = 100.0
|
||||
sun_curve = 0.05
|
||||
sun_energy = 16.0
|
||||
texture_size = 0
|
||||
|
||||
[resource]
|
||||
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
background_sky_scale = 1.0
|
||||
background_color = Color( 0, 0, 0, 1 )
|
||||
background_energy = 1.0
|
||||
background_canvas_max_layer = 0
|
||||
ambient_light_color = Color( 0, 0, 0, 1 )
|
||||
ambient_light_energy = 1.0
|
||||
ambient_light_sky_contribution = 0.0
|
||||
fog_enabled = false
|
||||
fog_color = Color( 0.5, 0.6, 0.7, 1 )
|
||||
fog_sun_color = Color( 1, 0.9, 0.7, 1 )
|
||||
fog_sun_amount = 0.0
|
||||
fog_depth_enabled = true
|
||||
fog_depth_begin = 10.0
|
||||
fog_depth_curve = 1.0
|
||||
fog_transmit_enabled = false
|
||||
fog_transmit_curve = 1.0
|
||||
fog_height_enabled = false
|
||||
fog_height_min = 0.0
|
||||
fog_height_max = 100.0
|
||||
fog_height_curve = 1.0
|
||||
tonemap_mode = 0
|
||||
tonemap_exposure = 1.0
|
||||
tonemap_white = 1.0
|
||||
auto_exposure_enabled = false
|
||||
auto_exposure_scale = 0.4
|
||||
auto_exposure_min_luma = 0.05
|
||||
auto_exposure_max_luma = 8.0
|
||||
auto_exposure_speed = 0.5
|
||||
ss_reflections_enabled = false
|
||||
ss_reflections_max_steps = 64
|
||||
ss_reflections_fade_in = 0.15
|
||||
ss_reflections_fade_out = 2.0
|
||||
ss_reflections_depth_tolerance = 0.2
|
||||
ss_reflections_roughness = true
|
||||
ssao_enabled = false
|
||||
ssao_radius = 1.0
|
||||
ssao_intensity = 1.0
|
||||
ssao_radius2 = 0.0
|
||||
ssao_intensity2 = 1.0
|
||||
ssao_bias = 0.01
|
||||
ssao_light_affect = 0.0
|
||||
ssao_color = Color( 0, 0, 0, 1 )
|
||||
ssao_blur = true
|
||||
dof_blur_far_enabled = false
|
||||
dof_blur_far_distance = 10.0
|
||||
dof_blur_far_transition = 5.0
|
||||
dof_blur_far_amount = 0.1
|
||||
dof_blur_far_quality = 1
|
||||
dof_blur_near_enabled = false
|
||||
dof_blur_near_distance = 2.0
|
||||
dof_blur_near_transition = 1.0
|
||||
dof_blur_near_amount = 0.1
|
||||
dof_blur_near_quality = 1
|
||||
glow_enabled = false
|
||||
glow_levels/1 = false
|
||||
glow_levels/2 = false
|
||||
glow_levels/3 = true
|
||||
glow_levels/4 = false
|
||||
glow_levels/5 = true
|
||||
glow_levels/6 = false
|
||||
glow_levels/7 = false
|
||||
glow_intensity = 0.8
|
||||
glow_strength = 1.0
|
||||
glow_bloom = 0.0
|
||||
glow_blend_mode = 2
|
||||
glow_hdr_treshold = 1.0
|
||||
glow_hdr_scale = 2.0
|
||||
glow_bicubic_upscale = false
|
||||
adjustment_enabled = false
|
||||
adjustment_brightness = 1.0
|
||||
adjustment_contrast = 1.0
|
||||
adjustment_saturation = 1.0
|
||||
|
||||
BIN
c/SimpleDemo/icon.png
Normal file
BIN
c/SimpleDemo/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
13
c/SimpleDemo/main.gd
Normal file
13
c/SimpleDemo/main.gd
Normal file
@@ -0,0 +1,13 @@
|
||||
extends Control
|
||||
|
||||
# load the SIMPLE library
|
||||
onready var data = preload("res://SIMPLE.gdn").new()
|
||||
|
||||
func _ready():
|
||||
# Called every time the node is added to the scene.
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
func _on_Button_pressed():
|
||||
get_node("Label").set_text("Data = " + data.get_data())
|
||||
43
c/SimpleDemo/main.tscn
Normal file
43
c/SimpleDemo/main.tscn
Normal file
@@ -0,0 +1,43 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://main.gd" type="Script" id=1]
|
||||
|
||||
[node name="main" type="Control"]
|
||||
|
||||
anchor_right = 1
|
||||
anchor_bottom = 1
|
||||
rect_clip_content = false
|
||||
mouse_filter = 0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
|
||||
margin_left = 384.0
|
||||
margin_top = 233.0
|
||||
margin_right = 630.0
|
||||
margin_bottom = 289.0
|
||||
rect_clip_content = false
|
||||
mouse_filter = 0
|
||||
toggle_mode = false
|
||||
enabled_focus_mode = 2
|
||||
shortcut = null
|
||||
group = null
|
||||
text = "Hello"
|
||||
flat = false
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
|
||||
margin_left = 392.0
|
||||
margin_top = 311.0
|
||||
margin_right = 629.0
|
||||
margin_bottom = 368.0
|
||||
rect_clip_content = false
|
||||
mouse_filter = 2
|
||||
size_flags_vertical = 0
|
||||
percent_visible = 1.0
|
||||
lines_skipped = 0
|
||||
max_lines_visible = -1
|
||||
|
||||
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
|
||||
|
||||
|
||||
14
c/SimpleDemo/project.godot
Normal file
14
c/SimpleDemo/project.godot
Normal file
@@ -0,0 +1,14 @@
|
||||
config_version=3
|
||||
[application]
|
||||
|
||||
name="SimpleDemo"
|
||||
main_scene="res://main.tscn"
|
||||
icon="res://icon.png"
|
||||
|
||||
[memory]
|
||||
|
||||
multithread/thread_rid_pool_prealloc=60
|
||||
|
||||
[rendering]
|
||||
|
||||
viewport/default_environment="res://default_env.tres"
|
||||
58
c/SimpleDemo/src/simple.c
Normal file
58
c/SimpleDemo/src/simple.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <godot.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct user_data_struct {
|
||||
char data[256];
|
||||
} user_data_struct;
|
||||
|
||||
void *simple_constructor(godot_object *instance, void *method_data);
|
||||
void simple_destructor(godot_object *instance, void *method_data, user_data_struct *user_data);
|
||||
godot_variant simple_get_data(godot_object *instance, void *method_data, user_data_struct *user_data, int num_args, godot_variant **args);
|
||||
|
||||
void godot_native_init(godot_native_init_options *options) {
|
||||
|
||||
godot_instance_create_func create = {};
|
||||
create.create_func = &simple_constructor;
|
||||
|
||||
godot_instance_destroy_func destroy = {};
|
||||
destroy.destroy_func = &simple_destructor;
|
||||
|
||||
godot_script_register_class("SIMPLE", "Reference", create, destroy);
|
||||
|
||||
{
|
||||
godot_instance_method get_data = {};
|
||||
get_data.method = &simple_get_data;
|
||||
|
||||
godot_method_attributes attributes = {};
|
||||
attributes.rpc_type = GODOT_METHOD_RPC_MODE_DISABLED;
|
||||
|
||||
godot_script_register_method("SIMPLE", "get_data", attributes, get_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void *simple_constructor(godot_object *instance, void *method_data) {
|
||||
printf("SIMPLE._init()\n");
|
||||
|
||||
user_data_struct *user_data = godot_alloc(sizeof(user_data_struct));
|
||||
strcpy(user_data->data, "World");
|
||||
|
||||
return user_data;
|
||||
}
|
||||
|
||||
void simple_destructor(godot_object *instance, void *method_data, user_data_struct *user_data) {
|
||||
printf("SIMPLE._byebye()\n");
|
||||
|
||||
godot_free(user_data);
|
||||
}
|
||||
|
||||
godot_variant simple_get_data(godot_object *instance, void *method_data, user_data_struct *user_data, int num_args, godot_variant **args) {
|
||||
godot_string data;
|
||||
godot_variant ret;
|
||||
|
||||
godot_string_new_data(&data, user_data->data, strlen(user_data->data));
|
||||
godot_variant_new_string(&ret, &data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user