update examples

This commit is contained in:
Richard Smith 2024-07-01 14:18:55 +01:00
parent ea29d96ff9
commit 1799c58ca5
9 changed files with 51 additions and 44 deletions

View file

@ -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) draw_texture_pro(target.texture, sourceRec, destRec, origin, 0.0, WHITE)
end_mode_2d() end_mode_2d()
draw_text(text_format("Screen resolution: %ix%i", screenWidth, screenHeight), 10, 10, 20, DARKBLUE) draw_text(f"Screen resolution: {screenWidth}, {screenHeight}", 10, 10, 20, DARKBLUE)
draw_text(text_format("World resolution: %ix%i", virtualScreenWidth, virtualScreenHeight), 10, 40, 20, DARKGREEN) draw_text(f"World resolution: {virtualScreenWidth}, {virtualScreenHeight}", 10, 40, 20, DARKGREEN)
draw_fps(get_screen_width() - 95, 10) draw_fps(get_screen_width() - 95, 10)
end_drawing() end_drawing()

View file

@ -1,4 +1,6 @@
import pyray import pyray
import raylib
GLSL_VERSION = 330 GLSL_VERSION = 330
# Initialization # Initialization
@ -30,18 +32,18 @@ device = pyray.VrDeviceInfo(
config = pyray.load_vr_stereo_config(device) config = pyray.load_vr_stereo_config(device)
# Distortion shader (uses device lens distortion and chroma) # 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 # 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, pyray.ffi.new('char []', b"leftLensCenter"), pyray.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,"rightLensCenter", 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,"leftScreenCenter", 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,"rightScreenCenter", 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,pyray.ffi.new('char []', b"scale"), pyray.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,"scaleIn", 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,"deviceWarpParam", pyray.SHADER_UNIFORM_VEC4) pyray.set_shader_value(distortion, 4,pyray.ffi.new('char []', b"deviceWarpParam"), pyray.SHADER_UNIFORM_VEC4)
pyray.set_shader_value(distortion, 4,"chromaAbParam", 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 # Initialize framebuffer for stereo rendering
# NOTE: Screen size should match HMD aspect ratio # NOTE: Screen size should match HMD aspect ratio

View file

@ -22,7 +22,7 @@ ray.set_material_texture(model.materials, ray.MATERIAL_MAP_ALBEDO, texture)
position = ( 0., 0., 0. ) # Set model position position = ( 0., 0., 0. ) # Set model position
# Load animation data # 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) anims = ray.load_model_animations("resources/models/iqm/guyanim.iqm", count)
anim_frame_counter = 0 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) 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): 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 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 ray.unload_texture(texture) # Unload texture
# Unload model animations data # Unload model animations data
for anim in anims: for i in range(count[0]):
ray.unload_model_animation(anim) ray.unload_model_animation(anims[i])
ray.unload_model(model) # Unload model ray.unload_model(model) # Unload model

View file

@ -1,4 +1,4 @@
from raylib.dynamic import raylib as rl, ffi import raylib as rl
from raylib.colors import * from raylib.colors import *
screenWidth = 1260 screenWidth = 1260
@ -6,7 +6,7 @@ screenHeight = 768
rl.InitWindow(screenWidth, screenHeight, b'Skymap Demo') 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) cube = rl.GenMeshCube(100, 100, 100)
skybox = rl.LoadModelFromMesh(cube) skybox = rl.LoadModelFromMesh(cube)
@ -19,8 +19,8 @@ skybox.materials[0].shader = rl.LoadShader(
rl.SetShaderValue( rl.SetShaderValue(
skybox.materials[0].shader, skybox.materials[0].shader,
rl.GetShaderLocation(skybox.materials[0].shader, b"environmentMap"), rl.GetShaderLocation(skybox.materials[0].shader, b"environmentMap"),
ffi.new('int[]', [rl.MAP_CUBEMAP]), rl.ffi.new('int[]', [rl.MATERIAL_MAP_CUBEMAP]),
rl.UNIFORM_INT rl.RL_SHADER_UNIFORM_INT
) )
shdrCubemap = rl.LoadShader( shdrCubemap = rl.LoadShader(
@ -31,13 +31,15 @@ shdrCubemap = rl.LoadShader(
rl.SetShaderValue( rl.SetShaderValue(
shdrCubemap, shdrCubemap,
rl.GetShaderLocation(shdrCubemap, b'equirectangularMap'), rl.GetShaderLocation(shdrCubemap, b'equirectangularMap'),
ffi.new('int[]', [0]), rl.ffi.new('int[]', [0]),
rl.UNIFORM_INT rl.SHADER_UNIFORM_INT
) )
texHDR = rl.LoadTexture(b'resources/dresden_square.hdr') 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.UnloadTexture(texHDR)
rl.UnloadShader(shdrCubemap) rl.UnloadShader(shdrCubemap)

View file

@ -20,32 +20,31 @@ from raylib.colors import (
MAROON, MAROON,
) )
#// Initialization
#//--------------------------------------------------------------------------------------
SCREEN_WIDTH = 800 SCREEN_WIDTH = 800
SCREEN_HEIGHT = 450 SCREEN_HEIGHT = 450
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [shapes] example - draw rectangle rounded") 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 drawRect = False
drawRoundedRect = True drawRoundedRect = True
drawRoundedLines = False 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 #// Main game loop
while not pyray.window_should_close(): #// Detect window close button or ESC key while not pyray.window_should_close(): #// Detect window close button or ESC key
#// Update #// 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 #// Draw
@ -65,18 +64,22 @@ while not pyray.window_should_close(): #// Detect window close button or ESC ke
#// Draw GUI controls #// 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) ) pyray.gui_slider_bar(pyray.Rectangle(640,40,105,20),"Width","",width,0,pyray.get_screen_width()-300)
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) ) # these need to be updated to new raygui format like above like
segments = int( pyray.gui_slider_bar(pyray.Rectangle(640,240,105,20),"Segments",0,segments,0,60) )
# height = int( pyray.gui_slider_bar(pyray.Rectangle(640,70,105,20),"Height",0,height,0,pyray.get_screen_height()-50) )
drawRoundedRect = pyray.gui_check_box(pyray.Rectangle(640,320,20,20),"DrawRoundedRect",drawRoundedRect) # roundness = pyray.gui_slider_bar(pyray.Rectangle(640,140,105,20),"Roundness",0,roundness,0,1)
drawRoundedLines = pyray.gui_check_box(pyray.Rectangle(640,350,20,20),"DrawRoundedLines",drawRoundedLines) # lineThick = int( pyray.gui_slider_bar(pyray.Rectangle(640,170,105,20),"Thickness",0,lineThick,0,20) )
drawRect = pyray.gui_check_box(pyray.Rectangle(640,380,20,20),"DrawRect",drawRect) # 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.draw_fps(10,10)
pyray.end_drawing() pyray.end_drawing()
#//------------------------------------------------------------------------------ #//------------------------------------------------------------------------------

View file

@ -3,7 +3,7 @@ init_window(800, 450, "Hello")
while not window_should_close(): while not window_should_close():
begin_drawing() begin_drawing()
clear_background(WHITE) 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_ex(font, "hellow font", (300, 300), 30, 0, BLACK)
draw_text("Hello world", 190, 200, 20, VIOLET) draw_text("Hello world", 190, 200, 20, VIOLET)
end_drawing() end_drawing()