Open he426100 opened 10 months ago
This is strange, since the result of the method is converted to an SDL-compatible type https://github.com/SerafimArts/ffi-sdl-ttf/blob/master/src/Marshaller.php#L83
I can not solve the problem right away, I'll try to figure it out a little later. Thank you very much for the example code to reproduce the error.
Ah, I think I understand! In return expressions i'll should do $this->sdl->cast()
instead of $this->cast()
. Whoops)
Solved, thank you very much!
Hmm... it seems this still needs to be fixed by the library so that all return types are compatible with SDL (instead of TTF). Is not it so?
I'm sorry, I don't understand these, just modify as you said, the problem solved
Kk. I will re-open the issue so as not to lose it and correct this behavior on the part of the TTF library in next minor patch.
define('ROOT_DIR', DIR . '/..');
require ROOT_DIR . '/vendor/autoload.php';
use Serafim\SDL\SDL; use Serafim\SDL\TTF\TTF; use Serafim\SDL\Event\Type;
$sdl = new SDL(library: ROOT_DIR . '/lib/SDL2.dll'); $ttf = new TTF(sdl: $sdl, library: ROOT_DIR . '/lib/SDL2_ttf.dll');
$sdl->SDL_Init(SDL::SDL_INIT_EVERYTHING); $ttf->TTF_Init();
$window = $sdl->SDL_CreateWindow( 'An SDL2 window', SDL::SDL_WINDOWPOS_UNDEFINED, SDL::SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL::SDL_WINDOW_OPENGL );
if ($window === null) { throw new \Exception(sprintf('Could not create window: %s', $sdl->SDL_GetError())); }
$renderer = $sdl->SDL_CreateRenderer($window, -1, 0); if (!$renderer) { throw new \Exception("Can't create renderer!"); }
$font = $ttf->TTF_OpenFont(ROOT_DIR . '/font/arial.ttf', 42);
echo 'Hinting: ' . $ttf->TTF_GetFontHinting($font) . "\n"; echo 'Kerning: ' . $ttf->TTF_GetFontKerning($font) . "\n"; echo 'Style: ' . match($ttf->TTF_GetFontStyle($font)) { TTF::TTF_STYLE_NORMAL => 'normal', TTF::TTF_STYLE_BOLD => 'bold', TTF::TTF_STYLE_ITALIC => 'italic', TTF::TTF_STYLE_UNDERLINE => 'underline', TTF::TTF_STYLE_STRIKETHROUGH => 'strikethrough', } . "\n";
$color = $sdl->new('SDL_Color'); $color->r = 120; $color->g = 100; $color->b = 80;
$surface = $ttf->TTF_RenderText_Solid($font, 'Hello World!', FFI::addr($color)); $texture = $sdl->SDL_CreateTextureFromSurface($renderer, $surface);
$event = $sdl->new('SDL_Event'); $running = true;
while ($running) { $sdl->SDL_PollEvent(FFI::addr($event)); if ($event->type === Type::SDL_QUIT) { $running = false; } }
$sdl->SDL_FreeSurface($surface); $sdl->SDL_DestroyTexture($texture); $sdl->SDL_DestroyWindow($window); $ttf->TTF_Quit(); $sdl->SDL_Quit();
Hinting: 0 Kerning: 1 Style: normal
Fatal error: Uncaught FFI\Exception: Passing incompatible argument 2 of C function 'SDL_CreateTextureFromSurface', expecting 'struct SDL_Surface', found 'struct SDL_Surface' in E:\Git\ffi-sdl-test\vendor\ffi\proxy\src\ProxyAwareTrait.php:21 Stack trace:
0 E:\Git\ffi-sdl-test\vendor\ffi\proxy\src\ProxyAwareTrait.php(21): FFI->SDL_CreateTextureFromSurface(Object(FFI\CData:struct SDL_Renderer), Object(FFI\CData:struct SDL_Surface))
1 E:\Git\ffi-sdl-test\src\ttf.php(54): FFI\Proxy\Proxy->__call('SDL_CreateTextu...', Array)
2 {main}
thrown in E:\Git\ffi-sdl-test\vendor\ffi\proxy\src\ProxyAwareTrait.php on line 21