Leider funktioniert das Zeichnen von Linien noch nicht
Ich hab noch nicht herausgefunden woran es liegt.
Wäre um jede Hilfe dankbar
Testcode (d2d1.lib von VS wird benötigt!) :
Code: Alles auswählen
;Ugly Direct2D example!
;by Mijikai
;PB 5.62 x64 Win 10
Import "d2d1.lib"
D2D1CreateFactory(FactoryType.i,IID.i,*FactoryOptions,*IFactory)
EndImport
Structure D2D1_PIXEL_FORMAT
Format.l
AlphaMode.l
EndStructure
Structure D2D1_RENDER_TARGET_PROPERTIES
Type.l
PixelFormat.D2D1_PIXEL_FORMAT
DpiX.f
DpiY.f
Usage.l
MinLevel.l
EndStructure
Structure D2D1_POINT_F
X.f
Y.f
EndStructure
Structure D2D1_SIZE_U
X.l
Y.l
EndStructure
Structure D2D1_HWND_RENDER_TARGET_PROPERTIES
Hwnd.i
PixelSize.D2D1_SIZE_U
PresentOptions.i
EndStructure
Structure D2D1_COLOR_F
R.f
G.f
B.f
A.f
EndStructure
Structure D2D1_MATRIX_3X2_F
_11.f
_12.f
_21.f
_22.f
_31.f
_32.f
EndStructure
Structure D2D1_BRUSH_PROPERTIES
Opacity.f
Transform.D2D1_MATRIX_3X2_F
EndStructure
Structure D2D1_RECT_F
Left.f
Top.f
Right.f
Bottom.f
EndStructure
Enumeration D2D1_FACTORY_TYPE
#D2D1_FACTORY_TYPE_SINGLE_THREADED
#D2D1_FACTORY_TYPE_MULTI_THREADED
EndEnumeration
Interface ID2D1Factory Extends IUnknown
ReloadSystemMetrics()
GetDesktopDpi(*dpiX,*dpiY)
CreateRectangleGeometry(*Rectangle,*RectangleGeometry)
CreateRoundedRectangleGeometry(*RoundedRectangle,*RoundedRectangleGeometry)
CreateEllipseGeometry(*Ellipse,*EllipseGeometry)
CreateGeometryGroup(FillMode.i,*Geometries,GeometriesCount.i,*GeometrieGroup)
CreateTransformedGeometry(*SourceGeometry,Transform.i,*TransformedGeometry)
CreatePathGeometry(*PathGeometry)
CreateStrokeStyle(*StrokeStyleProperties,*Dashes,DashesCount.i,*StrokeStyle)
CreateDrawingStateBlock(*DrawingStateDescription,*TextRenderingParams,*DrawingStateBlock)
CreateWicBitmapRenderTarget(*Target,*RenderTargetProperties,*RenderTarget)
CreateHwndRenderTarget(*RenderTargetProperties,*HwndRenderTargetProperties,*HwndRenderTarget)
CreateDxgiSurfaceRenderTarget(*DxgiSurface,*RenderTargetProperties,*RenderTarget)
CreateDCRenderTarget(*RenderTargetProperties,*DCRenderTarget)
EndInterface
Interface ID2D1Resource Extends IUnknown
GetFactory(*Factory)
EndInterface
Interface ID2D1RenderTarget Extends ID2D1Resource
CreateBitmap(*Size,*ScrData,Pitch.i,*BitmapProperties,*Bitmap)
CreateBitmapFromWicBitmap(*BitmapSource,*Desc,*Bitmap)
CreateSharedBitmap(IID.i,*Data,*Desc,*Bitmap)
CreateBitmapBrush(*Bitmap,*BitmapBrush,*BitmapBrushDesc,*Brush)
CreateSolidColorBrush(*Color,*Desc,*Brush)
CreateGradientStopCollection(*Stops,StopCount.i,Gamma.i,ExtendMode.i,*Gradient)
CreateLinearGradientBrush(*GradientBrushDesc,*BrushDesc,*Gradient,*Brush)
CreateRadialGradientBrush(*GradientBrushDesc,*BrushDesc,*Gradient,*Brush)
CreateCompatibleRenderTarget(*Size,*PixelSize,*Format,Options.i,*RenderTarget)
CreateLayer(*Size,*Layer)
CreateMesh(*Mesh)
DrawLine(*P1,*P2,*Brush,Width.f,*StrokeStyle)
DrawRectangle(*Rect,*Brush,Width.f,*StrokeStyle)
FillRectangle(*Rect,*Brush)
DrawRoundedRectangle(*Rect,*Brush,Width.f,*StrokeStyle)
FillRoundedRectangle(*Rect,*Brush)
DrawEllipse(*Ellipse,*Brush,Width.f,*StrokeStyle)
FillEllipse(*Ellipse,*Brush)
DrawGeometry(*Geometry,*Brush,Width.f,*StrokeStyle)
FillGeometry(*Geometry,*Brush,*OpacityBrush)
FillMesh(*Mesh,*Brush)
FillOpacityMask(*Mask,*Brush,Content.i,*DestRect,*SrcRect)
DrawBitmap(*Bitmap,*DstRect,Opacity.f,InterpolationMode.i,*SrcRect)
DrawText(String.s,StringSize.i,*TextFormat,*LayoutRect,*Brush,Options.i,MeasuringMode.i)
DrawTextLayout(*Origin,*Layout,*Brush,Options.i)
DrawGlyphRun(*Origin,*GlyphRun,*Brush,MeasuringMode.i)
SetTransform(*Transform)
GetTransform(*Transform)
SetAntialiasMode(AntiAliasMode.i)
GetAntialiasMode()
SetTextAntialiasMode(AntiAliasMode.i)
GetTextAntialiasMode()
SetTextRenderingParams(*TextRenderingParams)
GetTextRenderingParams(*TextRenderingParams)
SetTags(Tag1.i,Tag2.i)
GetTags(*Tag1,*Tag2)
PushLayer(*LayerParameters,*Layer)
PopLayer()
Flush(*Tag1,*Tag2)
SaveDrawingState(*StateBlock)
RestoreDrawingState(*StateBlock)
PushAxisAlignedClip(*ClipRect,AntiAliasMode.i)
PopAxisAlignedClip()
Clear(*Color)
BeginDraw()
EndDraw(*Tag1,*Tag2)
GetPixelFormat()
SetDpi(DpiX.f,DpiY.f)
GetDpi(*DpiX,*DpiY)
GetSize()
GetPixelSize()
GetMaximumBitmapSize()
IsSupported(*Desc)
EndInterface
Procedure.i CreateFactory()
Protected *Factory
If D2D1CreateFactory(#D2D1_FACTORY_TYPE_SINGLE_THREADED,?IID_ID2D1Factory,#Null,@*Factory) = #S_OK
ProcedureReturn *Factory
EndIf
ProcedureReturn #Null
IID_ID2D1Factory:;{06152247-6f50-465a-9245-118bfd3b6007}
!dd 006152247h
!dw 06f50h,0465ah
!db 092h,045h,011h,08bh,0fdh,03bh,060h,007h
EndProcedure
Procedure.i Window();UGLY EXAMPLE
Protected Windown.i
Protected Event.i
Protected DX.f
Protected DY.f
Protected D2D1Factory.ID2D1Factory
Protected D2D1RenderTarget.ID2D1RenderTarget
Protected RenderTarget.D2D1_RENDER_TARGET_PROPERTIES
Protected HwndTargetProperties.D2D1_HWND_RENDER_TARGET_PROPERTIES
Protected BrushRed.i
Protected Color.D2D1_COLOR_F
Protected ColorBackground.D2D1_COLOR_F
Protected BrushProperties.D2D1_BRUSH_PROPERTIES
Protected Box.D2D1_RECT_F
Protected P0.D2D1_POINT_F
Protected P1.D2D1_POINT_F
D2D1Factory = CreateFactory()
If D2D1Factory
Window = OpenWindow(#PB_Any,#Null,#Null,400,400,"Direct 2D - Test!",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
If Window
D2D1Factory\GetDesktopDpi(@DX,@DY)
RenderTarget\DpiX = DX
RenderTarget\DpiY = DY
HwndTargetProperties\Hwnd = WindowID(Window)
HwndTargetProperties\PixelSize\X = 400
HwndTargetProperties\PixelSize\Y = 400
If D2D1Factory\CreateHwndRenderTarget(@RenderTarget,@HwndTargetProperties,@D2D1RenderTarget) = #S_OK
If D2D1RenderTarget
Color\a = 1
Color\b = 0
Color\g = 0
Color\r = 1
ColorBackground\A = 1
BrushProperties\Opacity = 0.5
If D2D1RenderTarget\CreateSolidColorBrush(@Color,@BrushProperties,@BrushRed) = #S_OK
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Break
EndSelect
Box\Left = 10
Box\Top = 10
Box\Right = 40 + Box\Left
Box\Bottom = 40 + Box\Top
D2D1RenderTarget\BeginDraw()
D2D1RenderTarget\Clear(@ColorBackground)
D2D1RenderTarget\FillRectangle(@Box,BrushRed)
Box\Left = 20
Box\Top = 20
Box\Right = 40 + Box\Left
Box\Bottom = 40 + Box\Top; this is the correct way to calculate it!
D2D1RenderTarget\DrawRectangle(@Box,BrushRed,2,#Null)
P0\X = 10
P0\Y = 10
P1\X = 100
P1\Y = 100
D2D1RenderTarget\DrawLine(@P0,@P1,BrushRed,1,#Null);DOES NOT WORK?!
;void DrawLine(
;[in] D2D1_POINT_2F p0,
;[in] D2D1_POINT_2F p1,
;[in] ID2D1Brush *brush,
;[in] float stroke_width,
;[in] ID2D1StrokeStyle *stroke_style
;);
D2D1RenderTarget\EndDraw(#Null,#Null)
ForEver
EndIf
EndIf
EndIf
EndIf
EndIf
EndProcedure;better release all resources & interfaces!!!
Window()
und dann erst Veröffentlichen - wegen DrawLine komm ich leider nicht voran... )