PDA

View Full Version : zglTMemory



gintasdx
11-02-2011, 06:05 PM
I am trying to load textures from custom compressed stream format using TMemoryStream and zglTMemory,but can't get it working. I am filling the buffer with image data and provide extension 'JPG' as needed in tex_LoadFromMemory function.

Any good example of tex_LoadFromMemory would be really good :)

Andru
11-02-2011, 07:59 PM
Here the modified code of demo01.


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.



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.

gintasdx
15-02-2011, 09:05 PM
I am trying to SingleDataFileStorage (http://www.torry.net/authorsmore.php?id=5967) with ZenGL and probably there is something wrong in my code:


function SFDS_Tex_Load(FileName,Extension :string) : zglPTexture;
var
TempStream : TMemoryStream;
Reader :TSFDSFileReader;
OutStream:TStream;
OutStreamSize:Int64;
begin
TempStream := TMemoryStream.Create;
Reader := TSFDSFileReader.Create('data.sfds',0 ); //Open GPK File
OutStream := Reader.OpenStream(FileName, OutStreamSize);
TempStream.LoadFromStream(OutStream);
rama.Memory:= TempStream.Memory;
rama.Size := OutStreamSize;
rama.Position:=0;
Result := Tex_LoadFromMemory( rama, Extension);
TempStream.Free;
TempStream := nil;
OutStream.Free;
OutStream:=nil;

end;

Andru
15-02-2011, 09:54 PM
First of all try to use size value from TempStream.Size, not from OutStreamSize. If this didn't help then try to save TempStream into file(and look if this file is correct) and try to load texture from it. And just for to be sure - do you include units, which are needed to load texture with extension Extension? :)

gintasdx
16-02-2011, 01:56 PM
Yep,I forgot to include JPG unit into source code now everything works like a charm. :-[


procedure Init;
var
mehtexture : zglPTexture;
begin

mehtexture:= SFDS_Tex_Load( 'image.jpg', 'JPG' );
end;

Thanks for the help!

Andru
16-02-2011, 01:59 PM
Yep,I forgot to include JPG unit into source code now everything works like a charm.
Ehhh... seems I will rewrite all demos to use only ZenGL.dll, libZenGL.so and libZenGL.dylib, because everybody keep forgetting to include needed units... :) Or maybe I will implement showing this message - "YOU JUST FORGOT TO INCLUDE UNIT", hmm... this is an idea :)

Traveler
16-02-2011, 03:27 PM
Well, the problem (if you can call it that) is that you don't get a hint of whats causing the error(in my case anyway). If you can solve that somehow then that'd be great.
I quite like how you can choose between a dll or including the units yourself. To be honest it is one of the downsides of PyroGine, where you are forced to use the (imo bloated) dll.

gintasdx
17-02-2011, 02:42 PM
Maybe more hints in a log file would be cool. Having no DLL is great advantage since with SDL engine you need to carry 3 or 6 libraries. :)

There is one minus that when you use static linking you must release the ugly source code. Well if I am right about LGPL licence.

Andru
17-02-2011, 04:40 PM
There is one minus that when you use static linking you must release the ugly source code. Well if I am right about LGPL licence.
Yes, you are right, and this is the only thing which I "ask for" in return for a lot of my open source code :) But as author I can make an exception for someone :)

Traveler
17-02-2011, 09:43 PM
How does one use the dll anyway? I haven't seen it in the zengl archive. And when I remove the {Define static} it gives an error. (error while loading zengl)

Andru
18-02-2011, 04:27 AM
I haven't seen it in the zengl archive.
Because compilers are different(Delphi 2009+ wants 2-byte char's in type String) I dont provide dll in archive(also everyone can configure functionality of dll), you must build it by yourself. Go to src directory and open Delphi/Lazarus directory, there are project files for this IDE's. All this process is explained on google-wiki (http://code.google.com/p/zengl/wiki/en02Compilation). Then put compiled dll inside bin/i386 or bin/x86_64, and you will be able to start demos which was compiled without define STATIC.