-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
508c2d0
commit 112f1c4
Showing
14 changed files
with
342 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Linear Gradient | ||
|
||
This PHP GLFW Vector Graphics example show how to create a linear gradient and apply it to a rectangle. | ||
|
||
<figure markdown> | ||
{ width="600" } | ||
</figure> | ||
|
||
<div style="text-align: center;" markdown> | ||
[Check out the Code](https://github.com/mario-deluna/php-glfw/blob/master/examples/vg/gradient_linear.php){ .md-button .md-button--primary } | ||
</div> | ||
|
||
Run this example: | ||
|
||
``` | ||
php examples/vg/gradient_linear.php | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Radial Gradient | ||
|
||
This example demonstrates how to draw a radial gradient using the PHP GLFW Vector Graphics API. | ||
|
||
<figure markdown> | ||
{ width="600" } | ||
</figure> | ||
|
||
<div style="text-align: center;" markdown> | ||
[Check out the Code](https://github.com/mario-deluna/php-glfw/blob/master/examples/vg/gradient_radial.php){ .md-button .md-button--primary } | ||
</div> | ||
|
||
Run this example: | ||
|
||
``` | ||
php examples/vg/gradient_radial.php | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Gradient Wave | ||
|
||
This PHP GLFW Vector Graphics example shows how a gradient paint can be applied over multiple shapes. | ||
In this case we are drawing a wave of circles with a linear gradient applied to them. | ||
|
||
<figure markdown> | ||
{ width="600" } | ||
</figure> | ||
|
||
<div style="text-align: center;" markdown> | ||
[Check out the Code](https://github.com/mario-deluna/php-glfw/blob/master/examples/vg/gradient_wave.php){ .md-button .md-button--primary } | ||
</div> | ||
|
||
Run this example: | ||
|
||
``` | ||
php examples/vg/gradient_wave.php | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Text Boxes | ||
|
||
This interactive example shows how text boxes can used to render multi-line text. | ||
|
||
<figure markdown> | ||
{ width="600" } | ||
</figure> | ||
|
||
<div style="text-align: center;" markdown> | ||
[Check out the Code](https://github.com/mario-deluna/php-glfw/blob/master/examples/vg/text_boxes.php){ .md-button .md-button--primary } | ||
</div> | ||
|
||
Run this example: | ||
|
||
``` | ||
php examples/vg/text_boxes.php | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Colored Words | ||
|
||
This examples demonstrates how to render a sentence with each word having a different color. To | ||
achieve this we have to draw each word separately. | ||
|
||
<figure markdown> | ||
{ width="600" } | ||
</figure> | ||
|
||
<div style="text-align: center;" markdown> | ||
[Check out the Code](https://github.com/mario-deluna/php-glfw/blob/master/examples/vg/text_color_words.php){ .md-button .md-button--primary } | ||
</div> | ||
|
||
Run this example: | ||
|
||
``` | ||
php examples/vg/text_color_words.php | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
/** | ||
* Radial Gradient | ||
* This example demonstrates how to draw a radial gradient using the PHP GLFW Vector Graphics API. | ||
* | ||
* @category Gradients | ||
*/ | ||
/** | ||
* We utilize the example helpers here to focus on what matter in this specific example. | ||
*/ | ||
require __DIR__ . '/../99_example_helpers.php'; | ||
|
||
use GL\Math\GLM; | ||
use GL\Math\Vec2; | ||
use GL\VectorGraphics\{VGAlign, VGContext, VGColor, VGImage}; | ||
|
||
// ensure mbstring extension is loaded, we need it for the text rendering | ||
if (!extension_loaded('mbstring')) { | ||
throw new \Exception('mbstring extension is required for this example'); | ||
} | ||
|
||
$window = ExampleHelper::begin(); | ||
|
||
// initialize a vector graphics context | ||
$vg = new VGContext(VGContext::ANTIALIAS); | ||
|
||
$gradientCenter = new Vec2(300, 300); | ||
$gradientRadius = 150.0; | ||
$gradientColor1 = new VGColor(0.051, 0.682, 0.914, 1.0); | ||
$gradientColor2 = new VGColor(0.169, 0.961, 0.596, 1.0); | ||
|
||
$isDraggingCenter = false; | ||
$currentMousePos = new Vec2(0, 0); | ||
|
||
glfwSetMouseButtonCallback($window, function($button, $action, $mods) use($window, &$isDraggingCenter, $gradientCenter, $currentMousePos) { | ||
if ($button == GLFW_MOUSE_BUTTON_LEFT && $action == GLFW_PRESS) { | ||
if ($currentMousePos->distanceTo($gradientCenter) < 10) { | ||
$isDraggingCenter = true; | ||
} | ||
} else if ($button == GLFW_MOUSE_BUTTON_LEFT && $action == GLFW_RELEASE) { | ||
$isDraggingCenter = false; | ||
} | ||
}); | ||
|
||
glfwSetScrollCallback($window, function($xOffset, $yOffset) use (&$gradientRadius) { | ||
// increase or decrease the radius of the gradient | ||
$gradientRadius *= 1 + $yOffset * 0.1; | ||
$gradientRadius = min(max($gradientRadius, 10), 1000); | ||
}); | ||
|
||
// Main Loop | ||
// ---------------------------------------------------------------------------- | ||
while (!glfwWindowShouldClose($window)) | ||
{ | ||
// clear | ||
glClearColor(0, 0, 0, 1); | ||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | ||
|
||
// fetch the content scale of the window | ||
$contentScaleX; | ||
$contentScaleY; | ||
glfwGetWindowContentScale($window, $contentScaleX, $contentScaleY); | ||
|
||
// begin a new frame using the window size as the viewport size | ||
$vg->beginFrame(ExampleHelper::WIN_WIDTH, ExampleHelper::WIN_HEIGHT, $contentScaleX); | ||
|
||
$xpos = 0.0; | ||
$ypos = 0.0; | ||
glfwGetCursorPos($window, $xpos, $ypos); | ||
$currentMousePos->x = $xpos; | ||
$currentMousePos->y = $ypos; | ||
|
||
if ($isDraggingCenter) { | ||
$gradientCenter->x = $currentMousePos->x; | ||
$gradientCenter->y = $currentMousePos->y; | ||
} | ||
|
||
// create a radial gradient | ||
$gradientPaint = $vg->radialGradient( | ||
$gradientCenter->x, | ||
$gradientCenter->y, | ||
0, // inner radius | ||
$gradientRadius, // outer radius | ||
$gradientColor1, | ||
$gradientColor2 | ||
); | ||
|
||
// fill the screen with the gradient | ||
$vg->beginPath(); | ||
$vg->rect(50, 150, ExampleHelper::WIN_WIDTH - 100, ExampleHelper::WIN_HEIGHT - 300); | ||
$vg->fillPaint($gradientPaint); | ||
$vg->fill(); | ||
|
||
ExampleHelper::drawPoint($vg, $gradientCenter->x, $gradientCenter->y, 'Center('. round($gradientCenter->x) .', '. round($gradientCenter->y) .')'); | ||
|
||
ExampleHelper::drawFuncLabels($vg, 50, 50, [ | ||
"radialGradient({$gradientCenter->x}, {$gradientCenter->y}, 0, {$gradientRadius}, color1, color2)", | ||
"rect(50, 150, ". (ExampleHelper::WIN_WIDTH - 100) .", ". (ExampleHelper::WIN_HEIGHT - 300) .")", | ||
]); | ||
|
||
// end the frame will dispatch all the draw commands to the GPU | ||
$vg->endFrame(); | ||
|
||
// swap the window's framebuffer and | ||
// poll queued window events. | ||
glfwSwapBuffers($window); | ||
glfwPollEvents(); | ||
} | ||
|
||
ExampleHelper::stop($window); |
Oops, something went wrong.