diff --git a/src/game/sandbox/sandboxscene.c b/src/game/sandbox/sandboxscene.c index bc948789..28933564 100644 --- a/src/game/sandbox/sandboxscene.c +++ b/src/game/sandbox/sandboxscene.c @@ -8,12 +8,6 @@ #include "sandboxscene.h" bool sandboxSceneInit(sandboxscene_t *game) { - assetFontLoad(&game->font, "fonts/opensans/OpenSans-Regular.ttf"); - assetTextureLoad(&game->texture, "test_texture.png"); - assetShaderLoad(&game->shader, - "shaders/textured.vert", "shaders/textured.frag" - ); - // Init Scripter scripterInit(&game->scripter, &game->engine); game->scripter.user = game; @@ -21,30 +15,16 @@ bool sandboxSceneInit(sandboxscene_t *game) { scriptsApiIo(&game->scripter); scriptsApiDisplay(&game->scripter); scriptsApiAsset(&game->scripter); + assetScripterAppend(&game->scripter, "scripts/main.js"); + + scripterInvokeMethodSimple(&game->scripter, "init"); return true; } void sandboxSceneUpdate(sandboxscene_t *game) { - // cameraLookAt(&game->camera, 3,3,3, 0,0,0); - - // cameraPerspective(&game->camera, 45, - // game->engine.render.width/game->engine.render.height, - // 0.01f, 1000.0f - // ); - - // cameraLookAt(&game->camera, - // 3, 3, 3, - // 0, 0, 0 - // ); - - // shaderUse(&game->shader); - // shaderUseCamera(&game->shader, &game->camera); - // shaderUsePosition(&game->shader, 0,0,0, 0,0,0); - // shaderUseTexture(&game->shader, &game->texture); - scripterInvokeMethodSimple(&game->scripter, "update"); } diff --git a/src/game/sandbox/sandboxscene.h b/src/game/sandbox/sandboxscene.h index 979730a9..f7cbe88c 100644 --- a/src/game/sandbox/sandboxscene.h +++ b/src/game/sandbox/sandboxscene.h @@ -32,13 +32,6 @@ typedef struct { engine_t engine; - camera_t camera; - - primitive_t primitive; - texture_t texture; - shader_t shader; - font_t font; - scripter_t scripter; } sandboxscene_t; diff --git a/src/script/api/asset.c b/src/script/api/asset.c index 3d9fcd2d..4984d99b 100644 --- a/src/script/api/asset.c +++ b/src/script/api/asset.c @@ -7,19 +7,21 @@ #include "asset.h" -void _scriptApiShaderLoad(scriptercontext_t *ctx) { +scripterreturn_t _scriptApiShaderLoad(scriptercontext_t *ctx) { assetShaderLoad( duk_to_pointer(ctx, 0), duk_to_string(ctx, 1), duk_to_string(ctx, 2) ); + return 0; } -void _scriptApiTextureLoad(scriptercontext_t *ctx) { - assetShaderLoad( +scripterreturn_t _scriptApiTextureLoad(scriptercontext_t *ctx) { + assetTextureLoad( duk_to_pointer(ctx, 0), duk_to_string(ctx, 1) ); + return 0; } void scriptsApiAsset(scripter_t *s) { diff --git a/src/script/api/asset.d.ts b/src/script/api/asset.d.ts index 67f76bf7..8d21af15 100644 --- a/src/script/api/asset.d.ts +++ b/src/script/api/asset.d.ts @@ -3,8 +3,6 @@ // This software is released under the MIT License. // https://opensource.org/licenses/MIT -declare function assetShaderLoad( - shader:Shader, fileVertex:string, fileFrag:string -):void; +declare function assetShaderLoad(shader:Shader, vert:string, frag:string):void; -declare function assetTextureLoad(shader:Shader, texture:Texture):void; \ No newline at end of file +declare function assetTextureLoad(texture:Texture, file:string):void; \ No newline at end of file diff --git a/src/script/api/display.c b/src/script/api/display.c index fa12951f..dfb921cd 100644 --- a/src/script/api/display.c +++ b/src/script/api/display.c @@ -141,6 +141,11 @@ scripterreturn_t _scriptShaderUseCamera(scriptercontext_t *ctx) { return 0; } +scripterreturn_t _scriptShaderUseTexture(scriptercontext_t *ctx) { + shaderUseTexture(duk_to_pointer(ctx, 0), duk_to_pointer(ctx, 1)); + return 0; +} + scripterreturn_t _scriptShaderUsePosition(scriptercontext_t *ctx) { shaderUsePosition( duk_to_pointer(ctx, 0), @@ -172,6 +177,21 @@ scripterreturn_t _scriptShaderUsePositionAndScale(scriptercontext_t *ctx) { return 0; } + +scripterreturn_t _scriptTextureCreate(scriptercontext_t *ctx) { + texture_t *texture = malloc(sizeof(texture_t)); + duk_push_pointer(ctx, texture); + return 1; +} + +scripterreturn_t _scriptTextureDispose(scriptercontext_t *ctx) { + texture_t *texture = duk_to_pointer(ctx, 0); + textureDispose(texture); + free(texture); + return 0; +} + + void scriptsApiDisplay(scripter_t *s) { scripterDefineMethod(s, "primitiveCreate", 0, &_scriptPrimitiveCreate); scripterDefineMethod(s, "primitiveInit", 3, &_scriptPrimitiveInit); @@ -191,9 +211,13 @@ void scriptsApiDisplay(scripter_t *s) { scripterDefineMethod(s, "shaderInit", 3, &_scriptShaderInit); scripterDefineMethod(s, "shaderDispose", 1, &_scriptShaderDispose); scripterDefineMethod(s, "shaderUse", 1, &_scriptShaderUse); + scripterDefineMethod(s, "shaderUseTexture", 2, &_scriptShaderUseTexture); scripterDefineMethod(s, "shaderUseCamera", 2, &_scriptShaderUseCamera); scripterDefineMethod(s, "shaderUsePosition", 7, &_scriptShaderUsePosition); scripterDefineMethod( s, "shaderUsePositionAndScale", 10, &_scriptShaderUsePositionAndScale ); + + scripterDefineMethod(s, "textureCreate", 0, &_scriptTextureCreate); + scripterDefineMethod(s, "textureDispose", 1, &_scriptTextureDispose); } \ No newline at end of file diff --git a/src/script/api/display.d.ts b/src/script/api/display.d.ts index a94d2b84..91c8e795 100644 --- a/src/script/api/display.d.ts +++ b/src/script/api/display.d.ts @@ -56,6 +56,8 @@ declare function shaderDispose(shader:Shader):void; declare function shaderUse(shader:Shader):void; +declare function shaderUseTexture(shader:Shader, texture:Texture):void; + declare function shaderUseCamera(shader:Shader, camera:Camera):void; declare function shaderUsePosition(shader:Shader, @@ -67,4 +69,10 @@ declare function shaderUsePositionAndScale(shader:Shader, x:number, y:number, z:number, pitch:number, yaw:number, roll:number, sx:number, sy:number, sz:number -):void; \ No newline at end of file +):void; + +//////////////////////////////////////////////////////////////////////////////// + +declare function textureCreate():Texture; + +declare function textureDispose(texture:Texture):void; \ No newline at end of file diff --git a/ts/main.ts b/ts/main.ts index 23c5c5f4..47e1cf1d 100644 --- a/ts/main.ts +++ b/ts/main.ts @@ -1,25 +1,30 @@ let cube:Primitive; let shader:Shader; let camera:Camera; +let texture:Texture; const init = () => { print('Main invoked'); + // Create Quad cube = primitiveCreate(); quadInit(cube, 0, -1, -1, 0, 0, 1, 1, 1, 1); + // Create Camera camera = cameraCreate(); + // Load Shader shader = shaderCreate(); assetShaderLoad(shader, "shaders/textured.vert", "shaders/textured.frag"); - - shaderUse(shader); - cameraLookAt(camera, 3,3,3, 0,0,0); - cameraPerspective(camera, 45, 16/9, 0.01, 100); + + // Texture load + texture = textureCreate(); + assetTextureLoad(texture, "test_texture.png"); } const update = () => { shaderUse(shader); + shaderUseTexture(shader, texture); cameraLookAt(camera, 3,3,3, 0,0,0); cameraPerspective(camera, 45, 16/9, 0.01, 100);