Here the modified code of demo01.
Code:
program demo01;
{$DEFINE STATIC}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes,
{$IFNDEF STATIC}
zglHeader
{$ELSE}
zgl_main,
zgl_screen,
zgl_window,
zgl_memory,
zgl_sprite_2d,
zgl_textures,
zgl_textures_jpg,
zgl_timers,
zgl_utils
{$ENDIF}
;
var
texture : zglPTexture;
procedure Init;
var
stream : TMemoryStream;
mem : zglTMemory;
begin
stream := TMemoryStream.Create;
stream.LoadFromFile( '../data/back01.jpg' );
mem.Memory := stream.Memory; // set pointer to file in memory
mem.Size := stream.Size; // set size
mem.Position := 0; // set initial position
texture := tex_LoadFromMemory( mem, 'JPG' );
end;
procedure Draw;
begin
ssprite2d_Draw( texture, 0, 0, 800, 600, 0 );
end;
procedure Timer;
begin
wnd_SetCaption( '01 - Initialization[ FPS: ' + u_IntToStr( zgl_Get( RENDER_FPS ) ) + ' ]' );
end;
Begin
{$IFNDEF STATIC}
zglLoad( libZenGL );
{$ENDIF}
timer_Add( @Timer, 1000 );
zgl_Reg( SYS_LOAD, @Init );
zgl_Reg( SYS_DRAW, @Draw );
// Do not use it if you use Delphi lower than 2009
zgl_Enable( APP_USE_UTF8 );
wnd_SetCaption( '01 - Initialization' );
wnd_ShowCursor( TRUE );
scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
zgl_Init();
End.
Originally Posted by
gintasdx
I am filling the buffer with image data
If you filling zglTMemory.Memory buffer, then you must allocate memory for it using zgl_GetMem. Then mem_Free will work correct.
Bookmarks