Ejemplo n.º 1
0
    def UpdateLightValues(self):
        #// Send to shader light enabled state and type
        rl.SetShaderValue(self.shader, self.enabledLoc, ffi.new("int *",self.enabled), rl.UNIFORM_INT)
        rl.SetShaderValue(self.shader, self.typeLoc, ffi.new("int *",self.type), rl.UNIFORM_INT)

        #// Send to shader light position values
        position = [ self.position.x, self.position.y, self.position.z]
        rl.SetShaderValue(self.shader, self.posLoc, ffi.new("struct Vector3 *",position), rl.UNIFORM_VEC3)

        #// Send to shader light target position values
        target =[  self.target.x, self.target.y, self.target.z ]
        rl.SetShaderValue(self.shader, self.targetLoc, ffi.new("struct Vector3 *",target), rl.UNIFORM_VEC3)

        #// Send to shader light color values
        color = [self.color[0]/255.0, self.color[1]/255.0,  self.color[2]/255.0, self.color[3]/255.0]
        rl.SetShaderValue(self.shader, self.colorLoc, ffi.new("struct Vector4 *",color), rl.UNIFORM_VEC4)
Ejemplo n.º 2
0
def get_dropped_files():
    files = []
    if rl.IsFileDropped():
        file_count = ffi.new('int *')
        files = rl.GetDroppedFiles(file_count)
        files = [ffi.string(files[i]).decode() for i in range(file_count[0])]
        rl.ClearDroppedFiles()
    return files
Ejemplo n.º 3
0
    def update_mouse(self):
        pos = rl.GetMousePosition()
        width = rl.GetScreenWidth()
        height = rl.GetScreenHeight()

        mouse_coordinates = ffi.new(
            "struct Vector2 *",
            [pos.x - self.last_mouse.x, pos.y - self.last_mouse.y])

        self.yaw += mouse_coordinates.x * self.mouse_sensitivity
        self.pitch += (mouse_coordinates.y * self.mouse_sensitivity)
        self.pitch = min(self.pitch, 1.5)
        self.pitch = max(self.pitch, -1.5)
        self.last_mouse = rl.GetMousePosition()
Ejemplo n.º 4
0
 def __init__(self, x=0, y=0, z=0, fov=70.0):
     self.last_mouse = ffi.new("struct Vector2 *", [0, 0])
     self.fov = fov
     self.yaw = -46.33
     self.pitch = 0.0
     self.front = glm.vec3()
     self.up = glm.vec3()
     self.right = glm.vec3()
     self.position = glm.vec3(x, y, z)
     self.world_up = glm.vec3(0, 1, 0)
     self.fps_facing = glm.vec3()
     self.movement_speed = 10
     self.mouse_sensitivity = 0.002
     self.last_time = rl.GetFrameTime()
Ejemplo n.º 5
0
    def __init__(self, ambient = [ 0.2, 0.2, 0.2, 1.0 ], *ls):
        self.shader = rl.LoadShader(b"resources/shaders/fogLight.vs",
                            b"resources/shaders/fogLight.fs");

        #// Get some shader loactions
        self.shader.locs[rl.LOC_MATRIX_MODEL] = rl.GetShaderLocation(self.shader, b"matModel");
        self.shader.locs[rl.LOC_VECTOR_VIEW] = rl.GetShaderLocation(self.shader, b"viewPos");

        #// ambient light level
        self.ambientLoc = rl.GetShaderLocation(self.shader, b"ambient");
        v = ffi.new("struct Vector4 *", ambient)
        rl.SetShaderValue(self.shader, self.ambientLoc, v, rl.UNIFORM_VEC4);

        for light in ls:
            self.add(light)
Ejemplo n.º 6
0
"""
This shows how to use the CFFI dynamic (ABI) binding.  Note that is slower and more likely to run into silent errors and segfaults.
But it doesnt require any C compiler to build.
"""
from raylib.dynamic import ffi, raylib as rl
from raylib.colors import *

rl.InitWindow(800, 450, b"Raylib dynamic binding test")
rl.SetTargetFPS(60)

camera = ffi.new(
    "struct Camera3D *",
    [[18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0])
image = rl.LoadImage(b"examples/models/resources/heightmap.png")
texture = rl.LoadTextureFromImage(image)
mesh = rl.GenMeshHeightmap(image, [16, 8, 16])
model = rl.LoadModelFromMesh(mesh)
print(
    model.materials
)  # SHOULD BE A pointer to a 'struct Material' but some is NULL pointer to 'Material' ?
model.materials.maps[rl.MAP_DIFFUSE].texture = texture

rl.UnloadImage(image)
rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL)

while not rl.WindowShouldClose():
    rl.UpdateCamera(camera)
    rl.BeginDrawing()
    rl.ClearBackground(RAYWHITE)
    rl.BeginMode3D(camera[0])
    rl.DrawModel(model, (-8.0, 0.0, -8.0), 1.0, RED)
Ejemplo n.º 7
0
 def __init__(self, type,  position,  target, color):
     self.enabled = True
     self.type = type
     self.position = ffi.new("struct Vector3 *",position)
     self.target = target
     self.color = color
Ejemplo n.º 8
0
 def update(self, cameraPos):
     rl.SetShaderValue(self.shader, self.shader.locs[rl.LOC_VECTOR_VIEW], ffi.new("struct Vector3 *",cameraPos), rl.UNIFORM_VEC3)
     for light in self.lights:
         light.UpdateLightValues()
Ejemplo n.º 9
0
 def get_camera(self):
     return ffi.new("struct Camera3D *", [
         self.get_ray_front(),
         self.get_ray_position(),
         self.get_ray_up(), self.fov, rl.CAMERA_PERSPECTIVE
     ])
Ejemplo n.º 10
0
from raylib.dynamic import raylib as rl, ffi
from raylib.colors import *

screenWidth = 1260
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])

cube = rl.GenMeshCube(100, 100, 100)
skybox = rl.LoadModelFromMesh(cube)

skybox.materials[0].shader = rl.LoadShader(b'resources/shaders/skybox.vs',
                                           b'resources/shaders/skybox.fs')

rl.SetShaderValue(
    skybox.materials[0].shader,
    rl.GetShaderLocation(skybox.materials[0].shader, b"environmentMap"),
    ffi.new('int[]', [rl.MAP_CUBEMAP]), rl.UNIFORM_INT)

shdrCubemap = rl.LoadShader(b'resources/shaders/cubemap.vs',
                            b'resources/shaders/cubemap.fs')

rl.SetShaderValue(shdrCubemap,
                  rl.GetShaderLocation(shdrCubemap, b'equirectangularMap'),
                  ffi.new('int[]', [0]), rl.UNIFORM_INT)

texHDR = rl.LoadTexture(b'resources/dresden_square.hdr')

skybox.materials[0].maps[rl.MAP_CUBEMAP].texture = rl.GenTextureCubemap(
Ejemplo n.º 11
0
# a few functions ported from raymath
from rlmath import *

#// Initialization
#//--------------------------------------------------------------------------------------
screenWidth = 800
screenHeight = 450

rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE)
# Enable Multi Sampling Anti Aliasing 4x (if available)
rl.InitWindow(screenWidth, screenHeight,
              b"raylib [shaders] example - basic lighting")

camera = ffi.new(
    'struct Camera3D *',
    [[2, 12, 6], [0, .5, 0], [0, 1, 0], 45, rl.CAMERA_PERSPECTIVE])

imBlank = rl.GenImageColor(1024, 1024, BLANK)
texture = rl.LoadTextureFromImage(
    imBlank)  #// Load blank texture to fill on shader
rl.UnloadImage(imBlank)

#// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
shader = rl.LoadShader(b"", b"resources/shaders/glsl330/cubes_panning.fs")

time = ffi.new("float *", 0.0)
timeLoc = rl.GetShaderLocation(shader, b"uTime")
rl.SetShaderValue(shader, timeLoc, time, rl.UNIFORM_FLOAT)

rl.SetTargetFPS(60)  # // Set our game to run at 60 frames-per-second
Ejemplo n.º 12
0
"""
Example converted to Python from:
http://bedroomcoders.co.uk/raylib-fog/
"""

from raylib.dynamic import raylib as rl, ffi
from raylib.colors import *

rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE)
rl.InitWindow(1280, 768, b'Fog Test')

camera = ffi.new('struct Camera3D *',
                 [[2, 2, 6], [0, 5, 0], [0, 1, 0], 45, rl.CAMERA_PERSPECTIVE])

model = rl.LoadModelFromMesh(rl.GenMeshTorus(0.4, 1, 16, 32))
model2 = rl.LoadModelFromMesh(rl.GenMeshCube(1, 1, 1))
model3 = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))

texture = rl.LoadTexture(b'resources/test.png')

model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
model2.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
model3.materials[0].maps[rl.MAP_DIFFUSE].texture = texture

shader = rl.LoadShader(b'resources/shaders/fogLight.vs',
                       b'resources/shaders/fogLight.fs')
shader.locs[rl.LOC_MATRIX_MODEL] = rl.GetShaderLocation(shader, b'matModel')
shader.locs[rl.LOC_VECTOR_VIEW] = rl.GetShaderLocation(shader, b'viewPos')

amb = rl.GetShaderLocation(shader, b'ambient')
rl.SetShaderValue(shader, amb, ffi.new('float[]', [0.2, 0.2, 0.2, 1.0]),
Ejemplo n.º 13
0
# a few functions ported from raymath
from rlmath import *

#// Initialization
#//--------------------------------------------------------------------------------------
screenWidth = 800
screenHeight = 450

rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE)
# Enable Multi Sampling Anti Aliasing 4x (if available)
rl.InitWindow(screenWidth, screenHeight,
              b"raylib [shaders] example - basic lighting")

camera = ffi.new(
    'struct Camera3D *',
    [[2, 12, 6], [0, .5, 0], [0, 1, 0], 45, rl.CAMERA_PERSPECTIVE])

model = rl.LoadModel(b"resources/models/barracks.obj")  # // Load OBJ model
texture = rl.LoadTexture(b"resources/models/barracks_diffuse.png"
                         )  # // Load model texture (diffuse map)

#// Assign texture to default model material
model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
#// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
shader = rl.LoadShader(b"", b"resources/shaders/glsl330/swirl.fs")
swirlCenterLoc = rl.GetShaderLocation(shader, b"center")
angle = 6.282

swirl = ffi.new("struct Vector2 *", [0, 0])