-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtriangle.php
40 lines (32 loc) · 923 Bytes
/
triangle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
define('EXAMPLE_DIR', __DIR__);
require __DIR__ . '/../example_base.php';
use PHPR\Shader\TriangleTestShader;
use PHPR\Mesh\Vertex;
use PHPR\Math\Vec3;
$context = create_exmaple_context();
$context->bindShader(new TriangleTestShader);
// $context->setDrawMode(\PHPR\Context::DRAW_MODE_LINES);
/**
* Vertex subclass with color attribute
*/
class ExampleVertex extends Vertex
{
public static function c(float $x, float $y, float $z, float $r, float $g, float $b)
{
$v = ExampleVertex::cP($x, $y, $z);
$v->color = new Vec3($r, $g, $b);
return $v;
}
public Vec3 $color;
}
/**
* Draw the tirangle
*/
$context->drawTriangle(
// | position | color
ExampleVertex::c(-0.8, -0.8, 0.0, 1.0, 0.0, 0.0),
ExampleVertex::c( 0.8, -0.8, 0.0, 0.0, 1.0, 0.0),
ExampleVertex::c( 0.0, 0.8, 0.0, 0.0, 0.0, 1.0),
);
render_example_context($context);