Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: zglTMemory

  1. #1

    Question zglTMemory

    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

  2. #2
    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.
    Quote 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.
    Last edited by Andru; 11-02-2011 at 09:01 PM.

  3. #3

    Unhappy

    I am trying to SingleDataFileStorage with ZenGL and probably there is something wrong in my code:

    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;

  4. #4
    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?
    Last edited by Andru; 15-02-2011 at 10:59 PM.

  5. #5

    Talking Solved!

    Yep,I forgot to include JPG unit into source code now everything works like a charm.

    Code:
    procedure Init;
      var
        mehtexture : zglPTexture;
    begin
      
       mehtexture:= SFDS_Tex_Load( 'image.jpg', 'JPG' );
      end;
    Thanks for the help!

  6. #6
    Quote Originally Posted by gintasdx
    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

  7. #7
    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.

  8. #8
    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.
    Last edited by gintasdx; 17-02-2011 at 03:56 PM.

  9. #9
    Quote Originally Posted by gintasdx
    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
    Last edited by Andru; 17-02-2011 at 07:05 PM.

  10. #10
    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)

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL