|
|
@ -6,7 +6,14 @@ use Cijber\GraphicsToolkit\GLFW;
|
|
|
|
use Cijber\GraphicsToolkit\Utils;
|
|
|
|
use Cijber\GraphicsToolkit\Utils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_error_handler(function($severity, $message, $file, $line) {
|
|
|
|
|
|
|
|
global $error;
|
|
|
|
|
|
|
|
$error = new RuntimeException("$severity: $message [$file($line)]");
|
|
|
|
|
|
|
|
Fiber::suspend();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
include(__DIR__ . "/../vendor/autoload.php");
|
|
|
|
include(__DIR__ . "/../vendor/autoload.php");
|
|
|
|
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
function main() {
|
|
|
|
GL::init();
|
|
|
|
GL::init();
|
|
|
|
|
|
|
|
|
|
|
@ -31,63 +38,66 @@ function main() {
|
|
|
|
$window,
|
|
|
|
$window,
|
|
|
|
function($window, $width, $height) use (&$viewportHeight, &$viewportWidth) {
|
|
|
|
function($window, $width, $height) use (&$viewportHeight, &$viewportWidth) {
|
|
|
|
echo "Size: $width x $height\n";
|
|
|
|
echo "Size: $width x $height\n";
|
|
|
|
GL::viewport(0, 0, $viewportWidth = $width, $viewportHeight = $height);
|
|
|
|
glViewport(0, 0, $viewportWidth = $width, $viewportHeight = $height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
GL::viewport(0, 0, 800, 600);
|
|
|
|
glViewport(0, 0, 800, 600);
|
|
|
|
|
|
|
|
|
|
|
|
GL::debugMessageCallback(function($source, $type, $id, $severity, $length, $message, $user) {
|
|
|
|
glDebugMessageCallback(function($source, $type, $id, $severity, $length, $message, $user) {
|
|
|
|
$message = substr($message, 0, $length);
|
|
|
|
$message = substr($message, 0, $length);
|
|
|
|
|
|
|
|
|
|
|
|
var_dump(["source" => $source, "type" => $type, "id" => $id, "severity" => $severity, "message" => $message, "gl" => GL::$lastCall]);
|
|
|
|
var_dump(["source" => $source, "type" => $type, "id" => $id, "severity" => $severity, "message" => $message, "call" => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[2]]);
|
|
|
|
}, null);
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
|
|
|
|
// GL::debugMessageCallback($callback, null);
|
|
|
|
// glDebugMessageCallback($callback, null);
|
|
|
|
|
|
|
|
|
|
|
|
GL::enable(GL::DEBUG_OUTPUT);
|
|
|
|
glEnable(GL::DEBUG_OUTPUT);
|
|
|
|
GL::enable(GL::DEBUG_OUTPUT_SYNCHRONOUS);
|
|
|
|
glEnable(GL::DEBUG_OUTPUT_SYNCHRONOUS);
|
|
|
|
GL::enable(GL::BLEND);
|
|
|
|
|
|
|
|
GL::blendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$vertexShader = GL::createShader(GL::VERTEX_SHADER);
|
|
|
|
glEnable(GL::BLEND);
|
|
|
|
$vertexShaderSource = file_get_contents(__DIR__ . "/../shaders/vertex.glsl");
|
|
|
|
|
|
|
|
|
|
|
|
// glEnable(GL::BLEND);
|
|
|
|
|
|
|
|
glBlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
|
|
GL::shaderSource($vertexShader, 1, $vertexShaderSource, null);
|
|
|
|
$vertexShader = \glCreateShader(GL::VERTEX_SHADER);
|
|
|
|
|
|
|
|
$vertexShaderSource = file_get_contents(__DIR__ . "/../shaders/vertex.glsl");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GL::shaderSource($vertexShader, [$vertexShaderSource]);
|
|
|
|
|
|
|
|
|
|
|
|
GL::compileShader($vertexShader);
|
|
|
|
glCompileShader($vertexShader);
|
|
|
|
GL::getShaderiv($vertexShader, GL::COMPILE_STATUS, $success);
|
|
|
|
glGetShaderiv($vertexShader, GL::COMPILE_STATUS, Utils::pointer($success, "int32_t"));
|
|
|
|
|
|
|
|
|
|
|
|
if ( ! $success) {
|
|
|
|
if ( ! $success->cdata) {
|
|
|
|
GL::getShaderiv($vertexShader, GL::INFO_LOG_LENGTH, $logLength);
|
|
|
|
glGetShaderiv($vertexShader, GL::INFO_LOG_LENGTH, Utils::pointer($logLength, "int32_t"));
|
|
|
|
GL::getShaderInfoLog($vertexShader, $infoLog, $logLength);
|
|
|
|
glGetShaderInfoLog($vertexShader, $logLength, Utils::null(), Utils::stringBuffer($infoLog, $logLength->cdata));
|
|
|
|
die("ERROR::SHADER::VERTEX::COMPILATION_FAILED\n\t$infoLog");
|
|
|
|
die("ERROR::SHADER::VERTEX::COMPILATION_FAILED\n\t$infoLog");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fragmentShader = GL::createShader(GL::FRAGMENT_SHADER);
|
|
|
|
$fragmentShader = glCreateShader(GL::FRAGMENT_SHADER);
|
|
|
|
$fragmentShaderSource = file_get_contents(
|
|
|
|
$fragmentShaderSource = file_get_contents(
|
|
|
|
__DIR__ . "/../shaders/fragment.glsl"
|
|
|
|
__DIR__ . "/../shaders/fragment.glsl"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
GL::shaderSource($fragmentShader, 1, $fragmentShaderSource, null);
|
|
|
|
GL::shaderSource($fragmentShader, [$fragmentShaderSource]);
|
|
|
|
GL::compileShader($fragmentShader);
|
|
|
|
glCompileShader($fragmentShader);
|
|
|
|
GL::getShaderiv($fragmentShader, GL::COMPILE_STATUS, $success);
|
|
|
|
glGetShaderiv($fragmentShader, GL::COMPILE_STATUS, FFI::addr($success));
|
|
|
|
|
|
|
|
|
|
|
|
if ( ! $success) {
|
|
|
|
if ( ! $success->cdata) {
|
|
|
|
GL::getShaderiv($fragmentShader, GL::INFO_LOG_LENGTH, $logLength);
|
|
|
|
glGetShaderiv($fragmentShader, GL::INFO_LOG_LENGTH, Utils::pointer($logLength, "int32_t"));
|
|
|
|
GL::GetShaderInfoLog($fragmentShader, $infoLog, $logLength);
|
|
|
|
glGetShaderInfoLog($fragmentShader, $logLength->cdata, Utils::pointer($result, 'int32_t'), Utils::stringBuffer($infoLog, $logLength->cdata));
|
|
|
|
die("ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n\t$infoLog");
|
|
|
|
$infoLog = FFI::string($infoLog, $result->cdata);
|
|
|
|
|
|
|
|
die("ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n\t{$infoLog}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$shaderProgram = GL::createProgram();
|
|
|
|
$shaderProgram = glCreateProgram();
|
|
|
|
GL::attachShader($shaderProgram, $vertexShader);
|
|
|
|
glAttachShader($shaderProgram, $vertexShader);
|
|
|
|
GL::attachShader($shaderProgram, $fragmentShader);
|
|
|
|
glAttachShader($shaderProgram, $fragmentShader);
|
|
|
|
GL::linkProgram($shaderProgram);
|
|
|
|
glLinkProgram($shaderProgram);
|
|
|
|
|
|
|
|
|
|
|
|
GL::deleteShader($vertexShader);
|
|
|
|
glDeleteShader($vertexShader);
|
|
|
|
GL::deleteShader($fragmentShader);
|
|
|
|
glDeleteShader($fragmentShader);
|
|
|
|
|
|
|
|
|
|
|
|
$vertices = [
|
|
|
|
$vertices = [
|
|
|
|
-0.5,
|
|
|
|
-0.5,
|
|
|
@ -102,20 +112,21 @@ function main() {
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
$float = Utils::arrayOf('float', $vertices);
|
|
|
|
$float = Utils::arrayOf('float', $vertices);
|
|
|
|
GL::genVertexArrays(1, $VAO);
|
|
|
|
glGenVertexArrays(1, Utils::pointer($VAO, 'uint32_t'));
|
|
|
|
GL::genBuffers(1, $VBO);
|
|
|
|
glGenBuffers(1, Utils::pointer($VBO, 'uint32_t'));
|
|
|
|
|
|
|
|
$VAO = $VAO->cdata;
|
|
|
|
GL::bindVertexArray($VAO);
|
|
|
|
$VBO = $VBO->cdata;
|
|
|
|
|
|
|
|
|
|
|
|
GL::bindBuffer(GL::ARRAY_BUFFER, $VBO);
|
|
|
|
glBindVertexArray($VAO);
|
|
|
|
GL::bufferData(
|
|
|
|
glBindBuffer(GL::ARRAY_BUFFER, $VBO);
|
|
|
|
|
|
|
|
glBufferData(
|
|
|
|
GL::ARRAY_BUFFER,
|
|
|
|
GL::ARRAY_BUFFER,
|
|
|
|
FFI::sizeof($float),
|
|
|
|
FFI::sizeof($float),
|
|
|
|
$float,
|
|
|
|
$float,
|
|
|
|
GL::STATIC_DRAW
|
|
|
|
GL::STATIC_DRAW
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
GL::vertexAttribPointer(
|
|
|
|
glVertexAttribPointer(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
3,
|
|
|
|
3,
|
|
|
|
GL::FLOAT,
|
|
|
|
GL::FLOAT,
|
|
|
@ -124,10 +135,10 @@ function main() {
|
|
|
|
0
|
|
|
|
0
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
GL::enableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
|
|
|
|
|
|
|
GL::bindBuffer(GL::ARRAY_BUFFER, 0);
|
|
|
|
glBindBuffer(GL::ARRAY_BUFFER, 0);
|
|
|
|
GL::bindVertexArray(0);
|
|
|
|
glBindVertexArray(0);
|
|
|
|
|
|
|
|
|
|
|
|
$textureRow = Cairo::format_stride_for_width(Cairo::FORMAT_RGB24, 400);
|
|
|
|
$textureRow = Cairo::format_stride_for_width(Cairo::FORMAT_RGB24, 400);
|
|
|
|
$textureData = FFI::new(FFI::arrayType(FFI::type("unsigned char"), [$textureRow * 400]));
|
|
|
|
$textureData = FFI::new(FFI::arrayType(FFI::type("unsigned char"), [$textureRow * 400]));
|
|
|
@ -142,65 +153,57 @@ function main() {
|
|
|
|
Cairo::fill($cairo);
|
|
|
|
Cairo::fill($cairo);
|
|
|
|
Cairo::surface_flush($surface);
|
|
|
|
Cairo::surface_flush($surface);
|
|
|
|
|
|
|
|
|
|
|
|
Gl::genTextures(1, $texture);
|
|
|
|
glGenTextures(1, Utils::pointer($texture, "uint32_t"));
|
|
|
|
GL::bindTexture(GL::TEXTURE_2D, $texture);
|
|
|
|
$texture = $texture->cdata;
|
|
|
|
|
|
|
|
glBindTexture(GL::TEXTURE_2D, $texture);
|
|
|
|
|
|
|
|
|
|
|
|
gl::texParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method)
|
|
|
|
glTexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method)
|
|
|
|
gl::texParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::REPEAT);
|
|
|
|
glTexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::REPEAT);
|
|
|
|
// set texture filtering parameters
|
|
|
|
// set texture filtering parameters
|
|
|
|
gl::texParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR);
|
|
|
|
glTexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR);
|
|
|
|
gl::texParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR);
|
|
|
|
glTexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR);
|
|
|
|
|
|
|
|
|
|
|
|
GL::texImage2D(GL::TEXTURE_2D, 0, GL::RGBA, 400, 400, 0, GL::BGRA, GL::UNSIGNED_BYTE, $textureData);
|
|
|
|
glTexImage2D(GL::TEXTURE_2D, 0, GL::RGBA, 400, 400, 0, GL::BGRA, GL::UNSIGNED_BYTE, $textureData);
|
|
|
|
|
|
|
|
|
|
|
|
$vertexShader = GL::createShader(GL::VERTEX_SHADER);
|
|
|
|
$vertexShader = glCreateShader(GL::VERTEX_SHADER);
|
|
|
|
$vertexShaderSource = file_get_contents(__DIR__ . "/../shaders/sq_vertex_shader.glsl");
|
|
|
|
$vertexShaderSource = file_get_contents(__DIR__ . "/../shaders/sq_vertex_shader.glsl");
|
|
|
|
|
|
|
|
|
|
|
|
GL::shaderSource(
|
|
|
|
GL::shaderSource($vertexShader, [$vertexShaderSource]);
|
|
|
|
$vertexShader,
|
|
|
|
|
|
|
|
1,
|
|
|
|
|
|
|
|
$vertexShaderSource,
|
|
|
|
|
|
|
|
null
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCompileShader($vertexShader);
|
|
|
|
|
|
|
|
glGetShaderiv($vertexShader, GL::COMPILE_STATUS, Utils::pointer($success, 'int32_t'));
|
|
|
|
|
|
|
|
|
|
|
|
GL::compileShader($vertexShader);
|
|
|
|
if ( ! $success->cdata) {
|
|
|
|
GL::getShaderiv($vertexShader, GL::COMPILE_STATUS, $success);
|
|
|
|
glGetShaderiv($vertexShader, GL::INFO_LOG_LENGTH, Utils::pointer($logLength, "int32_t"));
|
|
|
|
|
|
|
|
glGetShaderInfoLog($vertexShader, $logLength, Utils::null(), Utils::stringBuffer($infoLog, $logLength->cdata));
|
|
|
|
if ( ! $success) {
|
|
|
|
|
|
|
|
GL::getShaderiv($vertexShader, GL::INFO_LOG_LENGTH, $logLength);
|
|
|
|
|
|
|
|
GL::getShaderInfoLog($vertexShader, $infoLog, $logLength);
|
|
|
|
|
|
|
|
die("ERROR::SHADER::VERTEX::COMPILATION_FAILED\n\t$infoLog");
|
|
|
|
die("ERROR::SHADER::VERTEX::COMPILATION_FAILED\n\t$infoLog");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fragmentShader = GL::createShader(GL::FRAGMENT_SHADER);
|
|
|
|
$fragmentShader = glCreateShader(GL::FRAGMENT_SHADER);
|
|
|
|
$fragmentShaderSource = file_get_contents(
|
|
|
|
$fragmentShaderSource = file_get_contents(
|
|
|
|
__DIR__ . "/../shaders/sq_fragment_shader.glsl"
|
|
|
|
__DIR__ . "/../shaders/sq_fragment_shader.glsl"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
GL::shaderSource(
|
|
|
|
GL::shaderSource($fragmentShader, [$fragmentShaderSource]);
|
|
|
|
$fragmentShader,
|
|
|
|
glCompileShader($fragmentShader);
|
|
|
|
1,
|
|
|
|
glGetShaderiv($fragmentShader, GL::COMPILE_STATUS, FFI::addr($success));
|
|
|
|
$fragmentShaderSource,
|
|
|
|
|
|
|
|
null
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
GL::compileShader($fragmentShader);
|
|
|
|
|
|
|
|
GL::getShaderiv($fragmentShader, GL::COMPILE_STATUS, $success);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( ! $success) {
|
|
|
|
|
|
|
|
GL::getShaderiv($fragmentShader, GL::INFO_LOG_LENGTH, $logLength);
|
|
|
|
if ( ! $success->cdata) {
|
|
|
|
GL::GetShaderInfoLog($fragmentShader, $infoLog, $logLength);
|
|
|
|
glGetShaderiv($fragmentShader, GL::INFO_LOG_LENGTH, Utils::pointer($logLength, "int32_t"));
|
|
|
|
die("ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n\t$infoLog");
|
|
|
|
glGetShaderInfoLog($fragmentShader, $logLength->cdata, Utils::pointer($result, 'int32_t'), Utils::stringBuffer($infoLog, $logLength->cdata));
|
|
|
|
|
|
|
|
$infoLog = FFI::string($infoLog, $result->cdata);
|
|
|
|
|
|
|
|
die("ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n\t{$infoLog}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$squareProgram = GL::createProgram();
|
|
|
|
$squareProgram = glCreateProgram();
|
|
|
|
GL::attachShader($squareProgram, $vertexShader);
|
|
|
|
glAttachShader($squareProgram, $vertexShader);
|
|
|
|
GL::attachShader($squareProgram, $fragmentShader);
|
|
|
|
glAttachShader($squareProgram, $fragmentShader);
|
|
|
|
GL::linkProgram($squareProgram);
|
|
|
|
glLinkProgram($squareProgram);
|
|
|
|
|
|
|
|
|
|
|
|
GL::deleteShader($vertexShader);
|
|
|
|
glDeleteShader($vertexShader);
|
|
|
|
GL::deleteShader($fragmentShader);
|
|
|
|
glDeleteShader($fragmentShader);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sq = [
|
|
|
|
$sq = [
|
|
|
@ -240,15 +243,18 @@ function main() {
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
$float = Utils::arrayOf('float', $sq);
|
|
|
|
$float = Utils::arrayOf('float', $sq);
|
|
|
|
GL::genVertexArrays(1, $SQUARE_VAO);
|
|
|
|
glGenVertexArrays(1, Utils::pointer($SQUARE_VAO, 'uint32_t'));
|
|
|
|
GL::genBuffers(1, $VBO);
|
|
|
|
$SQUARE_VAO = $SQUARE_VAO->cdata;
|
|
|
|
GL::genBuffers(1, $EBO);
|
|
|
|
glGenBuffers(1, Utils::pointer($VBO, 'uint32_t'));
|
|
|
|
|
|
|
|
$VBO = $VBO->cdata;
|
|
|
|
|
|
|
|
glGenBuffers(1, Utils::pointer($EBO, 'uint32_t'));
|
|
|
|
|
|
|
|
$EBO = $EBO->cdata;
|
|
|
|
|
|
|
|
|
|
|
|
GL::bindVertexArray($SQUARE_VAO);
|
|
|
|
glBindVertexArray($SQUARE_VAO);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GL::bindBuffer(GL::ARRAY_BUFFER, $VBO);
|
|
|
|
glBindBuffer(GL::ARRAY_BUFFER, $VBO);
|
|
|
|
GL::bufferData(
|
|
|
|
glBufferData(
|
|
|
|
GL::ARRAY_BUFFER,
|
|
|
|
GL::ARRAY_BUFFER,
|
|
|
|
FFI::sizeof($float),
|
|
|
|
FFI::sizeof($float),
|
|
|
|
$float,
|
|
|
|
$float,
|
|
|
@ -256,46 +262,48 @@ function main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$indices = Utils::arrayOf("unsigned int", [0, 1, 3, 1, 2, 3]);
|
|
|
|
$indices = Utils::arrayOf("unsigned int", [0, 1, 3, 1, 2, 3]);
|
|
|
|
GL::bindBuffer(GL::ELEMENT_ARRAY_BUFFER, $EBO);
|
|
|
|
glBindBuffer(GL::ELEMENT_ARRAY_BUFFER, $EBO);
|
|
|
|
GL::bufferData(
|
|
|
|
glBufferData(
|
|
|
|
GL::ELEMENT_ARRAY_BUFFER,
|
|
|
|
GL::ELEMENT_ARRAY_BUFFER,
|
|
|
|
FFI::sizeof($indices),
|
|
|
|
FFI::sizeof($indices),
|
|
|
|
$indices,
|
|
|
|
$indices,
|
|
|
|
GL::STATIC_DRAW,
|
|
|
|
GL::STATIC_DRAW,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
GL::vertexAttribPointer(0, 3, GL::FLOAT, false, 8 * 4, 0);
|
|
|
|
glVertexAttribPointer(0, 3, GL::FLOAT, 0, 8 * 4, 0);
|
|
|
|
GL::enableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
GL::vertexAttribPointer(1, 3, GL::FLOAT, false, 8 * 4, 3 * 4);
|
|
|
|
glVertexAttribPointer(1, 3, GL::FLOAT, 0, 8 * 4, 3 * 4);
|
|
|
|
GL::enableVertexAttribArray(1);
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
GL::vertexAttribPointer(2, 2, GL::FLOAT, false, 8 * 4, 6 * 4);
|
|
|
|
glVertexAttribPointer(2, 2, GL::FLOAT, 0, 8 * 4, 6 * 4);
|
|
|
|
GL::enableVertexAttribArray(2);
|
|
|
|
glEnableVertexAttribArray(2);
|
|
|
|
|
|
|
|
|
|
|
|
GL::useProgram($squareProgram);
|
|
|
|
glUseProgram($squareProgram);
|
|
|
|
$location = GL::getUniformLocation($squareProgram, "ourTexture");
|
|
|
|
$location = glGetUniformLocation($squareProgram, "ourTexture");
|
|
|
|
GL::uniform1i($location, 0);
|
|
|
|
glUniform1i($location, 0);
|
|
|
|
$viewportSizeLocation = GL::getUniformLocation($squareProgram, "viewportSize");
|
|
|
|
$viewportSizeLocation = glGetUniformLocation($squareProgram, "viewportSize");
|
|
|
|
|
|
|
|
|
|
|
|
while ( ! GLFW::windowShouldClose($window)) {
|
|
|
|
while ( ! GLFW::windowShouldClose($window)) {
|
|
|
|
processInput($window);
|
|
|
|
processInput($window);
|
|
|
|
|
|
|
|
|
|
|
|
GL::clearColor(0.2, 0.3, 0.3, 1.0);
|
|
|
|
glClearColor(0.2, 0.3, 0.3, 1.0);
|
|
|
|
GL::clear(GL::COLOR_BUFFER_BIT);
|
|
|
|
glClear(GL::COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glUseProgram($squareProgram);
|
|
|
|
|
|
|
|
|
|
|
|
GL::useProgram($shaderProgram);
|
|
|
|
glActiveTexture(GL::TEXTURE0);
|
|
|
|
GL::bindVertexArray($VAO);
|
|
|
|
glBindTexture(GL::TEXTURE_2D, $texture);
|
|
|
|
GL::drawArrays(GL::TRIANGLES, 0, 3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GL::activeTexture(GL::TEXTURE0);
|
|
|
|
glBindVertexArray($VAO);
|
|
|
|
GL::bindTexture(GL::TEXTURE_2D, $texture);
|
|
|
|
glDrawArrays(GL::TRIANGLES, 0, 3);
|
|
|
|
|
|
|
|
|
|
|
|
GL::useProgram($squareProgram);
|
|
|
|
glActiveTexture(GL::TEXTURE0);
|
|
|
|
GL::uniform2i($viewportSizeLocation, $viewportWidth, $viewportHeight);
|
|
|
|
glBindTexture(GL::TEXTURE_2D, $texture);
|
|
|
|
GL::bindVertexArray($SQUARE_VAO);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$f = FFI::new("long long");
|
|
|
|
glUseProgram($squareProgram);
|
|
|
|
$f->cdata = 0;
|
|
|
|
glUniform2i($viewportSizeLocation, $viewportWidth, $viewportHeight);
|
|
|
|
GL::drawElements(GL::TRIANGLES, 6, GL::UNSIGNED_INT, FFI::cast('void *', $f));
|
|
|
|
glBindVertexArray($SQUARE_VAO);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glDrawElements(GL::TRIANGLES, 6, GL::UNSIGNED_INT, 0);
|
|
|
|
|
|
|
|
|
|
|
|
GLFW::pollEvents();
|
|
|
|
GLFW::pollEvents();
|
|
|
|
GLFW::swapBuffers($window);
|
|
|
|
GLFW::swapBuffers($window);
|
|
|
@ -310,4 +318,11 @@ function processInput($window) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main();
|
|
|
|
global $error;
|
|
|
|
|
|
|
|
$error = null;
|
|
|
|
|
|
|
|
$fiber = new Fiber(fn() => main());
|
|
|
|
|
|
|
|
$fiber->start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($error !== null) {
|
|
|
|
|
|
|
|
throw $error;
|
|
|
|
|
|
|
|
}
|
|
|
|