Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

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

  1. #11

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

    Ready code?... Nope. But the code is very simple.

    Code:
    procedure outline( destinationpixels, sourcepixels, transparent, outlinecolour)
    
    For x = 0 to sourcewidth
    
    For y = 0 to sourceheight
    
      if sourcepixels( x,y ) = transparent and 
        &#40; sourcepixels&#40; x-1, y &#41; <> transparent or 
        sourcepixels&#40; x+1, y &#41; <> transparent or
        sourcepixels&#40; x, y-1 &#41; <> transparent or
        sourcepixels&#40; x, y+1 &#41; <> transparent &#41; then
        destinationpixels&#40; x,y &#41; = outlinecolour
      end if
    
    next y
    
    next x
    
    end procedure
    Code:
    procedure makeglow&#40; destinationpixels, sourcepixels, transparentcolour, outlinecolour , outlinedarknessfactor, outlinesteps &#41;
    
    outline&#40; destinationpixels, sourcepixels, transparent,outlinecolour &#41;
    
    
    for i = 1 to outlinesteps
    
       tempsource = copydestinationtotempdestination&#40; destinationpixels &#41;
    
       outlinecolour = outlinecolour - outlinedarknessfactor
    
       outline&#40; destinationpixels, tempsource, transparent, outlinecolour &#41;
    
    next i
    
    end procedure

    sorry, I can't write it in pascal at the moment, I don't have access to a pascal IDE.. so I've done it in Pseudocode.

  2. #12

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

    Quote Originally Posted by jasonf
    Ready code?... Nope. But the code is very simple.

    Code:
    procedure outline&#40; destinationpixels, sourcepixels, transparent, outlinecolour&#41;
    
    For x = 0 to sourcewidth
    
    For y = 0 to sourceheight
    
      if sourcepixels&#40; x,y &#41; = transparent and 
        &#40; sourcepixels&#40; x-1, y &#41; <> transparent or 
        sourcepixels&#40; x+1, y &#41; <> transparent or
        sourcepixels&#40; x, y-1 &#41; <> transparent or
        sourcepixels&#40; x, y+1 &#41; <> transparent &#41; then
        destinationpixels&#40; x,y &#41; = outlinecolour
      end if
    
    next y
    
    next x
    
    end procedure
    Code:
    procedure makeglow&#40; destinationpixels, sourcepixels, transparentcolour, outlinecolour , outlinedarknessfactor, outlinesteps &#41;
    
    outline&#40; destinationpixels, sourcepixels, transparent,outlinecolour &#41;
    
    
    for i = 1 to outlinesteps
    
       tempsource = copydestinationtotempdestination&#40; destinationpixels &#41;
    
       outlinecolour = outlinecolour - outlinedarknessfactor
    
       outline&#40; destinationpixels, tempsource, transparent, outlinecolour &#41;
    
    next i
    
    end procedure

    sorry, I can't write it in pascal at the moment, I don't have access to a pascal IDE.. so I've done it in Pseudocode.
    It looks like a MIX of Basic and Pascal
    From brazil (:

    Pascal pownz!

  3. #13

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

    well, yeah, it's a kind-of mix of both.. needless to say, it won't compile.

    Can you see what I'm trying to show you though?


    You see, writing a glow function is pretty much library dependent so I can't just write the code. You'll need access to the surface memory so you can manipulate it. Different libraries expose the underlying surface in different ways, some give an array of pixels you can use.

    If you're using the Jedi-SDL library then you're going to have a different mechanism to access the surface memory than with DelphiX.

    Once you've written a function which works for your library, you'll only want to call it whenever your main image (the one which you're generating the glow for) changes.. otherwise, you'll eat processor cycles re-generating the same glow for every frame.

  4. #14

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

    Quote Originally Posted by jasonf
    well, yeah, it's a kind-of mix of both.. needless to say, it won't compile.

    Can you see what I'm trying to show you though?


    You see, writing a glow function is pretty much library dependent so I can't just write the code. You'll need access to the surface memory so you can manipulate it. Different libraries expose the underlying surface in different ways, some give an array of pixels you can use.

    If you're using the Jedi-SDL library then you're going to have a different mechanism to access the surface memory than with DelphiX.

    Once you've written a function which works for your library, you'll only want to call it whenever your main image (the one which you're generating the glow for) changes.. otherwise, you'll eat processor cycles re-generating the same glow for every frame.
    I will try the code =)

    I will post results later.
    From brazil (:

    Pascal pownz!

  5. #15

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

    [pascal]
    function Tform1.outline( src : TBitmap ; transparentcolor , outlinecolor : TColor ): Tbitmap;
    var
    x, y: Integer;
    begin

    result:= TBitmap.Create;
    zprofiler.Mark(1,True);
    Result.Assign(src);
    zprofiler.Mark(1,False);

    for x := 1 to src.Width - 2 do
    for y := 1 to src.Height - 2 do
    begin
    if (src.Canvas.Pixels[ x,y ] = transparentcolor) and
    ( (src.Canvas.Pixels[ x-1, y ] <> transparentcolor) or
    (src.Canvas.Pixels[ x+1, y ] <> transparentcolor) or
    (src.Canvas.Pixels[ x, y-1 ] <> transparentcolor) or
    (src.Canvas.Pixels[ x, y+1 ] <> transparentcolor) ) then
    Result.Canvas.Pixels[ x,y ] := outlinecolor;
    end;
    end;

    function Tform1.makeglow(src : Tbitmap ; transparentcolor , glowcolor : TColor; outlinedarknessfactor, outlinesteps: Integer): TBitmap;
    var
    count : Integer;
    begin
    Result := TBitmap.Create;
    Result.Assign(src);
    for count:= 0 to outlinesteps-1 do
    begin
    Result := outline( Result, transparentcolor, glowcolor);
    glowcolor := glowcolor + outlinedarknessfactor; // << this is wrong i know
    end;
    end;

    procedure TForm1.Image1Click(Sender: TObject);
    begin
    image2.Picture.Bitmap:= makeglow(Image1.Picture.Bitmap, RGB(255,0,255), RGB(0,100,250), 100, 3);
    end;
    [/pascal]

    ;] it appers to have worked



    But the code is toooooo slow
    i think im making something wrong

    EDIT: Reuploaded the img cuz jpeg is a TRASH to show details
    From brazil (:

    Pascal pownz!

  6. #16

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

    Ofcourse it is slow on cpu! that's why people do such effects with graphic cards!
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  7. #17

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

    Quote Originally Posted by Delfi
    Ofcourse it is slow on cpu! that's why people do such effects with graphic cards!
    How can i make gpu do the work ?
    From brazil (:

    Pascal pownz!

  8. #18

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

    by using opengl or d3d to do the fancy rendering.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  9. #19

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

    There are some example of how to do this on Asphyre without using shaders?

  10. #20

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

    The general idea given, in the example of blurred vector/line games, was that you render to a small rendertarget, render normally, and then stretch the rendertarget over the screen with anti-aliasing on. Of course you must give it a transparency value and correct blendmode. It gives a pretty good result from what I understand.

    Without shaders that is pretty much the best you can do. At least efficiently.

Page 2 of 3 FirstFirst 123 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
  •