From 00c7e54d3c593dbddb036f2185e614e7e4b22a1f Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 6 Aug 2016 11:32:35 +0200 Subject: Add raylib lua examples --- examples/textures_raw_data.lua | 83 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 examples/textures_raw_data.lua (limited to 'examples/textures_raw_data.lua') diff --git a/examples/textures_raw_data.lua b/examples/textures_raw_data.lua new file mode 100644 index 00000000..16c1c0ad --- /dev/null +++ b/examples/textures_raw_data.lua @@ -0,0 +1,83 @@ +------------------------------------------------------------------------------------------- +-- +-- raylib [textures] example - Load textures from raw data +-- +-- NOTE: Images are loaded in CPU memory (RAM) textures are loaded in GPU memory (VRAM) +-- +-- This example has been created using raylib 1.6 (www.raylib.com) +-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +-- +-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) +-- +------------------------------------------------------------------------------------------- + +--#include -- Required for malloc() and free() + +-- Initialization +------------------------------------------------------------------------------------------- +local screenWidth = 800 +local screenHeight = 450 + +InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data") + +-- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + +-- Load RAW image data (512x512, 32bit RGBA, no file header) +local sonicRaw = LoadImageRaw("resources/texture_formats/sonic_R8G8B8A8.raw", 512, 512, TextureFormat.UNCOMPRESSED_R8G8B8A8, 0) +local sonic = LoadTextureFromImage(sonicRaw) -- Upload CPU (RAM) image to GPU (VRAM) +UnloadImage(sonicRaw) -- Unload CPU (RAM) image data + +-- Generate a checked texture by code (1024x1024 pixels) +local width = 1024 +local height = 1024 + +-- Dynamic memory allocation to store pixels data (Color type) +local pixels = {} + +for y = 1, height do + for x = 1, width do + if (((x/32+y/32)/1)%2 == 0) then pixels[y*height + x] = DARKBLUE + else pixels[y*height + x] = SKYBLUE end + end +end + +-- Load pixels data into an image structure and create texture +local checkedIm = LoadImageEx(pixels, width, height) +local checked = LoadTextureFromImage(checkedIm) +UnloadImage(checkedIm) -- Unload CPU (RAM) image data + +-- Dynamic memory must be freed after using it +--free(pixels) -- Unload CPU (RAM) pixels data +------------------------------------------------------------------------------------------- + +-- Main game loop +while not WindowShouldClose() do -- Detect window close button or ESC key + -- Update + --------------------------------------------------------------------------------------- + -- TODO: Update your variables here + --------------------------------------------------------------------------------------- + + -- Draw + --------------------------------------------------------------------------------------- + BeginDrawing() + + ClearBackground(RAYWHITE) + + DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.3)) + DrawTexture(sonic, 330, -20, WHITE) + + DrawText("CHECKED TEXTURE ", 84, 100, 30, DARKBLUE) + DrawText("GENERATED by CODE", 72, 164, 30, DARKBLUE) + DrawText("and RAW IMAGE LOADING", 46, 226, 30, DARKBLUE) + + EndDrawing() + --------------------------------------------------------------------------------------- +end + +-- De-Initialization +------------------------------------------------------------------------------------------- +UnloadTexture(sonic) -- Texture unloading +UnloadTexture(checked) -- Texture unloading + +CloseWindow() -- Close window and OpenGL context +------------------------------------------------------------------------------------------- \ No newline at end of file -- cgit v1.2.3 From 865b216ebef8e62a19f3a264001ddf17601f95c5 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 6 Aug 2016 19:29:58 +0200 Subject: Updated Lua examples Most of the examples already working! Only some of them still fail, mostly related to data arrays... --- examples/audio_module_playing.lua | 14 +----- examples/core_2d_camera.lua | 2 +- examples/core_3d_picking.lua | 8 ++-- examples/core_world_screen.lua | 2 +- examples/models_billboard.lua | 2 +- examples/models_box_collisions.lua | 2 +- examples/models_cubicmap.lua | 8 ++-- examples/models_heightmap.lua | 2 +- examples/rlua_execute_file.c | 66 +++++++++++++------------- examples/shaders_custom_uniform.lua | 2 +- examples/shaders_model_shader.lua | 2 +- examples/shaders_postprocessing.lua | 2 +- examples/shaders_standard_lighting.lua | 24 +++++----- examples/text_rbmf_fonts.lua | 2 +- examples/text_writing_anim.lua | 2 +- examples/textures_particles_trail_blending.lua | 5 +- examples/textures_raw_data.lua | 2 +- 17 files changed, 69 insertions(+), 78 deletions(-) (limited to 'examples/textures_raw_data.lua') diff --git a/examples/audio_module_playing.lua b/examples/audio_module_playing.lua index 38cf9afe..3c5ad641 100644 --- a/examples/audio_module_playing.lua +++ b/examples/audio_module_playing.lua @@ -11,16 +11,6 @@ MAX_CIRCLES = 64 ---[[ -typedef struct { -- TODO: Find a Lua alternative: TABLES? - Vector2 position - float radius - float alpha - float speed - Color color -} CircleWave ---]] - -- Initialization ------------------------------------------------------------------------------------------- local screenWidth = 800 @@ -78,7 +68,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key circles[i].radius = GetRandomValue(10, 40) circles[i].position.x = GetRandomValue(circles[i].radius, screenWidth - circles[i].radius) circles[i].position.y = GetRandomValue(circles[i].radius, screenHeight - circles[i].radius) - circles[i].color = colors[GetRandomValue(0, 13)] + circles[i].color = colors[GetRandomValue(1, 14)] circles[i].speed = GetRandomValue(1, 100)/20000.0 end end @@ -112,7 +102,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key -- Draw time bar DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY) - DrawRectangle(20, screenHeight - 20 - 12, timePlayed, 12, MAROON) + DrawRectangle(20, screenHeight - 20 - 12, timePlayed//1, 12, MAROON) DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE) EndDrawing() diff --git a/examples/core_2d_camera.lua b/examples/core_2d_camera.lua index a7c0515a..95302c26 100644 --- a/examples/core_2d_camera.lua +++ b/examples/core_2d_camera.lua @@ -91,7 +91,7 @@ while not WindowShouldClose() do -- Detect window close button or ClearBackground(RAYWHITE) - Begin2dMode(camera) -- ERROR: Lua Error: attempt to index a number value (?) + Begin2dMode(camera) DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY) diff --git a/examples/core_3d_picking.lua b/examples/core_3d_picking.lua index 2e1dc7c4..1adee67c 100644 --- a/examples/core_3d_picking.lua +++ b/examples/core_3d_picking.lua @@ -41,7 +41,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per-secon while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update internal camera and our camera if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then -- NOTE: This function is NOT WORKING properly! @@ -49,8 +49,10 @@ while not WindowShouldClose() do -- Detect window close button or ESC -- Check collision between ray and box collision = CheckCollisionRayBox(ray, - (BoundingBox)((Vector3)(cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2), - (Vector3)(cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2))) + BoundingBox(Vector3(cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2), + Vector3(cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2))) + + --print("collision check:", collision) end --------------------------------------------------------------------------------------- diff --git a/examples/core_world_screen.lua b/examples/core_world_screen.lua index ebad41f8..51f2cdbf 100644 --- a/examples/core_world_screen.lua +++ b/examples/core_world_screen.lua @@ -56,7 +56,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key End3dMode() - DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20)//2, cubeScreenPosition.y, 20, BLACK) + DrawText("Enemy: 100 / 100", cubeScreenPosition.x//1 - MeasureText("Enemy: 100 / 100", 20)//2, cubeScreenPosition.y//1, 20, BLACK) DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20))//2, 25, 20, GRAY) EndDrawing() diff --git a/examples/models_billboard.lua b/examples/models_billboard.lua index 25b00510..457198e6 100644 --- a/examples/models_billboard.lua +++ b/examples/models_billboard.lua @@ -34,7 +34,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per-secon while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update internal camera and our camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/models_box_collisions.lua b/examples/models_box_collisions.lua index d8b2e4b5..4a3107b9 100644 --- a/examples/models_box_collisions.lua +++ b/examples/models_box_collisions.lua @@ -60,7 +60,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC enemyBoxPos.z - enemyBoxSize.z/2), Vector3(enemyBoxPos.x + enemyBoxSize.x/2, enemyBoxPos.y + enemyBoxSize.y/2, - enemyBoxPos.z + enemyBoxSize.z/2))) then collision = true + enemyBoxPos.z + enemyBoxSize.z/2)))) then collision = true end -- Check collisions player vs enemy-sphere diff --git a/examples/models_cubicmap.lua b/examples/models_cubicmap.lua index 53cb2c12..bae3bac2 100644 --- a/examples/models_cubicmap.lua +++ b/examples/models_cubicmap.lua @@ -32,17 +32,17 @@ local mapPosition = Vector3(-16.0, 0.0, -8.0) -- Set model position UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position +SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update internal camera and our camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/models_heightmap.lua b/examples/models_heightmap.lua index 6d7f6f3f..4240f8b7 100644 --- a/examples/models_heightmap.lua +++ b/examples/models_heightmap.lua @@ -37,7 +37,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per-secon while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update internal camera and our camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/rlua_execute_file.c b/examples/rlua_execute_file.c index 5c2d8654..6050cf14 100644 --- a/examples/rlua_execute_file.c +++ b/examples/rlua_execute_file.c @@ -29,8 +29,8 @@ int main() //-------------------------------------------------------------------------------------- // ExecuteLuaFile("core_basic_window.lua"); // OK! - // ExecuteLuaFile("core_input_keys.lua"); // OK! - // ExecuteLuaFile("core_input_mouse.lua"); // OK! + // ExecuteLuaFile("core_input_keys.lua"); // OK! + // ExecuteLuaFile("core_input_mouse.lua"); // OK! // ExecuteLuaFile("core_mouse_wheel.lua"); // OK! // ExecuteLuaFile("core_input_gamepad.lua"); // OK! // ExecuteLuaFile("core_random_values.lua"); // OK! @@ -38,13 +38,13 @@ int main() // ExecuteLuaFile("core_drop_files.lua"); // ERROR: GetDroppedFiles() // ExecuteLuaFile("core_storage_values.lua"); // OK! // ExecuteLuaFile("core_gestures_detection.lua"); // OK! - // ExecuteLuaFile("core_3d_mode.lua"); // ERROR: Lua Error: attempt to index a number value - Begin3dMode() - // ExecuteLuaFile("core_3d_picking.lua"); // ERROR: Lua Error: attempt to index a number value - // ExecuteLuaFile("core_3d_camera_free.lua"); // ERROR: Lua Error: attempt to index a number value - // ExecuteLuaFile("core_3d_camera_first_person.lua"); // ERROR: Lua Error: attempt to index a number value - // ExecuteLuaFile("core_2d_camera.lua"); // ERROR: Lua Error: attempt to index a number value - Begin2dMode() - // ExecuteLuaFile("core_world_screen.lua"); // ERROR: Lua Error: attempt to index a number value - // ExecuteLuaFile("core_oculus_rift.lua"); // ERROR: Lua Error: attempt to index a number value + // ExecuteLuaFile("core_3d_mode.lua"); // OK! + // ExecuteLuaFile("core_3d_picking.lua"); // ISSUE: CheckCollisionRayBox() returns false despite touching box + // ExecuteLuaFile("core_3d_camera_free.lua"); // OK! + // ExecuteLuaFile("core_3d_camera_first_person.lua"); // OK! + // ExecuteLuaFile("core_2d_camera.lua"); // OK! + // ExecuteLuaFile("core_world_screen.lua"); // OK! + // ExecuteLuaFile("core_oculus_rift.lua"); // OK! // ExecuteLuaFile("shapes_logo_raylib.lua"); // OK! // ExecuteLuaFile("shapes_basic_shapes.lua"); // OK! // ExecuteLuaFile("shapes_colors_palette.lua"); // OK! @@ -54,31 +54,31 @@ int main() // ExecuteLuaFile("textures_rectangle.lua"); // OK! // ExecuteLuaFile("textures_srcrec_dstrec.lua"); // OK! // ExecuteLuaFile("textures_to_image.lua"); // OK! - // ExecuteLuaFile("textures_raw_data.lua"); // ERROR: Lua Error: attempt to index a number value - // ExecuteLuaFile("textures_formats_loading.lua"); // ISSUE: texture.id not exposed to be checked - // ExecuteLuaFile("textures_particles_trail_blending.lua"); // ERROR: Using struct - // ExecuteLuaFile("textures_image_processing.lua"); // ERROR: GetImageData() --> UpdateTexture() - // ExecuteLuaFile("textures_image_drawing.lua"); // OK! - // ExecuteLuaFile("text_sprite_fonts.lua"); // OK! - // ExecuteLuaFile("text_bmfont_ttf.lua"); // OK! - // ExecuteLuaFile("text_rbmf_fonts.lua"); // ERROR: Lua Error: attempt to index a nil value - // ExecuteLuaFile("text_format_text.lua"); // OK! NOTE: Use lua string.format() instead of raylib FormatText() - // ExecuteLuaFile("text_font_select.lua"); // OK! - // ExecuteLuaFile("text_writing_anim.lua"); // ERROR: SubText() - // ExecuteLuaFile("models_geometric_shapes.lua"); // ERROR: Lua Error: attempt to index a number value - Begin3dMode(camera) - // ExecuteLuaFile("models_box_collisions.lua"); // - // ExecuteLuaFile("models_billboard.lua"); // - // ExecuteLuaFile("models_obj_loading.lua"); // - // ExecuteLuaFile("models_heightmap.lua"); // - // ExecuteLuaFile("models_cubicmap.lua"); // - // ExecuteLuaFile("shaders_model_shader.lua"); // - // ExecuteLuaFile("shaders_shapes_textures.lua"); // - // ExecuteLuaFile("shaders_custom_uniform.lua"); // - // ExecuteLuaFile("shaders_postprocessing.lua"); // - // ExecuteLuaFile("shaders_standard_lighting.lua"); // + // ExecuteLuaFile("textures_raw_data.lua"); // ERROR: bad argument #2 to 'LoadImageEx' (number expected, got no value) + // ExecuteLuaFile("textures_formats_loading.lua"); // ISSUE: texture.id not exposed to be checked (not really an issue...) + // ExecuteLuaFile("textures_particles_trail_blending.lua"); // OK! + // ExecuteLuaFile("textures_image_processing.lua"); // ERROR: GetImageData() --> UpdateTexture() + // ExecuteLuaFile("textures_image_drawing.lua"); // OK! + // ExecuteLuaFile("text_sprite_fonts.lua"); // OK! + // ExecuteLuaFile("text_bmfont_ttf.lua"); // OK! + // ExecuteLuaFile("text_rbmf_fonts.lua"); // OK! + // ExecuteLuaFile("text_format_text.lua"); // OK! NOTE: Use lua string.format() instead of raylib FormatText() + // ExecuteLuaFile("text_font_select.lua"); // OK! + // ExecuteLuaFile("text_writing_anim.lua"); // OK! + // ExecuteLuaFile("models_geometric_shapes.lua"); // OK! + // ExecuteLuaFile("models_box_collisions.lua"); // OK! + // ExecuteLuaFile("models_billboard.lua"); // OK! + // ExecuteLuaFile("models_obj_loading.lua"); // OK! + // ExecuteLuaFile("models_heightmap.lua"); // OK! + // ExecuteLuaFile("models_cubicmap.lua"); // OK! + // ExecuteLuaFile("shaders_model_shader.lua"); // OK! + // ExecuteLuaFile("shaders_shapes_textures.lua"); // OK! + // ExecuteLuaFile("shaders_custom_uniform.lua"); // ISSUE: SetShaderValue() + // ExecuteLuaFile("shaders_postprocessing.lua"); // OK! + // ExecuteLuaFile("shaders_standard_lighting.lua"); // ERROR: CreateLight() returns an opaque pointer (fields can not be accessed) // ExecuteLuaFile("audio_sound_loading.lua"); // OK! // ExecuteLuaFile("audio_music_stream.lua"); // OK! - ExecuteLuaFile("audio_module_playing.lua"); // ERROR: Using struct + // ExecuteLuaFile("audio_module_playing.lua"); // OK! ExecuteLuaFile("audio_raw_stream.lua"); // ERROR: UpdateAudioStream() // De-Initialization @@ -86,5 +86,5 @@ int main() CloseLuaDevice(); // Close Lua device and free resources //-------------------------------------------------------------------------------------- - return 0; + return 0; } \ No newline at end of file diff --git a/examples/shaders_custom_uniform.lua b/examples/shaders_custom_uniform.lua index b4e4d483..fb93adc1 100644 --- a/examples/shaders_custom_uniform.lua +++ b/examples/shaders_custom_uniform.lua @@ -66,7 +66,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key -- Send new value to the shader to be used on drawing SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2) - UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update internal camera and our camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/shaders_model_shader.lua b/examples/shaders_model_shader.lua index b31c8609..d1436a7e 100644 --- a/examples/shaders_model_shader.lua +++ b/examples/shaders_model_shader.lua @@ -50,7 +50,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-pe while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update internal camera and our camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/shaders_postprocessing.lua b/examples/shaders_postprocessing.lua index 0913fbbd..f20f31ec 100644 --- a/examples/shaders_postprocessing.lua +++ b/examples/shaders_postprocessing.lua @@ -52,7 +52,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per-s while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update internal camera and our camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/shaders_standard_lighting.lua b/examples/shaders_standard_lighting.lua index 7c354d54..2f3700ff 100644 --- a/examples/shaders_standard_lighting.lua +++ b/examples/shaders_standard_lighting.lua @@ -27,9 +27,9 @@ InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader") -- Define the camera to look into our 3d world local camera = Camera(Vector3(4.0, 4.0, 4.0), Vector3(0.0, 1.5, 0.0), Vector3(0.0, 1.0, 0.0), 45.0) -local position = Vector3(0.0, 0.0, 0.0) -- Set model position local dwarf = LoadModel("resources/model/dwarf.obj") -- Load OBJ model +local position = Vector3(0.0, 0.0, 0.0) -- Set model position local material = LoadStandardMaterial() @@ -37,30 +37,30 @@ material.texDiffuse = LoadTexture("resources/model/dwarf_diffuse.png") -- Load material.texNormal = LoadTexture("resources/model/dwarf_normal.png") -- Load model normal texture material.texSpecular = LoadTexture("resources/model/dwarf_specular.png") -- Load model specular texture material.colDiffuse = WHITE -material.colAmbient = (Color)(0, 0, 10, 255) +material.colAmbient = Color(0, 0, 10, 255) material.colSpecular = WHITE material.glossiness = 50.0 dwarf.material = material -- Apply material to model -local spotLight = CreateLight(LIGHT_SPOT, (Vector3)(3.0, 5.0, 2.0), (Color)(255, 255, 255, 255)) -spotLight.target = (Vector3)(0.0, 0.0, 0.0) +local spotLight = CreateLight(LightType.SPOT, Vector3(3.0, 5.0, 2.0), Color(255, 255, 255, 255)) +spotLight.target = Vector3(0.0, 0.0, 0.0) spotLight.intensity = 2.0 -spotLight.diffuse = (Color)(255, 100, 100, 255) +spotLight.diffuse = Color(255, 100, 100, 255) spotLight.coneAngle = 60.0 -local dirLight = CreateLight(LIGHT_DIRECTIONAL, (Vector3)(0.0, -3.0, -3.0), (Color)(255, 255, 255, 255)) -dirLight.target = (Vector3)(1.0, -2.0, -2.0) +local dirLight = CreateLight(LightType.DIRECTIONAL, Vector3(0.0, -3.0, -3.0), Color(255, 255, 255, 255)) +dirLight.target = Vector3(1.0, -2.0, -2.0) dirLight.intensity = 2.0 -dirLight.diffuse = (Color)(100, 255, 100, 255) +dirLight.diffuse = Color(100, 255, 100, 255) -local pointLight = CreateLight(LIGHT_POINT, (Vector3)(0.0, 4.0, 5.0), (Color)(255, 255, 255, 255)) +local pointLight = CreateLight(LightType.POINT, Vector3(0.0, 4.0, 5.0), Color(255, 255, 255, 255)) pointLight.intensity = 2.0 -pointLight.diffuse = (Color)(100, 100, 255, 255) +pointLight.diffuse = Color(100, 100, 255, 255) pointLight.radius = 3.0 -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode +SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode SetCameraPosition(camera.position) -- Set internal camera position to match our camera position SetCameraTarget(camera.target) -- Set internal camera target to match our camera target @@ -71,7 +71,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per-s while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update internal camera and our camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/text_rbmf_fonts.lua b/examples/text_rbmf_fonts.lua index 0e0e4142..31a733f1 100644 --- a/examples/text_rbmf_fonts.lua +++ b/examples/text_rbmf_fonts.lua @@ -47,7 +47,7 @@ local positions = {} for i = 1, 8 do positions[i] = Vector2(0, 0) positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].size*2, spacings[i]).x/2 - positions[i].y = 60 + fonts[i].size + 50*i + positions[i].y = 60 + fonts[i].size + 45*(i - 1) end local colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, BLACK } diff --git a/examples/text_writing_anim.lua b/examples/text_writing_anim.lua index 05195dc4..f4af9f58 100644 --- a/examples/text_writing_anim.lua +++ b/examples/text_writing_anim.lua @@ -38,7 +38,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC ClearBackground(RAYWHITE) - DrawText(string.sub(message, 0, framesCounter/10), 210, 160, 20, MAROON) + DrawText(string.sub(message, 0, framesCounter//10), 210, 160, 20, MAROON) DrawText("PRESS [ENTER] to RESTART!", 240, 280, 20, LIGHTGRAY) diff --git a/examples/textures_particles_trail_blending.lua b/examples/textures_particles_trail_blending.lua index 38036bcf..d2c2518e 100644 --- a/examples/textures_particles_trail_blending.lua +++ b/examples/textures_particles_trail_blending.lua @@ -11,7 +11,6 @@ MAX_PARTICLES = 200 --- Particle structure with basic data -- Initialization ------------------------------------------------------------------------------------------- local screenWidth = 800 @@ -56,7 +55,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC mouseTail[i].active = true mouseTail[i].alpha = 1.0 mouseTail[i].position = GetMousePosition() - i = MAX_PARTICLES + break end end @@ -90,7 +89,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC if (mouseTail[i].active) then DrawTexturePro(smoke, Rectangle(0, 0, smoke.width, smoke.height), Rectangle(mouseTail[i].position.x, mouseTail[i].position.y, - smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size), + smoke.width*mouseTail[i].size//1, smoke.height*mouseTail[i].size//1), Vector2(smoke.width*mouseTail[i].size/2, smoke.height*mouseTail[i].size/2), mouseTail[i].rotation, Fade(mouseTail[i].color, mouseTail[i].alpha)) end end diff --git a/examples/textures_raw_data.lua b/examples/textures_raw_data.lua index 16c1c0ad..8a955adf 100644 --- a/examples/textures_raw_data.lua +++ b/examples/textures_raw_data.lua @@ -36,7 +36,7 @@ local pixels = {} for y = 1, height do for x = 1, width do - if (((x/32+y/32)/1)%2 == 0) then pixels[y*height + x] = DARKBLUE + if ((((x - 1)/32+(y - 1)//32)//1)%2 == 0) then pixels[y*height + x] = DARKBLUE else pixels[y*height + x] = SKYBLUE end end end -- cgit v1.2.3 From 7fbd821727228396e03f47786a4db27f00aaebba Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 7 Aug 2016 13:51:01 +0200 Subject: Some code review tweaks --- examples/textures_raw_data.lua | 4 +-- src/rlua.h | 70 ++++++++++++------------------------------ 2 files changed, 22 insertions(+), 52 deletions(-) (limited to 'examples/textures_raw_data.lua') diff --git a/examples/textures_raw_data.lua b/examples/textures_raw_data.lua index 8a955adf..0bad1771 100644 --- a/examples/textures_raw_data.lua +++ b/examples/textures_raw_data.lua @@ -36,8 +36,8 @@ local pixels = {} for y = 1, height do for x = 1, width do - if ((((x - 1)/32+(y - 1)//32)//1)%2 == 0) then pixels[y*height + x] = DARKBLUE - else pixels[y*height + x] = SKYBLUE end + if ((((x - 1)/32+(y - 1)//32)//1)%2 == 0) then pixels[(y - 1)*height + x] = DARKBLUE + else pixels[(y - 1)*height + x] = SKYBLUE end end end diff --git a/src/rlua.h b/src/rlua.h index 153f2c37..849c1c64 100644 --- a/src/rlua.h +++ b/src/rlua.h @@ -138,6 +138,7 @@ RLUADEF void CloseLuaDevice(void); // De-initialize Lua system #define LuaGetArgument_char (char)luaL_checkinteger #define LuaGetArgument_float (float)luaL_checknumber #define LuaGetArgument_double luaL_checknumber + #define LuaGetArgument_Image(L, img) *(Image*)LuaGetArgumentOpaqueTypeWithMetatable(L, img, "Image") #define LuaGetArgument_Texture2D(L, tex) *(Texture2D*)LuaGetArgumentOpaqueTypeWithMetatable(L, tex, "Texture2D") #define LuaGetArgument_RenderTexture2D(L, rtex) *(RenderTexture2D*)LuaGetArgumentOpaqueTypeWithMetatable(L, rtex, "RenderTexture2D") @@ -739,17 +740,6 @@ static int lua_Quaternion(lua_State* L) return 1; } -/* -static int lua_Matrix(lua_State* L) -{ - LuaPush_Matrix(L, (Matrix) { (float)luaL_checknumber(L, 1), (float)luaL_checknumber(L, 2), (float)luaL_checknumber(L, 3), (float)luaL_checknumber(L, 4), - (float)luaL_checknumber(L, 5), (float)luaL_checknumber(L, 6), (float)luaL_checknumber(L, 7), (float)luaL_checknumber(L, 8), - (float)luaL_checknumber(L, 9), (float)luaL_checknumber(L, 10), (float)luaL_checknumber(L, 11), (float)luaL_checknumber(L, 12), - (float)luaL_checknumber(L, 13), (float)luaL_checknumber(L, 14), (float)luaL_checknumber(L, 15), (float)luaL_checknumber(L, 16) }); - return 1; -} -*/ - static int lua_Rectangle(lua_State* L) { LuaPush_Rectangle(L, (Rectangle) { (int)luaL_checkinteger(L, 1), (int)luaL_checkinteger(L, 2), (int)luaL_checkinteger(L, 3), (int)luaL_checkinteger(L, 4) }); @@ -777,8 +767,8 @@ static int lua_Camera(lua_State* L) Vector3 pos = LuaGetArgument_Vector3(L, 1); Vector3 tar = LuaGetArgument_Vector3(L, 2); Vector3 up = LuaGetArgument_Vector3(L, 3); - //float fovy = LuaGetArgument_float(L, 4); // ??? - LuaPush_Camera(L, (Camera) { { pos.x, pos.y, pos.z }, { tar.x, tar.y, tar.z }, { up.x, up.y, up.z }, (float)luaL_checknumber(L, 4) }); + float fovy = LuaGetArgument_float(L, 4); + LuaPush_Camera(L, (Camera) { { pos.x, pos.y, pos.z }, { tar.x, tar.y, tar.z }, { up.x, up.y, up.z }, fovy }); return 1; } @@ -792,23 +782,6 @@ static int lua_Camera2D(lua_State* L) return 1; } -/* -// NOTE: does it make sense to have this constructor? Probably not... -static int lua_Material(lua_State* L) -{ - Shader sdr = LuaGetArgument_Shader(L, 1); - Texture2D td = LuaGetArgument_Texture2D(L, 2); - Texture2D tn = LuaGetArgument_Texture2D(L, 3); - Texture2D ts = LuaGetArgument_Texture2D(L, 4); - Color cd = LuaGetArgument_Color(L, 5); - Color ca = LuaGetArgument_Color(L, 6); - Color cs = LuaGetArgument_Color(L, 7); - float gloss = LuaGetArgument_float(L, 8); - LuaPush_Material(L, (Material) { sdr, td, tn, ts cd, ca, cs, gloss }); - return 1; -} -*/ - /************************************************************************************* * raylib Lua Functions Bindings **************************************************************************************/ @@ -1817,14 +1790,11 @@ int lua_LoadImage(lua_State* L) int lua_LoadImageEx(lua_State* L) { - //Color * arg1 = LuaGetArgument_Color *(L, 1); GET_TABLE(Color, arg1, 1); - int arg2 = LuaGetArgument_int(L, 2); int arg3 = LuaGetArgument_int(L, 3); - Image result = LoadImageEx(arg1, arg2, arg3); + Image result = LoadImageEx(arg1, arg2, arg3); // ISSUE: #3 number expected, got no value LuaPush_Image(L, result); - free(arg1); return 1; } @@ -1860,7 +1830,7 @@ int lua_LoadTexture(lua_State* L) int lua_LoadTextureEx(lua_State* L) { - void * arg1 = (char *)LuaGetArgument_string(L, 1); // NOTE: getting argument as string + void * arg1 = (char *)LuaGetArgument_string(L, 1); // NOTE: getting argument as string? int arg2 = LuaGetArgument_int(L, 2); int arg3 = LuaGetArgument_int(L, 3); int arg4 = LuaGetArgument_int(L, 4); @@ -2056,7 +2026,7 @@ int lua_ImageDrawTextEx(lua_State* L) Vector2 arg2 = LuaGetArgument_Vector2(L, 2); SpriteFont arg3 = LuaGetArgument_SpriteFont(L, 3); const char * arg4 = LuaGetArgument_string(L, 4); - int arg5 = LuaGetArgument_int(L, 5); + float arg5 = LuaGetArgument_float(L, 5); int arg6 = LuaGetArgument_int(L, 6); Color arg7 = LuaGetArgument_Color(L, 7); ImageDrawTextEx(&arg1, arg2, arg3, arg4, arg5, arg6, arg7); @@ -2134,7 +2104,7 @@ int lua_UpdateTexture(lua_State* L) { Texture2D arg1 = LuaGetArgument_Texture2D(L, 1); void * arg2 = (char *)LuaGetArgument_string(L, 2); // NOTE: Getting (void *) as string? - UpdateTexture(arg1, arg2); + UpdateTexture(arg1, arg2); // ISSUE: #2 string expected, got table -> GetImageData() returns a table! return 0; } @@ -2231,7 +2201,7 @@ int lua_DrawTextEx(lua_State* L) SpriteFont arg1 = LuaGetArgument_SpriteFont(L, 1); const char * arg2 = LuaGetArgument_string(L, 2); Vector2 arg3 = LuaGetArgument_Vector2(L, 3); - int arg4 = LuaGetArgument_int(L, 4); + float arg4 = LuaGetArgument_float(L, 4); int arg5 = LuaGetArgument_int(L, 5); Color arg6 = LuaGetArgument_Color(L, 6); DrawTextEx(arg1, arg2, arg3, arg4, arg5, arg6); @@ -3911,7 +3881,7 @@ static luaL_Reg raylib_functions[] = { REG(QuaternionToAxisAngle) REG(QuaternionTransform) - {0,0} + {NULL, NULL} // sentinel: end signal }; // Register raylib functionality @@ -4017,16 +3987,16 @@ RLUADEF void InitLuaDevice(void) LuaSetEnum("PLAYER3", 2); LuaSetEnum("PLAYER4", 3); - LuaSetEnum("BUTTON_A", 2); - LuaSetEnum("BUTTON_B", 1); - LuaSetEnum("BUTTON_X", 3); - LuaSetEnum("BUTTON_Y", 4); - LuaSetEnum("BUTTON_R1", 7); - LuaSetEnum("BUTTON_R2", 5); - LuaSetEnum("BUTTON_L1", 6); - LuaSetEnum("BUTTON_L2", 8); - LuaSetEnum("BUTTON_SELECT", 9); - LuaSetEnum("BUTTON_START", 10); + LuaSetEnum("PS3_BUTTON_A", 2); + LuaSetEnum("PS3_BUTTON_B", 1); + LuaSetEnum("PS3_BUTTON_X", 3); + LuaSetEnum("PS3_BUTTON_Y", 4); + LuaSetEnum("PS3_BUTTON_R1", 7); + LuaSetEnum("PS3_BUTTON_R2", 5); + LuaSetEnum("PS3_BUTTON_L1", 6); + LuaSetEnum("PS3_BUTTON_L2", 8); + LuaSetEnum("PS3_BUTTON_SELECT", 9); + LuaSetEnum("PS3_BUTTON_START", 10); LuaSetEnum("XBOX_BUTTON_A", 0); LuaSetEnum("XBOX_BUTTON_B", 1); @@ -4040,7 +4010,7 @@ RLUADEF void InitLuaDevice(void) #if defined(PLATFORM_RPI) LuaSetEnum("XBOX_AXIS_DPAD_X", 7); LuaSetEnum("XBOX_AXIS_DPAD_Y", 6); - LuaSetEnum("XBOX_AXIS_RIGHT_X", 3); + LuaSetEnum("XBOX_AXIS_RIGHT_X", 3); LuaSetEnum("XBOX_AXIS_RIGHT_Y", 4); LuaSetEnum("XBOX_AXIS_LT", 2); LuaSetEnum("XBOX_AXIS_RT", 5); -- cgit v1.2.3