Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Glow, Blur in 2d with no opengl or d3d ? possible ?

  1. #21

    Glow, Blur in 2d with no opengl or d3d ? possible ?

    Use Bitmap.Scanline instead of Bitmap.Canvas.Pixels[ x,y ] and you'll jump alot in speed;

    The following code is to convert a Phoenix texture to a windows Bitmap showing the use of scanline:

    Code:
    Type TRGBQuadArray = Array[WORD] of TRGBQuad;
    Type PRGBQuadArray = ^TRGBQuadArray;
    Type TRGBTripleArray = Array[WORD] of TRGBTriple;
    Type PRGBTripleArray = ^TRGBTripleArray;
    
    var Line   : PRGBTripleArray;
    var X,Y    : Integer;
    var Color  : TColor4b;
    begin
      Dest.Width      := Source.Width;
      Dest.Height     := Source.Height;
      Dest.PixelFormat:= Graphics.pf24Bit;
    
      For Y:=0 to Source.Height-1 do begin
        Line:=Dest.ScanLine[Y];
        For X:=0 to Source.Width-1 do begin
          Color:= Source.Pixels[X,Y];
    
          Line[X].rgbtRed     := Color.Red  ;
          Line[X].rgbtGreen   := Color.Green;
          Line[X].rgbtBlue    := Color.Blue ;
        end;
      end;
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  2. #22

    Glow, Blur in 2d with no opengl or d3d ? possible ?

    Quote Originally Posted by Andreaz
    Use Bitmap.Scanline instead of Bitmap.Canvas.Pixels[ x,y ] and you'll jump alot in speed;

    The following code is to convert a Phoenix texture to a windows Bitmap showing the use of scanline:

    Code:
    Type TRGBQuadArray = Array[WORD] of TRGBQuad;
    Type PRGBQuadArray = ^TRGBQuadArray;
    Type TRGBTripleArray = Array[WORD] of TRGBTriple;
    Type PRGBTripleArray = ^TRGBTripleArray;
    
    var Line   : PRGBTripleArray;
    var X,Y    : Integer;
    var Color  : TColor4b;
    begin
      Dest.Width      := Source.Width;
      Dest.Height     := Source.Height;
      Dest.PixelFormat:= Graphics.pf24Bit;
    
      For Y:=0 to Source.Height-1 do begin
        Line:=Dest.ScanLine[Y];
        For X:=0 to Source.Width-1 do begin
          Color:= Source.Pixels[X,Y];
    
          Line[X].rgbtRed     := Color.Red  ;
          Line[X].rgbtGreen   := Color.Green;
          Line[X].rgbtBlue    := Color.Blue ;
        end;
      end;
    I will try =]
    From brazil (:

    Pascal pownz!

  3. #23

    Glow, Blur in 2d with no opengl or d3d ? possible ?

    Also, Cache your results wherever possible, don't regenerate glows for images you've already generated glows for.

    To speed the process up, if you have a small number of sprites, you could generate glows for all of your sprites before the game begins.. or generate and cache them as you go if you have more.

    By doing this, you, and not making your glows for every render, you'll improve your performance enormously.

    How you implement your cache system is up to you though, I could suggest something, but it might be incompatible with your game engine.

  4. #24

    Glow, Blur in 2d with no opengl or d3d ? possible ?

    Quote Originally Posted by jasonf
    Also, Cache your results wherever possible, don't regenerate glows for images you've already generated glows for.

    To speed the process up, if you have a small number of sprites, you could generate glows for all of your sprites before the game begins.. or generate and cache them as you go if you have more.

    By doing this, you, and not making your glows for every render, you'll improve your performance enormously.

    How you implement your cache system is up to you though, I could suggest something, but it might be incompatible with your game engine.
    Suggest
    From brazil (:

    Pascal pownz!

  5. #25

    Glow, Blur in 2d with no opengl or d3d ? possible ?

    Well, one way would be to use a list of some type, something which gives you access to objects contained within using a key. I use a TStringList

    Then, all you need to do is.

    1. Drawing routine wants to draw a glow for sprite named "MAN"

    2. Check GlowCache (aformentioned list), If glowsurface exists, return it.

    2.1 If glow surface does not exist, render the glow to a new surface for the sprite named "MAN" and add the glow to the cache with the key of "MAN", return it.

    3. Render the glow to the destination surface.


    From this point on, all calls for a glow for the sprite "MAN" will return a pre-generated glow.

Page 3 of 3 FirstFirst 123

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
  •