Esempio n. 1
0
def camera_test():
    rl.SetTraceLogLevel(rl.LOG_ERROR)
    rl.SetConfigFlags(rl.FLAG_WINDOW_RESIZABLE)
    rl.InitWindow(512, 256, b'Test')
    rl.SetTargetFPS(60)
    rl.DisableCursor()

    flycam = CameraFly()

    while not rl.WindowShouldClose():
        flycam.update()
        cam = flycam.get_camera()

        rl.BeginDrawing()
        rl.ClearBackground((0, 200, 255, 255))
        rl.BeginMode3D(cam[0])

        # NOTE(pebaz): For whatever reason, this can solve a percentage of artifacts
        rl.DrawGizmo([100000000, 100000000, 100000000])

        rl.DrawGrid(32, 1)

        rl.EndMode3D()
        rl.EndDrawing()

    rl.CloseWindow()
Esempio n. 2
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)
Esempio n. 3
0
python3 flow-field
        flow-field bees
"""

import sys, math, time, random
import glm
from raylib.dynamic import raylib as rl, ffi
from raylib.colors import *

CTM = lambda: round(time.time() * 1000)

BEES = bool(sys.argv[1:])

rl.SetTraceLogLevel(rl.LOG_ERROR)
rl.SetConfigFlags(rl.FLAG_WINDOW_RESIZABLE)
rl.InitWindow(512, 512, b'Friendly Bees')
rl.SetTargetFPS(60)
#rl.DisableCursor()

canvas = rl.LoadRenderTexture(rl.GetScreenWidth(), rl.GetScreenHeight())
rl.SetTextureWrap(canvas.texture, rl.WRAP_MIRROR_REPEAT)


def random_point_in_circle(center, radius):
    a = random.random() * 2 * math.pi
    r = radius * math.sqrt(random.random())
    x = r * math.cos(a)
    z = r * math.sin(a)
    return glm.vec3(x + center.x, center.y, z + center.z)

Esempio n. 4
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(
Esempio n. 5
0
#!/usr/bin/env python3

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

# 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")
Esempio n. 6
0
Vec2 = lambda p: glm.vec2(p.x, p.y)
CTM = lambda: round(time.perf_counter() * 1000)

monitors = screeninfo.get_monitors()
drag = False
offset = Vec2(rl.GetMousePosition())
width = height = 160
window_vel = glm.vec2()
window_pos = glm.vec2(monitors[0].width - width, monitors[0].height - height)

rl.SetConfigFlags(rl.FLAG_WINDOW_TRANSPARENT
                  | rl.FLAG_WINDOW_UNDECORATED
                  | rl.FLAG_VSYNC_HINT
                  | rl.FLAG_MSAA_4X_HINT)
rl.InitWindow(width, height, b'')
rl.SetWindowPosition(int(window_pos.x), int(window_pos.y))
#rl.SetTargetFPS(500)
target = rl.LoadRenderTexture(width, height)

# Top-Level Window Support Only On Windows
if sys.platform == 'win32':
    import win32gui, win32con, pywintypes

    # Set window to always top without moving it
    win32gui.SetWindowPos(
        pywintypes.HANDLE(ffi.cast('int', rl.GetWindowHandle())),
        win32con.HWND_TOPMOST, 0, 0, 0, 0,
        win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)

#tint = glm.vec4(255, 255, 255, 255) When mouse over, brighten everything fade
Esempio n. 7
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]),
Esempio n. 8
0
import toml, pprint, math, sys
from raylib.dynamic import raylib as rl, ffi
from raylib.colors import *
from haishoku.haishoku import Haishoku

TILE_SIZE = 64

colors = toml.load(open((sys.argv[1:] or ['palettes/painting.toml'])[0]))
pprint.pprint(colors)

WIDTH = 640
HEIGHT = 512

rl.SetConfigFlags(rl.FLAG_WINDOW_RESIZABLE)
rl.InitWindow(WIDTH, HEIGHT, b'Palettizer - Press E To Export Palette')
rl.SetTargetFPS(30)


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


while not rl.WindowShouldClose():
    for file in get_dropped_files():
        h = Haishoku.loadHaishoku(file)
Esempio n. 9
0
from raylib.dynamic import raylib as rl, ffi
from raylib.colors import *
from camera import CameraFly

rl.SetTraceLogLevel(rl.LOG_ERROR)
rl.SetConfigFlags(rl.FLAG_WINDOW_RESIZABLE)
rl.InitWindow(512, 256, b'Test')
rl.SetTargetFPS(60)
rl.DisableCursor()

flycam = CameraFly()


while not rl.WindowShouldClose():
    flycam.update()
    cam = flycam.get_camera()

    rl.BeginDrawing()
    rl.ClearBackground((0, 200, 255, 255))
    rl.BeginMode3D(cam[0])

    # NOTE(pebaz): For whatever reason, this can solve a percentage of artifacts
    rl.DrawGizmo([100000000, 100000000, 100000000])

    rl.DrawGrid(32, 1)

    rl.EndMode3D()
    rl.EndDrawing()

rl.CloseWindow()