X2D - eXtended 2D

Developed or developing a new product in PureBasic? Tell the world about it.
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

X2D - eXtended 2D

Post 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.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

A few sugestions:

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


Pleasssssssssssssssseeeeeeeee :P
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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 ;-)
Fred
Administrator
Administrator
Posts: 18225
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Nice lib :)
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

Fred wrote:Nice lib :)
:oops:



@All: Suggestions are welcome
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

change the bitmap to an icon file and you have transparency, in a way...
(dirty but works in some cases)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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 
SPAMINATOR NR.1
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post 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 ?
Paid up PB User !
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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???).
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

OK, version 0.7 is up and running.

New Functions are: DrawTransparentImage, CopyImageToMemory and CopyMemoryToImage

Have Fun
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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!!!
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Any chance to see anti-aliasing as option? :)
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

Blade wrote:Any chance to see anti-aliasing as option? :)
Where? What function?
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post 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...
Post Reply