2d GUI

Advanced game related topics
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

2d GUI

Post by X »

Have anyone have any luck with creating a 2D gui for DirectX? (not for 3d but for 2d)?
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Re: 2d GUI

Post by X »

Ref: http://www.cegui.org.uk/

CEGUI looks like a good option. It does not require a 3d Engine to use, and should be able to use with our regular Sprite/Sprite3d commands. I'll have to create a working example and post on this thread.
User avatar
STARGÅTE
Addict
Addict
Posts: 2265
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: 2d GUI

Post by STARGÅTE »

I've already written quite a lot of GUIs.
The most important elements is my function:
DisplayBoxedSprite3D ()

It allows you to zoom in with the edge of sprites
Here's an example: (DX9!)

Code: Select all

InitSprite()
InitSprite3D()


; DirectX9
Structure Sprite3D_DX9_Vertex
  x.f:y.f:z.f
  rhw.f:Color.l
  tu.f:tv.f
EndStructure  

Structure Sprite3D_DX9
  TexRes.i
  Vertice.Sprite3D_DX9_Vertex[4]
  TmpVertice.Sprite3D_DX9_Vertex[4]
  Width.l 
  Height.l
  RealWidth.l
  RealHeight.l
  Angle.f
  Transformed.l
EndStructure

Procedure DisplayBoxedSprite3D(Sprite3D, x, y, Width, Height, Top, Right, Bottom, Left)
  Protected *Sprite3D.Sprite3D_DX9 = IsSprite3D(Sprite3D)
  Protected Dim u.f(3), Dim v.f(3) ; Vertex
  Protected Dim x.i(3), Dim y.i(3) ; Position
  Protected ix.i, iy.i
  With *Sprite3D
    u(0) = 0 : u(1) = Left/\RealWidth : u(2) = 1-Right/\RealWidth   : u(3) = 1
    v(0) = 0 : v(1) = Top/\RealHeight : v(2) = 1-Bottom/\RealHeight : v(3) = 1
    x(0) = x : x(1) = x+Left          : x(2) = x+Width-Right        : x(3) = x+Width
    y(0) = y : y(1) = y+Top           : y(2) = y+Height-Bottom      : y(3) = y+Height
    For iy = 0 To 2
    For ix = 0 To 2
      \Vertice[0]\tu = u(ix)   : \Vertice[0]\tv = v(iy)
      \Vertice[1]\tu = u(ix+1) : \Vertice[1]\tv = v(iy)
      \Vertice[2]\tu = u(ix)   : \Vertice[2]\tv = v(iy+1)
      \Vertice[3]\tu = u(ix+1) : \Vertice[3]\tv = v(iy+1)
      \Width = x(ix+1)-x(ix)   : \Height = y(iy+1)-y(iy)
      \Transformed = #False
      DisplaySprite3D(Sprite3D, x(ix), y(iy))
    Next
    Next
    \Vertice[0]\tu = 0 : \Vertice[0]\tv = 0
    \Vertice[1]\tu = 1 : \Vertice[1]\tv = 0
    \Vertice[2]\tu = 0 : \Vertice[2]\tv = 1
    \Vertice[3]\tu = 1 : \Vertice[3]\tv = 1
    \Width = \RealWidth : \Height = \RealHeight 
    \Transformed = #False
  EndWith
EndProcedure



OpenWindow(0, 0, 0, 800, 600, "Screen", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)
  
  UsePNGImageDecoder()
  CatchSprite(0, ?Window_png, #PB_Sprite_Texture|#PB_Sprite_AlphaBlending)
  CreateSprite3D(0, 0)
  
  
Repeat

  ClearScreen($FFFFFF)

  Start3D()
    Time.f = ElapsedMilliseconds()/1000
    DisplaySprite3D(0, 0, 0)
    DisplayBoxedSprite3D(0, 100, 100, 400+Sin(Time)*100, 300+Cos(Time)*100, 32, 16, 16, 16)
  Stop3D()

FlipBuffers()

Until WindowEvent() = #PB_Event_CloseWindow



DataSection
  Window_png:
  Data.q $0A1A0A0D474E5089,$524448490D000000,$4000000040000000,$7169AA0000000608,$47527301000000DE
  Data.q $0000E91CCEAE0042,$FF0044474B620600,$93A7BDA0FF00FF00,$7359487009000000,$130B0000130B0000
  Data.q $000000189C9A0001,$08DA07454D497407,$5F29C112161B151C,$5441444959020000,$30C26E7D9BEDDA78
  Data.q $F7636C413F5FC50C,$E0970A3D28E0971A,$D368A7D92760DC06,$DD2851337B51FD96,$DA0AD592D8B250D8
  Data.q $22017814DD8BF78A,$E94A651931C2648F,$C800AFE51D94F463,$ED0899210C941400,$BBB286F164A0719A
  Data.q $F02AE4A732294004,$1C88D94B7E8F0011,$1549644CDAF1DC8D,$AC6F16016E7C10C0,$73E124A003BFAAC1
  Data.q $D1C8056BE004820B,$D5B9095630F39F97,$0DA214212E10A5F3,$8FC5B7D189D0047C,$0CFDF44280251CDE
  Data.q $B2A610C7AAAAACC0,$E213EBD4A81EAAAA,$8085CA31320073DB,$76EDF8B5E56AD580,$1CDE00F600F7000B
  Data.q $ADC866739348616D,$B6DB400059173EB9,$A1D3916852C11421,$0809E90031B2C19C,$2DB696E00084C630
  Data.q $00B58E9F10E341B5,$B0154059915238DF,$92D49B83C52F11A0,$3F73EF29EB00039C,$2D29E9AA4F900A90
  Data.q $F80A90228E841F53,$1DFC054810059C71,$BA00D44015EFBE80,$EF400A00500AD3AE,$006E24924802F101
  Data.q $0532CB200DC79E79,$05B400A015A02DA0,$E2EDDBB0056202B4,$D9B016BDAF5EB006,$00A1E4453F3A2E6C
  Data.q $01400A0050028014,$02801400A0050028,$07BF90C6200A0050,$DBEFD2FF68FAEBB0,$A9D03FB1C6B60A57
  Data.q $0DC01CD7BFFC15C5,$30EE00176F15B706,$900B68AC18971098,$015E00EFF133CC7B,$BDAF42F00278033C
  Data.q $02AA7F76F24F3063,$7C49D35915B69FA4,$B4F7224D4014F19C,$5C05AC7EAEB0352F,$062DA7ED8C5D0DE2
  Data.q $565F06E9668F9E1F,$0028C20BBB3E9AD9,$F0B94CE72DB5A9E9,$08D992C18BD9C6F0,$5EDC2CE2DC130610
  Data.q $BB77CF7E7476C219,$3A059D9C41810DBC,$4C1690E1301B17B8,$2707400029BA10D8,$00B1A664B6870B8E
  Data.q $01B17249D0002A60,$E6CBA5345CBFFE8F,$686A4E17AFF31C26,$0555541F1D446868,$0000000B4E3C66FF
  Data.q $6042AE444E454900,$0000000000000082
EndDataSection 
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: 2d GUI

Post by PMV »

@Stargate
You have written a CEGUI in PB? Then post it! :mrgreen:

@X
I would love to be able to use CEGUI with PB without
build-in OGRE3D :D


MFG PMV
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Re: 2d GUI

Post by X »

According to the CEGUI docs, you only need DirectX itself, no need for the Orgre3d. I'm poking around with it right now at home, hopefully some fruit will come of this.
PureLust
Enthusiast
Enthusiast
Posts: 478
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: 2d GUI

Post by PureLust »

X wrote:Have anyone have any luck with creating a 2D gui for DirectX? (not for 3d but for 2d)?
Maybe you should have a look at the SGX-Lib by #Null :

Image
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Re: 2d GUI

Post by X »

Ah, thanks. That havent been updated in years though :( there was some bugs/issues when i tried it last, but that was a few versions ago.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: 2d GUI

Post by IdeasVacuum »

I think PrincieD's GUI uses DirectX?

http://www.purebasic.fr/english/viewtop ... &start=375
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: 2d GUI

Post by PMV »

X wrote:According to the CEGUI docs, you only need DirectX itself, no need for the Orgre3d. I'm poking around with it right now at home, hopefully some fruit will come of this.
You doesn't should say "only" ... if it would be simple someone had it done
already for pb. :twisted: But i hope it is not to hard for you. Because it would
really be nice to have a working lib or a little example. :D

As i remember the sgx is open source ... so feel free to fix bugs on your own. :wink:
(and don't forget to post the fixes :D )
As i see, the last update is for PB v4.41.

MFG PMV
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Re: 2d GUI

Post by X »

I dunno ;) The CEGUI said you need DirectX and/or OpenGL to run the gui against. We have Sprite3D commands which uses DirectX and not the Orge engine, so it must be possible unless the CEGUI website isn't correct. Any how, I now have some time to code since it is finally raining out side.

I looked at that ProGUI, I actually bought it recently for some other products. According to the thread start post, and the website, it does not use DirectX at all.
Post Reply