" />

" />

phpMedia: And shaders arrived...

phpMedia: Y llegaron los shaders...

25 Apr 2009

Ya se puede usar GLSL en phpmedia:

Ejemplo: http://phpelegante.googlepages.com/phpmedia_test_glsl.7z

error_reporting(E_ALL | E_STRICT);  

Screen::title('Shader test');  
$screen = Screen::init(800, 600);  
$key = 'Keyboard';  

$shader = new Shader("  
    uniform sampler2D image, mask;  
    uniform float step;  
    void main (void) {  
        gl_FragColor.rgb = texture2D(image, vec2(gl_TexCoord[0])).rgb;  
        gl_FragColor.a = texture2D(mask , vec2(gl_TexCoord[1])).r + step;  
    }  
");  

$mask = Bitmap::fromFile('mask.png');  
$image = Bitmap::fromFile('file.jpg');  
$arrows = Bitmap::fromFile('arrows.png');  

$v = -1.0;  

$timer = 0;  

while (!$key::pressed($key::ESC)) {  
    if ($key::down($key::LEFT )) $v -= 0.03;  
    if ($key::down($key::RIGHT)) $v += 0.03;  

    Math::clamp($v, -1.0, 1.0);  

    $screen->blit($image, 0, 0, 1, 0, 1, $shader, array('mask' => $mask, 'step' => $v));  
    $screen->blit($arrows, 16, 16, 1, 0, 0.6 + abs(cos($timer / 64)) * 0.8);  

    $timer++;  
    Screen::frame();  
}