Page 1 of 5

X2D - eXtended 2D

Posted: Sun Apr 04, 2004 7:44 pm
by freedimension
Here's a library for drawing additional shapes within StartDrawing...StopDrawing.

http://www.physical-touch.de/X2D.zip

Have fun.

P.S.: THX to Freak without whom this library would never have seen daylight.

Posted: Sun Apr 04, 2004 9:21 pm
by Num3
A few sugestions:

[For games]
X2D_LoadtransparentBitmap(bitmapid,transparent color)
X2D_DrawtransparentBitmap(bitmapid,x,y)


Pleasssssssssssssssseeeeeeeee :P

Posted: Sun Apr 04, 2004 10:44 pm
by freedimension
Num3 wrote:A few sugestions:

[For games]
X2D_LoadtransparentBitmap(bitmapid,transparent color)
X2D_DrawtransparentBitmap(bitmapid,x,y)


Pleasssssssssssssssseeeeeeeee :P
That's not only useful for Games. Hell, I could use it in a lot of my applications. But at the moment I have no idea how to implement that. How can I incorporate that in my lib. I don't even know if PB loads the Alpha Channel of, for example, a PNG!?
I just found out about the other GDI Stuff I used in this version of the lib. Don't expect my 'learning curve' to be that steep ;-)

Posted: Sun Apr 04, 2004 11:31 pm
by Fred
Nice lib :)

Posted: Mon Apr 05, 2004 7:59 am
by freedimension
Fred wrote:Nice lib :)
:oops:



@All: Suggestions are welcome

Posted: Mon Apr 05, 2004 8:26 am
by blueznl
change the bitmap to an icon file and you have transparency, in a way...
(dirty but works in some cases)

Posted: Tue Apr 06, 2004 1:00 am
by freedimension
New Version online. Added some new functions, including AngleText for drawing crooked text and SetHatchBrush/SetPatternBrush for filling shapes with other backgrounds than only solid colors.

Posted: Tue Apr 06, 2004 7:48 am
by Rings
Num3 wrote:A few sugestions:

[For games]
X2D_LoadtransparentBitmap(bitmapid,transparent color)
X2D_DrawtransparentBitmap(bitmapid,x,y)


Pleasssssssssssssssseeeeeeeee :P
maybe this can help (thx Danilo to post that )

Code: Select all

; 
; by Danilo, 22.04.2003 - german forum 
; 
Procedure LoadTransparentImage(Number,FileName$,TransColor,NewColor) 
  ;> 
  ;> Number     = ImageNumber 
  ;> FileName$  = File Name 
  ;> TransColor = RGB: Transparent Color,        -1 = First Color in Picture 
  ;> NewColor   = RGB: New Color for TransColor, -1 = System Window Background 
  ;> 
  Structure _LTI_BITMAPINFO 
    bmiHeader.BITMAPINFOHEADER 
    bmiColors.RGBQUAD[1] 
  EndStructure 

  Structure _LTI_LONG 
   l.l 
  EndStructure 

  hBmp = LoadImage(Number,FileName$) 
  If hBmp 
    hDC  = StartDrawing(ImageOutput()) 
    If hDC 
      ImageWidth  = ImageWidth() : ImageHeight = ImageHeight() 
      mem = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT,ImageWidth*ImageHeight*4) 
      If mem 
        bmi._LTI_BITMAPINFO 
        bmi\bmiHeader\biSize   = SizeOf(BITMAPINFOHEADER) 
        bmi\bmiheader\biWidth  = ImageWidth 
        bmi\bmiheader\biHeight = ImageHeight 
        bmi\bmiheader\biPlanes = 1 
        bmi\bmiheader\biBitCount = 32 
        bmi\bmiheader\biCompression = #BI_RGB 
        If GetDIBits_(hDC,hBmp,0,ImageHeight(),mem,bmi,#DIB_RGB_COLORS) <> 0 
          If TransColor = -1 
            *pixels._LTI_LONG = mem+((ImageHeight-1)*ImageWidth*4) 
            TransColor = *pixels\l 
          Else 
            TransColor = RGB(Blue(TransColor),Green(TransColor),Red(TransColor)) 
          EndIf 

          If NewColor = -1 
            NewColor = GetSysColor_(#COLOR_BTNFACE) ; #COLOR_WINDOW 
          EndIf 
          NewColor = RGB(Blue(NewColor),Green(NewColor),Red(NewColor)) 

          *pixels._LTI_LONG = mem 
          For a = 1 To ImageWidth*ImageHeight 
            If *pixels\l = TransColor 
              *pixels\l = NewColor 
            EndIf 
            *pixels + 4 
          Next a 

          If SetDIBits_(hDC,hBmp,0,ImageHeight(),mem,bmi,#DIB_RGB_COLORS) <> 0 
            Result = hBmp 
          EndIf 
        EndIf 
        GlobalFree_(mem) 
      EndIf 
    EndIf 
    StopDrawing() 
  EndIf 
  ProcedureReturn Result 
EndProcedure 

image1 = LoadTransparentImage(1,"d:\bilder\berthel.bmp",-1,-1) 
If image1 
  OpenWindow(0,0,0,ImageWidth(),ImageHeight(),#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"Image") 
    CreateGadgetList(WindowID()) 
    ImageGadget(0,0,0,ImageWidth(),ImageHeight(),image1) 
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
Else 
  MessageRequester("ERROR","Cant load image!",#MB_ICONERROR) 
EndIf 

Posted: Tue Apr 06, 2004 10:41 am
by dontmailme
Nice work :)

Could you link the F1 key to the help file, would be useful ;)

Also in the hello example under angle text, there is a shadow, with the text raised..... ?! How is that possible ?

Posted: Tue Apr 06, 2004 4:31 pm
by freedimension
Num3 wrote: X2D_DrawtransparentBitmap(bitmapid,x,y)
This one will come in the next version as X2D_DrawTransparentImage. It's already running here but I don't know if it's really fast enough for games. On the other hand, for games there is a working alternative: Sprites - isn't it?
Num3 wrote: X2D_LoadtransparentBitmap(bitmapid,transparent color)
But this one ... you won't need it ;-)

I also work on a way to display Images with an Alpha-Channel and SemiTransparent Images. But I can't promiss that it will work.

@dontmailme: Thx for pointing out the F1 issue. I thought this was already done :oops:

The example-image was done by simply drawing the text 2 times with slightly different angles and colors. The second with DrawingMode(1) for transparent Background.

Make sure to have called DrawingFont first, otherwise the text won't be displayed crooked (and I have no idea why - Fred???).

Posted: Tue Apr 06, 2004 6:52 pm
by freedimension
OK, version 0.7 is up and running.

New Functions are: DrawTransparentImage, CopyImageToMemory and CopyMemoryToImage

Have Fun

Posted: Tue Apr 06, 2004 8:54 pm
by Num3
Speed is not an issue in windowed games...
If you want speed full screen is a must anyway :P

Thanks for the lib!!!

Posted: Wed Apr 07, 2004 7:33 am
by Blade
Any chance to see anti-aliasing as option? :)

Posted: Wed Apr 07, 2004 9:52 am
by freedimension
Blade wrote:Any chance to see anti-aliasing as option? :)
Where? What function?

Posted: Wed Apr 07, 2004 6:54 pm
by Blade
freedimension wrote:Where? What function?
All the shapes in your lib 8)

Don't worry, I imagine that those shapes are drawn using OS calls, instead drawing with AA has to be made from scratch... doesn't seem an easy task, and the result could be very slow...