For some reason I can draw a vertical/horizontal render texture to actual SFML shapes, but not drawn points like I am creating for the rounded rectangle with the triangle fans. So I am approaching this another way different from the previous reply and edits.
I am making an attempt to convert this so I can use it like other shapes:
Source: Draw Rounded RectangleHere is the class I have converted from that link:
Imports System
.MathImports SFML
.SystemImports SFML
.GraphicsPublic Class RoundedRectangleShape
Inherits Shape
Dim mySize
As Vector2f
Dim myRadius
As Single Dim myCornerPointCount
As UInteger Public Sub SetSize
(ByVal size
As Vector2f
) mySize
= size
Update
() End Sub Public Function GetSize
() Return mySize
End Function Public Sub SetCornerRadius
(ByVal radius
As Single) myRadius
= radius
Update
() End Sub Public Function GetCornerRadius
() Return myRadius
End Function Public Sub SetCornerPointCount
(ByVal count
As UInteger) myCornerPointCount
= count
Update
() End Sub Public Overrides Function GetPointCount
() As UInteger Return myCornerPointCount
* 4 End Function Public Sub New(ByVal size
As Vector2f,
ByVal radius
As Single,
ByVal cornerPointCount
As UInteger) mySize
= size
myRadius
= radius
myCornerPointCount
= cornerPointCount
Update
() End Sub Public Overrides Function GetPoint
(ByVal index
As UInteger) As Vector2f
If index
>= myCornerPointCount
* 4 Then Return New Vector2f
(0,
0) End If Dim deltaAngle
As Single = 90
.0F
/ (myCornerPointCount
- 1) Dim center
As Vector2f
Dim centerIndex
As UInteger = index
/ myCornerPointCount
Dim pi
As Single = 3
.14159274F
Select Case (centerIndex
) Case 0 center
.X = mySize
.X - myRadius
center
.Y = myRadius
Case 1 center
.X = myRadius
center
.Y = myRadius
Case 2 center
.X = myRadius
center
.Y = mySize
.Y - myRadius
Case 3 center
.X = mySize
.X - myRadius
center
.Y = mySize
.Y - myRadius
End Select Return New Vector2f
(myRadius
* Cos(deltaAngle
* (index
- centerIndex
) * pi
/ 180) + center
.X,
-myRadius
* Sin(deltaAngle
* (index
- centerIndex
) * pi
/ 180) + center
.Y) End FunctionEnd Class Implementation in loop:
Dim roundedRectangle As New GFX_Control_Library.RoundedRectangleShape(New Vector2f(75, 25), 5, 3)
roundedRectangle.SetSize(New Vector2f(75, 25))
roundedRectangle.SetCornerRadius(5)
roundedRectangle.SetCornerPointCount(3)
roundedRectangle.Position = New Vector2f(140, 20)
roundedRectangle.OutlineThickness = 1
roundedRectangle.OutlineColor = Color.Blue
roundedRectangle.Texture = m_renderTexture.Texture
roundedRectangle.TextureRect = New IntRect(20, 20, 95, 45)
m_engineWindow.Draw(roundedRectangle)
Here is my result:
I will be honest, I do not fully understand how this is working as the GetPoint function in the class works differently than the way points are being set drawing a rounded rectangle with triangle fans. However, it looks like the 2 points on the right side are pulled to the left, and I have no idea where to start on correcting that.
Please tell me someone understand what is going on
?
Edit:
Okay, so looped through the debugger and noticed that it was only hitting [Case 0] 3 times while it hit the others 5, then looping through twice and returning the last 2 set values instead of a Case. So I added this to the bottom:
Case Else
center.X = mySize.X - myRadius
center.Y = myRadius
I increased the radius size to 10, and this is what I get now:
So I'm getting closer, but I do not see a way to pull back the starting points. After messing with a few settings I noticed this is drawing backwards, with position 0 at the top right, position 1 at the top left, and continuing counter clockwise. It is drawing in the correct position I set it to though.
I believe this issue has something to do with the way the base Shape class draws the custom shapes, but honestly am not certain. I'm hoping for some ideas on what I might be doing wrong so the starting points of the radii can draw in the correct position.