From 1799c58ca5ae84ccdca3286e34f0bfcf9a954f06 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 1 Jul 2024 14:18:55 +0100 Subject: [PATCH] update examples --- ...core_3d_camera_first_person_incomplete.py} | 0 ...e.py => core_3d_camera_free_incomplete.py} | 0 .../core/core_smooth_pixel_perfect_camera.py | 4 +- examples/core/core_vr_simulator.py | 20 +++++---- .../{textures => extra}/textures_opencv.py | 0 examples/models/models_animation.py | 8 ++-- ...=> models_skybox_outdated_needs_update.py} | 16 ++++--- ...apes_draw_rounded_rectangle_incomplete.py} | 45 ++++++++++--------- tests/test_hello_world.py | 2 +- 9 files changed, 51 insertions(+), 44 deletions(-) rename examples/core/{core_3d_camera_first_person.py => core_3d_camera_first_person_incomplete.py} (100%) rename examples/core/{core_3d_camera_free.py => core_3d_camera_free_incomplete.py} (100%) rename examples/{textures => extra}/textures_opencv.py (100%) rename examples/models/{models_skybox.py => models_skybox_outdated_needs_update.py} (78%) rename examples/shapes/{shapes_draw_rounded_rectangle.py => shapes_draw_rounded_rectangle_incomplete.py} (62%) diff --git a/examples/core/core_3d_camera_first_person.py b/examples/core/core_3d_camera_first_person_incomplete.py similarity index 100% rename from examples/core/core_3d_camera_first_person.py rename to examples/core/core_3d_camera_first_person_incomplete.py diff --git a/examples/core/core_3d_camera_free.py b/examples/core/core_3d_camera_free_incomplete.py similarity index 100% rename from examples/core/core_3d_camera_free.py rename to examples/core/core_3d_camera_free_incomplete.py diff --git a/examples/core/core_smooth_pixel_perfect_camera.py b/examples/core/core_smooth_pixel_perfect_camera.py index 15b600c..1dcdc67 100644 --- a/examples/core/core_smooth_pixel_perfect_camera.py +++ b/examples/core/core_smooth_pixel_perfect_camera.py @@ -77,8 +77,8 @@ while not window_should_close(): # Detect window close button or ESC key draw_texture_pro(target.texture, sourceRec, destRec, origin, 0.0, WHITE) end_mode_2d() - draw_text(text_format("Screen resolution: %ix%i", screenWidth, screenHeight), 10, 10, 20, DARKBLUE) - draw_text(text_format("World resolution: %ix%i", virtualScreenWidth, virtualScreenHeight), 10, 40, 20, DARKGREEN) + draw_text(f"Screen resolution: {screenWidth}, {screenHeight}", 10, 10, 20, DARKBLUE) + draw_text(f"World resolution: {virtualScreenWidth}, {virtualScreenHeight}", 10, 40, 20, DARKGREEN) draw_fps(get_screen_width() - 95, 10) end_drawing() diff --git a/examples/core/core_vr_simulator.py b/examples/core/core_vr_simulator.py index f8cc6be..59a4a61 100644 --- a/examples/core/core_vr_simulator.py +++ b/examples/core/core_vr_simulator.py @@ -1,4 +1,6 @@ import pyray +import raylib + GLSL_VERSION = 330 # Initialization @@ -30,18 +32,18 @@ device = pyray.VrDeviceInfo( config = pyray.load_vr_stereo_config(device) # Distortion shader (uses device lens distortion and chroma) -distortion = pyray.load_shader(0, f"resources/distortion{GLSL_VERSION}.fs") +distortion = pyray.load_shader(pyray.ffi.NULL, f"resources/distortion{GLSL_VERSION}.fs") # Update distortion shader with lens and distortion-scale parameters -pyray.set_shader_value(distortion, 2,"leftLensCenter", pyray.SHADER_UNIFORM_VEC2) -pyray.set_shader_value(distortion, 2,"rightLensCenter", pyray.SHADER_UNIFORM_VEC2) -pyray.set_shader_value(distortion, 2,"leftScreenCenter", pyray.SHADER_UNIFORM_VEC2) -pyray.set_shader_value(distortion, 2,"rightScreenCenter", pyray.SHADER_UNIFORM_VEC2) +pyray.set_shader_value(distortion, 2, pyray.ffi.new('char []', b"leftLensCenter"), pyray.SHADER_UNIFORM_VEC2) +pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"rightLensCenter"), pyray.SHADER_UNIFORM_VEC2) +pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"leftScreenCenter"), pyray.SHADER_UNIFORM_VEC2) +pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"rightScreenCenter"), pyray.SHADER_UNIFORM_VEC2) -pyray.set_shader_value(distortion, 2,"scale", pyray.SHADER_UNIFORM_VEC2) -pyray.set_shader_value(distortion, 2,"scaleIn", pyray.SHADER_UNIFORM_VEC2) -pyray.set_shader_value(distortion, 4,"deviceWarpParam", pyray.SHADER_UNIFORM_VEC4) -pyray.set_shader_value(distortion, 4,"chromaAbParam", pyray.SHADER_UNIFORM_VEC4) +pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"scale"), pyray.SHADER_UNIFORM_VEC2) +pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"scaleIn"), pyray.SHADER_UNIFORM_VEC2) +pyray.set_shader_value(distortion, 4,pyray.ffi.new('char []', b"deviceWarpParam"), pyray.SHADER_UNIFORM_VEC4) +pyray.set_shader_value(distortion, 4,pyray.ffi.new('char []', b"chromaAbParam"), pyray.SHADER_UNIFORM_VEC4) # Initialize framebuffer for stereo rendering # NOTE: Screen size should match HMD aspect ratio diff --git a/examples/textures/textures_opencv.py b/examples/extra/textures_opencv.py similarity index 100% rename from examples/textures/textures_opencv.py rename to examples/extra/textures_opencv.py diff --git a/examples/models/models_animation.py b/examples/models/models_animation.py index 87e2480..9cd5710 100644 --- a/examples/models/models_animation.py +++ b/examples/models/models_animation.py @@ -22,7 +22,7 @@ ray.set_material_texture(model.materials, ray.MATERIAL_MAP_ALBEDO, texture) position = ( 0., 0., 0. ) # Set model position # Load animation data -count = ray.ffi.new("unsigned int *", 1) +count = ray.ffi.new("int *", 1) anims = ray.load_model_animations("resources/models/iqm/guyanim.iqm", count) anim_frame_counter = 0 @@ -55,7 +55,7 @@ while not ray.window_should_close(): # Detect window close button or ESC ray.draw_model_ex(model, position, ray.Vector3( 1.0, 0.0, 0.0 ), -90.0, ray.Vector3( 1.0, 1.0, 1.0 ), ray.WHITE) for i in range(model.boneCount): - ray.draw_cube(anims[0].framePoses[anim_frame_counter][i].translation, 0.2, 0.2, 0.2, ray.RED) + ray.draw_cube(anims.framePoses[anim_frame_counter][i].translation, 0.2, 0.2, 0.2, ray.RED) ray.draw_grid(10, 1.0) # Draw a grid @@ -75,8 +75,8 @@ while not ray.window_should_close(): # Detect window close button or ESC ray.unload_texture(texture) # Unload texture # Unload model animations data -for anim in anims: - ray.unload_model_animation(anim) +for i in range(count[0]): + ray.unload_model_animation(anims[i]) ray.unload_model(model) # Unload model diff --git a/examples/models/models_skybox.py b/examples/models/models_skybox_outdated_needs_update.py similarity index 78% rename from examples/models/models_skybox.py rename to examples/models/models_skybox_outdated_needs_update.py index 633cc40..a3dc441 100644 --- a/examples/models/models_skybox.py +++ b/examples/models/models_skybox_outdated_needs_update.py @@ -1,4 +1,4 @@ -from raylib.dynamic import raylib as rl, ffi +import raylib as rl from raylib.colors import * screenWidth = 1260 @@ -6,7 +6,7 @@ screenHeight = 768 rl.InitWindow(screenWidth, screenHeight, b'Skymap Demo') -camera = ffi.new('struct Camera3D *', [[1, 1, 1], [4, 1, 4], [0, 1, 0], 70, 0]) +camera = rl.ffi.new('struct Camera3D *', [[1, 1, 1], [4, 1, 4], [0, 1, 0], 70, 0]) cube = rl.GenMeshCube(100, 100, 100) skybox = rl.LoadModelFromMesh(cube) @@ -19,8 +19,8 @@ skybox.materials[0].shader = rl.LoadShader( rl.SetShaderValue( skybox.materials[0].shader, rl.GetShaderLocation(skybox.materials[0].shader, b"environmentMap"), - ffi.new('int[]', [rl.MAP_CUBEMAP]), - rl.UNIFORM_INT + rl.ffi.new('int[]', [rl.MATERIAL_MAP_CUBEMAP]), + rl.RL_SHADER_UNIFORM_INT ) shdrCubemap = rl.LoadShader( @@ -31,13 +31,15 @@ shdrCubemap = rl.LoadShader( rl.SetShaderValue( shdrCubemap, rl.GetShaderLocation(shdrCubemap, b'equirectangularMap'), - ffi.new('int[]', [0]), - rl.UNIFORM_INT + rl.ffi.new('int[]', [0]), + rl.SHADER_UNIFORM_INT ) texHDR = rl.LoadTexture(b'resources/dresden_square.hdr') -skybox.materials[0].maps[rl.MAP_CUBEMAP].texture = rl.GenTextureCubemap(shdrCubemap, texHDR, 512, rl.UNCOMPRESSED_R32G32B32); +# THIS FUNCTION NO LONGER EXISTS, will require porting a lot of C code from the C example to replace it +skybox.materials[0].maps[rl.MAP_CUBEMAP].texture = rl.GenTextureCubemap(shdrCubemap, texHDR, 512, rl.UNCOMPRESSED_R32G32B32) + rl.UnloadTexture(texHDR) rl.UnloadShader(shdrCubemap) diff --git a/examples/shapes/shapes_draw_rounded_rectangle.py b/examples/shapes/shapes_draw_rounded_rectangle_incomplete.py similarity index 62% rename from examples/shapes/shapes_draw_rounded_rectangle.py rename to examples/shapes/shapes_draw_rounded_rectangle_incomplete.py index ab948c8..078b083 100644 --- a/examples/shapes/shapes_draw_rounded_rectangle.py +++ b/examples/shapes/shapes_draw_rounded_rectangle_incomplete.py @@ -20,32 +20,31 @@ from raylib.colors import ( MAROON, ) -#// Initialization -#//-------------------------------------------------------------------------------------- + SCREEN_WIDTH = 800 SCREEN_HEIGHT = 450 pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [shapes] example - draw rectangle rounded") -roundness = 0.2 -width = 200 -height = 100 -segments = 0 -lineThick = 1 + drawRect = False drawRoundedRect = True drawRoundedLines = False -pyray.set_target_fps(60) #// Set our game to run at 60 frames-per-second -#//-------------------------------------------------------------------------------------- - +pyray.set_target_fps(60) +width = pyray.ffi.new('float *', 200) +# these need to be changed to pointers for new raygui format +roundness = 0.2 +height = 100 +segments = 0 +lineThick = 1 #// Main game loop while not pyray.window_should_close(): #// Detect window close button or ESC key #// Update #//---------------------------------------------------------------------------------- - rec = pyray.Rectangle( (pyray.get_screen_width()-width-250)/2, (pyray.get_screen_height()-height)/2, width, height ) + rec = pyray.Rectangle( (pyray.get_screen_width()-width[0]-250)/2, (pyray.get_screen_height()-height)/2, width[0], height ) #//---------------------------------------------------------------------------------- #// Draw @@ -65,18 +64,22 @@ while not pyray.window_should_close(): #// Detect window close button or ESC ke #// Draw GUI controls #//------------------------------------------------------------------------------ - width = int( pyray.gui_slider_bar(pyray.Rectangle(640,40,105,20),"Width",0,width,0,pyray.get_screen_width()-300) ) - height = int( pyray.gui_slider_bar(pyray.Rectangle(640,70,105,20),"Height",0,height,0,pyray.get_screen_height()-50) ) - roundness = pyray.gui_slider_bar(pyray.Rectangle(640,140,105,20),"Roundness",0,roundness,0,1) - lineThick = int( pyray.gui_slider_bar(pyray.Rectangle(640,170,105,20),"Thickness",0,lineThick,0,20) ) - segments = int( pyray.gui_slider_bar(pyray.Rectangle(640,240,105,20),"Segments",0,segments,0,60) ) - - drawRoundedRect = pyray.gui_check_box(pyray.Rectangle(640,320,20,20),"DrawRoundedRect",drawRoundedRect) - drawRoundedLines = pyray.gui_check_box(pyray.Rectangle(640,350,20,20),"DrawRoundedLines",drawRoundedLines) - drawRect = pyray.gui_check_box(pyray.Rectangle(640,380,20,20),"DrawRect",drawRect) + + pyray.gui_slider_bar(pyray.Rectangle(640,40,105,20),"Width","",width,0,pyray.get_screen_width()-300) + + # these need to be updated to new raygui format like above like + + # height = int( pyray.gui_slider_bar(pyray.Rectangle(640,70,105,20),"Height",0,height,0,pyray.get_screen_height()-50) ) + # roundness = pyray.gui_slider_bar(pyray.Rectangle(640,140,105,20),"Roundness",0,roundness,0,1) + # lineThick = int( pyray.gui_slider_bar(pyray.Rectangle(640,170,105,20),"Thickness",0,lineThick,0,20) ) + # segments = int( pyray.gui_slider_bar(pyray.Rectangle(640,240,105,20),"Segments",0,segments,0,60) ) + # + # drawRoundedRect = pyray.gui_check_box(pyray.Rectangle(640,320,20,20),"DrawRoundedRect",drawRoundedRect) + # drawRoundedLines = pyray.gui_check_box(pyray.Rectangle(640,350,20,20),"DrawRoundedLines",drawRoundedLines) + # drawRect = pyray.gui_check_box(pyray.Rectangle(640,380,20,20),"DrawRect",drawRect) #//------------------------------------------------------------------------------ - pyray.draw_text(pyray.text_format( "MODE: %s" % "MANUAL" if segments >= 4 else "AUTO" ), 640, 280, 10, MAROON if segments >= 4 else DARKGRAY ) + pyray.draw_text( "MANUAL" if segments >= 4 else "AUTO" , 640, 280, 10, MAROON if segments >= 4 else DARKGRAY) pyray.draw_fps(10,10) pyray.end_drawing() #//------------------------------------------------------------------------------ diff --git a/tests/test_hello_world.py b/tests/test_hello_world.py index a76f275..44e86b6 100644 --- a/tests/test_hello_world.py +++ b/tests/test_hello_world.py @@ -3,7 +3,7 @@ init_window(800, 450, "Hello") while not window_should_close(): begin_drawing() clear_background(WHITE) - font = load_font_ex("/home/richard/pycharm-2022.1.4/jbr/lib/fonts/DroidSans.ttf", 30, None, 0) + font = load_font_ex("/usr/share/fonts/TTF/FiraSans-Ultra.ttf", 30, None, 0) draw_text_ex(font, "hellow font", (300, 300), 30, 0, BLACK) draw_text("Hello world", 190, 200, 20, VIOLET) end_drawing()