Results 1 to 10 of 11

Thread: zglTMemory

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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

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
  •