test, review and fix the shader examples. https://github.com/electronstudio/raylib-python-cffi/issues/47
This commit is contained in:
parent
ff84bdf2dd
commit
218d9a18f7
7 changed files with 84 additions and 145 deletions
|
@ -1,4 +1,4 @@
|
|||
from raylib.dynamic import raylib as rl, ffi
|
||||
import raylib as rl
|
||||
|
||||
|
||||
class LightSystem:
|
||||
|
@ -11,13 +11,13 @@ class LightSystem:
|
|||
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");
|
||||
self.shader.locs[rl.SHADER_LOC_MATRIX_MODEL] = rl.GetShaderLocation(self.shader, b"matModel");
|
||||
self.shader.locs[rl.SHADER_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);
|
||||
v = rl.ffi.new("struct Vector4 *", ambient)
|
||||
rl.SetShaderValue(self.shader, self.ambientLoc, v, rl.SHADER_UNIFORM_VEC4);
|
||||
|
||||
for light in ls:
|
||||
self.add(light)
|
||||
|
@ -29,7 +29,7 @@ class LightSystem:
|
|||
raise Exception("Too many lights")
|
||||
|
||||
def update(self, cameraPos):
|
||||
rl.SetShaderValue(self.shader, self.shader.locs[rl.LOC_VECTOR_VIEW], ffi.new("struct Vector3 *",cameraPos), rl.UNIFORM_VEC3)
|
||||
rl.SetShaderValue(self.shader, self.shader.locs[rl.SHADER_LOC_VECTOR_VIEW], rl.ffi.new("struct Vector3 *",cameraPos), rl.SHADER_UNIFORM_VEC3)
|
||||
for light in self.lights:
|
||||
light.UpdateLightValues()
|
||||
|
||||
|
@ -49,7 +49,7 @@ class Light:
|
|||
def __init__(self, type, position, target, color):
|
||||
self.enabled = True
|
||||
self.type = type
|
||||
self.position = ffi.new("struct Vector3 *",position)
|
||||
self.position = rl.ffi.new("struct Vector3 *",position)
|
||||
self.target = target
|
||||
self.color = color
|
||||
|
||||
|
@ -80,20 +80,20 @@ class Light:
|
|||
#// NOTE: Light shader locations should be available
|
||||
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)
|
||||
rl.SetShaderValue(self.shader, self.enabledLoc, rl.ffi.new("int *",self.enabled), rl.SHADER_UNIFORM_INT)
|
||||
rl.SetShaderValue(self.shader, self.typeLoc, rl.ffi.new("int *",self.type), rl.SHADER_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)
|
||||
rl.SetShaderValue(self.shader, self.posLoc, rl.ffi.new("struct Vector3 *",position), rl.SHADER_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)
|
||||
rl.SetShaderValue(self.shader, self.targetLoc, rl.ffi.new("struct Vector3 *",target), rl.SHADER_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)
|
||||
rl.SetShaderValue(self.shader, self.colorLoc, rl.ffi.new("struct Vector4 *",color), rl.SHADER_UNIFORM_VEC4)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
# just a few functions from raymath
|
||||
#from raylib.dynamic import raylib as rl, ffi
|
||||
from raylib import rl, ffi
|
||||
|
||||
import raylib as rl
|
||||
import math
|
||||
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
#=======
|
||||
#>>>>>>> 2e2e575 (added shaders custom uniform)
|
||||
#=======
|
||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
||||
|
||||
PI = 3.14159265358979323846
|
||||
DEG2RAD = (PI/180.0)
|
||||
RAD2DEG = (180.0/PI)
|
||||
|
@ -27,16 +21,9 @@ def Lerp(start: float, end: float, amount: float):
|
|||
def Vector2Zero():
|
||||
return ffi.new("struct Vector2 *",[ 0, 0])
|
||||
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
#=======
|
||||
#>>>>>>> ffe4403 (complete fog example)
|
||||
#=======
|
||||
#>>>>>>> 2e2e575 (added shaders custom uniform)
|
||||
#=======
|
||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
||||
|
||||
def Vector3Zero():
|
||||
return ffi.new("struct Vector3 *",[ 0, 0, 0])
|
||||
return rl.ffi.new("struct Vector3 *",[ 0, 0, 0])
|
||||
|
||||
def MatrixRotateX(angle):
|
||||
result = MatrixIdentity();
|
||||
|
@ -68,7 +55,7 @@ def MatrixRotateY(angle):
|
|||
|
||||
|
||||
def MatrixIdentity():
|
||||
result = ffi.new("struct Matrix *",[ 1.0, 0.0, 0.0, 0.0,0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ])
|
||||
result = rl.ffi.new("struct Matrix *",[ 1.0, 0.0, 0.0, 0.0,0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ])
|
||||
return result
|
||||
|
||||
|
||||
|
@ -88,7 +75,7 @@ def MatrixRotateZ(angle):
|
|||
|
||||
|
||||
def MatrixMultiply(left, right):
|
||||
result = ffi.new("struct Matrix *")
|
||||
result = rl.ffi.new("struct Matrix *")
|
||||
result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
|
||||
result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
|
||||
result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
|
||||
|
|
|
@ -27,19 +27,10 @@
|
|||
# *
|
||||
# ********************************************************************************************/
|
||||
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
from raylib import rl, ffi
|
||||
#=======
|
||||
#from raylib.dynamic import raylib as rl, ffi
|
||||
#>>>>>>> ffe4403 (complete fog example)
|
||||
#=======
|
||||
#from raylib.static import rl, ffi
|
||||
#>>>>>>> 10b63b9 (added shaders_texture_waves.py)
|
||||
#=======
|
||||
#from raylib.static import rl, ffi
|
||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
||||
|
||||
import raylib as rl
|
||||
|
||||
|
||||
from raylib.colors import *
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
@ -60,7 +51,7 @@ screenHeight = 720;
|
|||
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 *', [
|
||||
camera = rl.ffi.new('struct Camera3D *', [
|
||||
[2, 2, 6],
|
||||
[0, .5, 0],
|
||||
[0, 1, 0],
|
||||
|
@ -77,9 +68,9 @@ modelC = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))
|
|||
texture = rl.LoadTexture(b"resources/texel_checker.png")
|
||||
|
||||
#// Assign texture to default model material
|
||||
modelA.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
||||
modelB.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
||||
modelC.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
||||
modelA.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||
modelB.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||
modelC.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||
|
||||
angle = 6.282;
|
||||
|
||||
|
@ -137,8 +128,8 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
|||
#// Rotate the torus
|
||||
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0]
|
||||
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0]
|
||||
modelA.transform = ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)))[0]
|
||||
modelA.transform = ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)))[0]
|
||||
modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)))[0]
|
||||
modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)))[0]
|
||||
|
||||
if (rl.IsKeyPressed(rl.KEY_F)):
|
||||
rl.ToggleFullscreen()
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
|
||||
#=======
|
||||
# /*******************************************************************************************
|
||||
# *
|
||||
# * raylib [shaders] example - basic lighting
|
||||
# * raylib [shaders] example - custom uniform
|
||||
# *
|
||||
# * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||
# * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
||||
|
@ -30,12 +25,9 @@
|
|||
# *
|
||||
# *
|
||||
# ********************************************************************************************/
|
||||
#>>>>>>> 2e2e575 (added shaders custom uniform)
|
||||
#=======#
|
||||
#
|
||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
||||
|
||||
from raylib.dynamic import raylib as rl, ffi
|
||||
|
||||
import raylib as rl
|
||||
from raylib.colors import *
|
||||
import math
|
||||
|
||||
|
@ -49,9 +41,9 @@ 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")
|
||||
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - custom uniform")
|
||||
|
||||
camera = ffi.new('struct Camera3D *', [
|
||||
camera = rl.ffi.new('struct Camera3D *', [
|
||||
[2, 12, 6],
|
||||
[0, .5, 0],
|
||||
[0, 1, 0],
|
||||
|
@ -63,7 +55,7 @@ model = rl.LoadModel(b"resources/models/barracks.obj") # // Loa
|
|||
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
|
||||
model.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].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")
|
||||
|
@ -71,7 +63,7 @@ angle = 6.282;
|
|||
|
||||
|
||||
|
||||
swirl = ffi.new("struct Vector2 *", [0,0])
|
||||
swirl = rl.ffi.new("struct Vector2 *", [0,0])
|
||||
|
||||
target = rl.LoadRenderTexture(screenWidth, screenHeight)
|
||||
|
||||
|
@ -90,7 +82,7 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
|||
|
||||
swirl.x = rl.GetMouseX()
|
||||
swirl.y = screenHeight - rl.GetMouseY()
|
||||
rl.SetShaderValue(shader, swirlCenterLoc, swirl, rl.UNIFORM_VEC2);
|
||||
rl.SetShaderValue(shader, swirlCenterLoc, swirl, rl.SHADER_UNIFORM_VEC2);
|
||||
#//----------------------------------------------------------------------------------
|
||||
|
||||
#// Draw
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
|
||||
Example converted to Python from:
|
||||
|
@ -8,20 +7,9 @@ http://bedroomcoders.co.uk/raylib-fog/
|
|||
|
||||
|
||||
"""
|
||||
#
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
from raylib import rl, ffi
|
||||
#=======
|
||||
#from raylib.dynamic import raylib as rl, ffi
|
||||
#>>>>>>> ffe4403 (complete fog example)
|
||||
#=======
|
||||
#from raylib.static import rl, ffi
|
||||
#>>>>>>> 10b63b9 (added shaders_texture_waves.py)
|
||||
#=======
|
||||
#from raylib.static import rl, ffi
|
||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
||||
|
||||
import raylib as rl
|
||||
|
||||
from raylib.colors import *
|
||||
import math
|
||||
|
||||
|
@ -31,7 +19,7 @@ from light_system import *
|
|||
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE)
|
||||
rl.InitWindow(1280, 768, b'Fog Test')
|
||||
|
||||
camera = ffi.new('struct Camera3D *', [
|
||||
camera = rl.ffi.new('struct Camera3D *', [
|
||||
[6, 2, 6],
|
||||
[0, .5, 0],
|
||||
[0, 1, 0],
|
||||
|
@ -45,26 +33,20 @@ 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
|
||||
model.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||
model2.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||
model3.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||
|
||||
light = Light(LIGHT_POINT, [ 0, 4, 0 ], Vector3Zero(), WHITE)
|
||||
lightSystem = LightSystem([ 0.2, 0.2, 0.2, 1.0 ], light)
|
||||
#
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
fog_color = ffi.new('float[]', [0.2,0.2,1.0,1.0])
|
||||
|
||||
fog_color = rl.ffi.new('float[]', [0.2,0.2,1.0,1.0])
|
||||
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
|
||||
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.UNIFORM_VEC4);
|
||||
#=======
|
||||
#fog_color = [0.2, 0.2, 1.0, 1.0]
|
||||
#>>>>>>> ffe4403 (complete fog example)
|
||||
#=======
|
||||
#fog_color = ffi.new('float[]', [0.2,0.2,1.0,1.0])
|
||||
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.SHADER_UNIFORM_VEC4);
|
||||
|
||||
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
|
||||
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.UNIFORM_VEC4);
|
||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
||||
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.SHADER_UNIFORM_VEC4);
|
||||
|
||||
fogD = rl.GetShaderLocation(lightSystem.shader, b'FogDensity')
|
||||
fogDensity = 0.12
|
||||
|
||||
|
@ -84,8 +66,8 @@ while not rl.WindowShouldClose():
|
|||
lightSystem.update(camera.position)
|
||||
|
||||
|
||||
model.transform = ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[0]
|
||||
model.transform = ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
|
||||
model.transform = rl.ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[0]
|
||||
model.transform = rl.ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
|
||||
|
||||
if rl.IsKeyDown(rl.KEY_UP):
|
||||
fogDensity = min(fogDensity + 0.001, 1)
|
||||
|
@ -93,21 +75,15 @@ while not rl.WindowShouldClose():
|
|||
if rl.IsKeyDown(rl.KEY_DOWN):
|
||||
fogDensity = max(fogDensity - 0.001, 0)
|
||||
|
||||
rl.SetShaderValue(lightSystem.shader, fogD, ffi.new('float[]', [fogDensity]), rl.UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(lightSystem.shader, fogD, rl.ffi.new('float[]', [fogDensity]), rl.SHADER_UNIFORM_FLOAT)
|
||||
|
||||
rl.BeginDrawing()
|
||||
|
||||
rl.ClearBackground([int(255 * i) for i in fog_color])
|
||||
#<<<<<<< HEAD
|
||||
#<<<<<<< HEAD
|
||||
# if rl.IsKeyDown(rl.KEY_SPACE):
|
||||
# rl.ClearBackground(BLACK)
|
||||
#=======
|
||||
#>>>>>>> ffe4403 (complete fog example)
|
||||
#=======
|
||||
|
||||
if rl.IsKeyDown(rl.KEY_SPACE):
|
||||
rl.ClearBackground(BLACK)
|
||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
||||
|
||||
|
||||
rl.BeginMode3D(camera[0])
|
||||
rl.DrawModel(model, [0] * 3, 1, WHITE)
|
||||
|
@ -118,7 +94,8 @@ while not rl.WindowShouldClose():
|
|||
rl.DrawModel(model, [i, 0, 2], 1, WHITE)
|
||||
|
||||
|
||||
rl.DrawGizmo([1000, 1000, 1000])
|
||||
#Raylib removed this function
|
||||
#rl.DrawGizmo([1000, 1000, 1000])
|
||||
|
||||
rl.EndMode3D()
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
import raylib as rl
|
||||
|
||||
|
||||
from raylib.dynamic import raylib as rl, ffi
|
||||
from raylib.colors import *
|
||||
|
||||
|
||||
# a few functions ported from raymath
|
||||
from rlmath import *
|
||||
|
||||
|
||||
#// Initialization
|
||||
|
@ -17,7 +11,7 @@ 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 *', [
|
||||
camera = rl.ffi.new('struct Camera3D *', [
|
||||
[2, 12, 6],
|
||||
[0, .5, 0],
|
||||
[0, 1, 0],
|
||||
|
@ -25,16 +19,16 @@ camera = ffi.new('struct Camera3D *', [
|
|||
rl.CAMERA_PERSPECTIVE
|
||||
])
|
||||
|
||||
imBlank = rl.GenImageColor(1024, 1024, BLANK)
|
||||
imBlank = rl.GenImageColor(1024, 1024, rl.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)
|
||||
time = rl.ffi.new("float *", 0.0)
|
||||
timeLoc = rl.GetShaderLocation(shader, b"uTime");
|
||||
rl.SetShaderValue(shader, timeLoc, time, rl.UNIFORM_FLOAT);
|
||||
rl.SetShaderValue(shader, timeLoc, time, rl.SHADER_UNIFORM_FLOAT);
|
||||
|
||||
|
||||
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
||||
|
@ -45,7 +39,7 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
|||
#// Update
|
||||
#//----------------------------------------------------------------------------------
|
||||
time[0] = rl.GetTime();
|
||||
rl.SetShaderValue(shader, timeLoc, time, rl.UNIFORM_FLOAT);
|
||||
rl.SetShaderValue(shader, timeLoc, time, rl.SHADER_UNIFORM_FLOAT);
|
||||
|
||||
#//----------------------------------------------------------------------------------
|
||||
|
||||
|
@ -53,13 +47,13 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
|||
#//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing()
|
||||
|
||||
rl.ClearBackground(RAYWHITE)
|
||||
rl.ClearBackground(rl.RAYWHITE)
|
||||
|
||||
rl.BeginShaderMode(shader) #// Enable our custom shader for next shapes/textures drawings
|
||||
rl.DrawTexture(texture, 0, 0, WHITE) #// Drawing BLANK texture, all magic happens on shader
|
||||
rl.DrawTexture(texture, 0, 0, rl.WHITE) #// Drawing BLANK texture, all magic happens on shader
|
||||
rl.EndShaderMode() #// Disable our custom shader, return to default shader
|
||||
|
||||
rl.DrawText(b"BACKGROUND is PAINTED and ANIMATED on SHADER!", 10, 10, 20, MAROON);
|
||||
rl.DrawText(b"BACKGROUND is PAINTED and ANIMATED on SHADER!", 10, 10, 20, rl.MAROON);
|
||||
|
||||
|
||||
rl.EndDrawing()
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from raylib import rl, ffi
|
||||
import raylib as rl
|
||||
from raylib.colors import *
|
||||
import math
|
||||
|
||||
|
@ -17,7 +15,7 @@ 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]")
|
||||
|
||||
camera = ffi.new('struct Camera3D *', [
|
||||
camera = rl.ffi.new('struct Camera3D *', [
|
||||
[2, 12, 6],
|
||||
[0, .5, 0],
|
||||
[0, 1, 0],
|
||||
|
@ -36,24 +34,24 @@ ampYLoc = rl.GetShaderLocation(shader, b"ampY")
|
|||
speedXLoc = rl.GetShaderLocation(shader, b"speedX")
|
||||
speedYLoc = rl.GetShaderLocation(shader, b"speedY")
|
||||
|
||||
freqX = ffi.new("float *", 25.0)
|
||||
freqY = ffi.new("float *", 25.0)
|
||||
ampX = ffi.new("float *", 5.0)
|
||||
ampY = ffi.new("float *", 5.0)
|
||||
speedX = ffi.new("float *", 8.0)
|
||||
speedY = ffi.new("float *", 8.0)
|
||||
freqX = rl.ffi.new("float *", 25.0)
|
||||
freqY = rl.ffi.new("float *", 25.0)
|
||||
ampX = rl.ffi.new("float *", 5.0)
|
||||
ampY = rl.ffi.new("float *", 5.0)
|
||||
speedX = rl.ffi.new("float *", 8.0)
|
||||
speedY = rl.ffi.new("float *", 8.0)
|
||||
|
||||
screenSize = ffi.new("struct Vector2 *",[ rl.GetScreenWidth(), rl.GetScreenHeight() ])
|
||||
rl.SetShaderValue(shader, rl.GetShaderLocation(shader, b"size"), screenSize, rl.UNIFORM_VEC2)
|
||||
screenSize = rl.ffi.new("struct Vector2 *",[ rl.GetScreenWidth(), rl.GetScreenHeight() ])
|
||||
rl.SetShaderValue(shader, rl.GetShaderLocation(shader, b"size"), screenSize, rl.SHADER_UNIFORM_VEC2)
|
||||
|
||||
rl.SetShaderValue(shader, freqXLoc, freqX, rl.UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, freqYLoc, freqY, rl.UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, ampXLoc, ampX, rl.UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, ampYLoc, ampY, rl.UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, speedXLoc, speedX, rl.UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, speedYLoc, speedY, rl.UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, freqXLoc, freqX, rl.SHADER_UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, freqYLoc, freqY, rl.SHADER_UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, ampXLoc, ampX, rl.SHADER_UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, ampYLoc, ampY, rl.SHADER_UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, speedXLoc, speedX, rl.SHADER_UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, speedYLoc, speedY, rl.SHADER_UNIFORM_FLOAT)
|
||||
|
||||
seconds = ffi.new("float *", 0.0)
|
||||
seconds = rl.ffi.new("float *", 0.0)
|
||||
|
||||
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
||||
#//--------------------------------------------------------------------------------------
|
||||
|
@ -63,7 +61,7 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
|||
#// Update
|
||||
#//----------------------------------------------------------------------------------
|
||||
seconds[0] += rl.GetFrameTime()
|
||||
rl.SetShaderValue(shader, secondsLoc, seconds, rl.UNIFORM_FLOAT)
|
||||
rl.SetShaderValue(shader, secondsLoc, seconds, rl.SHADER_UNIFORM_FLOAT)
|
||||
#//----------------------------------------------------------------------------------
|
||||
|
||||
#// Draw
|
||||
|
|
Reference in a new issue