From 50c2fb12e2e6d99eb942d4cce2ab865fbd7f1eb7 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 4 Oct 2021 15:56:29 +0100 Subject: [PATCH] QOL docs, colors, version number, example imports --- README.md | 15 ++++----- docs-src/pyray.rst | 35 ++++++++++---------- dynamic/raylib/__init__.py | 3 +- dynamic/raylib/version.py | 1 + dynamic/setup.py | 3 +- dynamic/version.py | 1 + raylib/__init__.py | 4 ++- raylib/build.py | 6 ++-- raylib/pyray.py | 27 +++++++++++++++ raylib/version.py | 1 + setup.py | 3 +- test_pyray.py | 68 +++++++++++++++++++------------------- version.py | 1 + 13 files changed, 102 insertions(+), 66 deletions(-) create mode 120000 dynamic/raylib/version.py create mode 120000 dynamic/version.py create mode 120000 raylib/version.py create mode 100644 version.py diff --git a/README.md b/README.md index ec8bb17..6bf01f1 100644 --- a/README.md +++ b/README.md @@ -12,20 +12,20 @@ statically link and use in non-free / proprietary / commercial projects! # Installation -We distribute a statically linked binary Raylib wheel: - python3 -m pip install raylib -Problems may be caused by out of date pip: +If it doesn't work, first make sure you have latest pip installed: python3 -m pip install --upgrade pip -Some platforms that _should_ be available: Windows 10 x64, MacOS 10.15 x64, Linux Ubuntu1804 x64. +On most platforms it should install a binary wheel (Windows 10 x64, MacOS 10.15 x64, Linux Ubuntu1804 x64). If yours isn't available then pip will attempt to build from source, in which case you will need to have Raylib development libs installed, e.g. using homebrew, apt, etc. -[If it doesn't work, build from source](BUILDING.md) +[If it doesn't work, you can build manually.](BUILDING.md) + +## Dynamic binding version There is now a separate dynamic version of this binding: @@ -36,8 +36,7 @@ There is now a separate dynamic version of this binding: # How to use -There are two different ways of using this binding. You only need to pick one method, but you -can combine two methods in one program if you want to. +There are two APIs, you can use either or both: ### If you are familiar with C coding and the Raylib C library and you want to use an exact copy of the C API @@ -63,7 +62,7 @@ Work in progress: # Performance -For fastest permformance use Pypy rather than standard python. +For fastest performance use Pypy rather than standard python. Every call to C is costly, so it's slightly faster if you use Python data structures and functions when calculating in your update loop diff --git a/docs-src/pyray.rst b/docs-src/pyray.rst index 6dfe959..3284b9b 100644 --- a/docs-src/pyray.rst +++ b/docs-src/pyray.rst @@ -22,29 +22,28 @@ The API is *still the same as Raylib*, so you should still reply on `the officia Example program: -.. code-block:: +.. code-block:: - from raylib.pyray import PyRay - from raylib.colors import * + import raylib - pyray = PyRay() + pr = raylib.PyRay() - pyray.init_window(800, 450, "Hello Pyray") - pyray.set_target_fps(60) + pr.init_window(800, 450, "Hello Pyray") + pr.set_target_fps(60) - camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0) - pyray.set_camera_mode(camera, pyray.CAMERA_ORBITAL) + camera = pr.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0) + pr.set_camera_mode(camera, pr.CAMERA_ORBITAL) - while not pyray.window_should_close(): - pyray.update_camera(camera) - pyray.begin_drawing() - pyray.clear_background(RAYWHITE) - pyray.begin_mode_3d(camera) - pyray.draw_grid(20, 1.0) - pyray.end_mode_3d() - pyray.draw_text("Hello world", 190, 200, 20, VIOLET) - pyray.end_drawing() - pyray.close_window() + while not pr.window_should_close(): + pr.update_camera(camera) + pr.begin_drawing() + pr.clear_background(pr.RAYWHITE) + pr.begin_mode_3d(camera) + pr.draw_grid(20, 1.0) + pr.end_mode_3d() + pr.draw_text("Hello world", 190, 200, 20, pr.VIOLET) + pr.end_drawing() + pr.close_window() See also https://github.com/electronstudio/raylib-python-cffi/blob/master/test_pyray.py diff --git a/dynamic/raylib/__init__.py b/dynamic/raylib/__init__.py index 71e80ea..a858bea 100644 --- a/dynamic/raylib/__init__.py +++ b/dynamic/raylib/__init__.py @@ -22,6 +22,7 @@ import itertools import os import pathlib import platform +from .version import __version__ MODULE = pathlib.Path(__file__).parent @@ -52,6 +53,6 @@ ffi.cdef(open(MODULE / "raylib_modified.h").read().replace('RLAPI ', '')) try: raylib_fname = raylib_library_path() rl = ffi.dlopen(raylib_fname) - print('LOADED DYNAMICALLY SHARED LIB "{}"'.format(raylib_fname)) + print('LOADED DYNAMICALLY SHARED LIB {} {}'.format(__version__, raylib_fname)) except Exception as e: print(e) diff --git a/dynamic/raylib/version.py b/dynamic/raylib/version.py new file mode 120000 index 0000000..b6d41e6 --- /dev/null +++ b/dynamic/raylib/version.py @@ -0,0 +1 @@ +../../version.py \ No newline at end of file diff --git a/dynamic/setup.py b/dynamic/setup.py index d1d2232..a623d01 100644 --- a/dynamic/setup.py +++ b/dynamic/setup.py @@ -1,6 +1,7 @@ import pathlib from setuptools import setup from setuptools.dist import Distribution +from version import __version__ # The directory containing this file HERE = pathlib.Path(__file__).parent @@ -12,7 +13,7 @@ README = (HERE / "README.rst").read_text() # This call to setup() does all the work setup( name="raylib_dynamic", - version="3.7.0.post6", + version=__version__, description="Python CFFI bindings for Raylib DLL version", long_description=README, long_description_content_type="text/x-rst", diff --git a/dynamic/version.py b/dynamic/version.py new file mode 120000 index 0000000..a508b60 --- /dev/null +++ b/dynamic/version.py @@ -0,0 +1 @@ +../version.py \ No newline at end of file diff --git a/raylib/__init__.py b/raylib/__init__.py index eee90b6..743b69b 100644 --- a/raylib/__init__.py +++ b/raylib/__init__.py @@ -18,5 +18,7 @@ from raylib.colors import * import cffi import sys from raylib.pyray import PyRay +from .version import __version__ + +print("RAYLIB STATIC "+__version__+" LOADED", file=sys.stderr) -print("RAYLIB STATIC LOADED", file=sys.stderr) diff --git a/raylib/build.py b/raylib/build.py index a5833b4..91e8e0e 100644 --- a/raylib/build.py +++ b/raylib/build.py @@ -15,6 +15,8 @@ # Assumes raylib, GL, etc are all already installed as system libraries. We dont distribute them. # Raylib must be installed and compiled with: cmake -DWITH_PIC=ON -DSHARED=ON -DSTATIC=ON .. +# We use /usr/local/lib/libraylib.a to ensure we link to static version + from cffi import FFI import os import platform @@ -27,7 +29,7 @@ def build_linux(): ffibuilder.cdef(open("raylib/raylib_modified.h").read().replace('RLAPI ', '')) ffibuilder.set_source("raylib._raylib_cffi", """ - #include "../../raylib/raylib.h" + #include "raylib.h" """, extra_link_args=['/usr/local/lib/libraylib.a','-lm', '-lpthread', '-lGLU', '-lGL', '-lrt', '-lm', '-ldl', '-lX11', '-lpthread'], libraries=['GL','m','pthread', 'dl', 'rt', 'X11'] @@ -55,7 +57,7 @@ def build_mac(): """ #include "../../raylib/raylib.h" // the C header of the library, supplied by us here """, - extra_link_args=['-lraylib', '-framework', 'OpenGL', '-framework', 'Cocoa', '-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework', 'CoreVideo'], + extra_link_args=['/usr/local/lib/libraylib.a', '-framework', 'OpenGL', '-framework', 'Cocoa', '-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework', 'CoreVideo'], ) if __name__ == "__main__": diff --git a/raylib/pyray.py b/raylib/pyray.py index 2eeb936..741b26f 100644 --- a/raylib/pyray.py +++ b/raylib/pyray.py @@ -21,6 +21,33 @@ class PyRay: def pointer(self, struct): return ffi.addressof(struct) + LIGHTGRAY =( 200, 200, 200, 255 ) + GRAY =( 130, 130, 130, 255 ) + DARKGRAY =( 80, 80, 80, 255 ) + YELLOW =( 253, 249, 0, 255 ) + GOLD =( 255, 203, 0, 255 ) + ORANGE =( 255, 161, 0, 255 ) + PINK =( 255, 109, 194, 255 ) + RED =( 230, 41, 55, 255 ) + MAROON =( 190, 33, 55, 255 ) + GREEN =( 0, 228, 48, 255 ) + LIME =( 0, 158, 47, 255 ) + DARKGREEN =( 0, 117, 44, 255 ) + SKYBLUE =( 102, 191, 255, 255 ) + BLUE =( 0, 121, 241, 255 ) + DARKBLUE =( 0, 82, 172, 255 ) + PURPLE =( 200, 122, 255, 255 ) + VIOLET =( 135, 60, 190, 255 ) + DARKPURPLE =( 112, 31, 126, 255 ) + BEIGE =( 211, 176, 131, 255 ) + BROWN =( 127, 106, 79, 255 ) + DARKBROWN =( 76, 63, 47, 255 ) + WHITE =( 255, 255, 255, 255 ) + BLACK =( 0, 0, 0, 255 ) + BLANK =( 0, 0, 0, 0 ) + MAGENTA =( 255, 0, 255, 255 ) + RAYWHITE =( 245, 245, 245, 255 ) + def makefunc(a): #print("makefunc ",a, ffi.typeof(a).args) diff --git a/raylib/version.py b/raylib/version.py new file mode 120000 index 0000000..a508b60 --- /dev/null +++ b/raylib/version.py @@ -0,0 +1 @@ +../version.py \ No newline at end of file diff --git a/setup.py b/setup.py index ed3abca..c448e8d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ import pathlib from setuptools import setup from setuptools.dist import Distribution +from version import __version__ # The directory containing this file HERE = pathlib.Path(__file__).parent @@ -16,7 +17,7 @@ class BinaryDistribution(Distribution): # This call to setup() does all the work setup( name="raylib", - version="3.7.0.post6", + version=__version__, description="Python CFFI bindings for Raylib", long_description=README, long_description_content_type="text/markdown", diff --git a/test_pyray.py b/test_pyray.py index ba49841..279496c 100644 --- a/test_pyray.py +++ b/test_pyray.py @@ -2,47 +2,47 @@ This shows how to use the Pyray wrapper around the static binding. """ -from raylib.pyray import PyRay -from raylib.colors import * +import raylib -pyray = PyRay() -pyray.init_window(800, 450, "Raylib texture test") -pyray.set_target_fps(60) +pr = raylib.PyRay() -image = pyray.gen_image_color(800, 400, (0,0,0,255) ) -texture = pyray.load_texture_from_image(image) -pyray.update_texture(texture, image.data) +pr.init_window(800, 450, "Raylib texture test") +pr.set_target_fps(60) -camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0) -image = pyray.load_image("examples/models/resources/heightmap.png") -texture = pyray.load_texture_from_image(image) -mesh = pyray.gen_mesh_heightmap(image, (16, 8, 16)) -model = pyray.load_model_from_mesh(mesh) -model.materials.maps[pyray.MATERIAL_MAP_DIFFUSE].texture = texture +image = pr.gen_image_color(800, 400, (0,0,0,255) ) +texture = pr.load_texture_from_image(image) +pr.update_texture(texture, image.data) -pyray.unload_image(image) -pyray.set_camera_mode(camera, pyray.CAMERA_ORBITAL) +camera = pr.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0) +image = pr.load_image("examples/models/resources/heightmap.png") +texture = pr.load_texture_from_image(image) +mesh = pr.gen_mesh_heightmap(image, (16, 8, 16)) +model = pr.load_model_from_mesh(mesh) +model.materials.maps[pr.MATERIAL_MAP_DIFFUSE].texture = texture -pos = pyray.get_mouse_position() -ray = pyray.get_mouse_ray(pos, camera) -rayhit = pyray.get_collision_ray_ground(ray, 0) +pr.unload_image(image) +pr.set_camera_mode(camera, pr.CAMERA_ORBITAL) + +pos = pr.get_mouse_position() +ray = pr.get_mouse_ray(pos, camera) +rayhit = pr.get_collision_ray_ground(ray, 0) print(str(rayhit.position.x)) -while not pyray.window_should_close(): - pyray.update_camera(camera) - pyray.begin_drawing() - pyray.clear_background(RAYWHITE) - pyray.begin_mode_3d(camera) - pyray.draw_model(model, (-8.0, 0.0, -8.0), 1.0, RED) - pyray.draw_grid(20, 1.0) - pyray.end_mode_3d() - pyray.draw_text("This mesh should be textured", 190, 200, 20, VIOLET) - pyray.end_drawing() +while not pr.window_should_close(): + pr.update_camera(camera) + pr.begin_drawing() + pr.clear_background(pr.RAYWHITE) + pr.begin_mode_3d(camera) + pr.draw_model(model, (-8.0, 0.0, -8.0), 1.0, pr.RED) + pr.draw_grid(20, 1.0) + pr.end_mode_3d() + pr.draw_text("This mesh should be textured", 190, 200, 20, pr.VIOLET) + pr.end_drawing() - pos = pyray.get_mouse_position() - ray = pyray.get_mouse_ray(pos, camera) - rayhit = pyray.get_collision_ray_ground(ray, 0) - print(str(rayhit.position.x)) + pos = pr.get_mouse_position() + ray = pr.get_mouse_ray(pos, camera) + rayhit = pr.get_collision_ray_ground(ray, 0) + #print(str(rayhit.position.x)) -pyray.close_window() +pr.close_window() diff --git a/version.py b/version.py new file mode 100644 index 0000000..d37c29f --- /dev/null +++ b/version.py @@ -0,0 +1 @@ +__version__ = "3.7.0.post7" \ No newline at end of file