-
Apr 19th, 2009, 01:59 PM
#1
Thread Starter
Member
Having some trouble with VB+DirectX8
the 0,0 oriented part is the source material the stuff in the square is the output. vb seems to be destroying it during rendering. I dont understand, it looks like scaling artifacting, but its rendering each tile at the proper size (16x16)
(please) help?
-
Apr 19th, 2009, 02:34 PM
#2
Addicted Member
Re: Having some trouble with VB+DirectX8
hiya buddy, could be quiet a few rpobs here, any chance you can shows us the code in your paint procedure
-
Apr 19th, 2009, 02:41 PM
#3
Thread Starter
Member
Re: Having some trouble with VB+DirectX8
Spritesize = 16
TilesetList(Tile.TilesetID)
.pHheight = 1 / the height of the texture
.Height = 1 / (TextureList(TextureID).Height \ SpriteSize)
(same goes for pWidth and Width)
Tile.tilesetx and tilesety refer to the XY grid coordinates of the source material
.Grid(Tile.TilesetY, Tile.TilesetX).Frame adds to Tile.tilesetx for animated tiles
Public Sub DrawTile(Tile As GridTileset, X As Long, Y As Long, Optional Alpha As Byte = 255)
Dim TempX As Single, TempY As Single
If Tile.TilesetID < TilesetCount And Tile.TilesetID > -1 Then
With TilesetList(Tile.TilesetID)
TempX = (Tile.TilesetX + .Grid(Tile.TilesetY, Tile.TilesetX).Frame) * .Width + .pWidth
TempY = Tile.TilesetY * .Height + .pHeight
DX_RenderTexture .TextureID, X, Y, CSng(SpriteSize), CSng(SpriteSize), TempX, TempY, .Width, .Height, Tile.FlipX, Tile.FlipY, , , Alpha
End With
End If
End Sub
Public Sub DX_RenderTexture(Index As Long, ByVal X As Long, ByVal Y As Long, Width As Long, Height As Long, Optional srcX As Single, Optional srcY As Single, Optional srcWidth As Single = 1, Optional srcHeight As Single = 1, Optional FlipX As Boolean, Optional FlipY As Boolean, Optional Scalefactor As Single = 1, Optional color As Long = 16777215, Optional Alpha As Byte = 255, Optional ScaleY As Single = -1, Optional Alignment As Long = DT_CENTER + DT_VCENTER) ', Optional Opacity As Single = 1) &HFFFFFFFF
'srcX, srcY, srcWidth, srcHeight are based on scales of 0 to 1, where 0 = left or top, and 1 = width or height
Dim Left As Single, Top As Single, Right As Single, Bottom As Single, CenterX As Single, CenterY As Single, temp As Single, Distance As Single, Radians As Double, X2 As Single, Y2 As Single
If Not Initialised Then Exit Sub
If ScaleY = -1 Then ScaleY = Scalefactor
If Alpha < 255 Then
If color <= 16777215 And color > -1 Then ' Color = Color + Alpha * &H1000000
If Alpha < 128 Then
color = color + Alpha * &H1000000
Else
color = -1 - ((255 - Alpha) * &H1000000) - (16777215 - color) '+ (Not Color)
End If
End If
D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 1
D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE
'D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE
'D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT
End If
If Scalefactor = 1 Then
Left = X
Top = Y
Right = X + Width '- 1
Bottom = Y + Height ' - 1
CenterX = X + (Width / 2)
CenterY = Y + (Height / 2)
Else
temp = (Width / 2)
CenterX = X + temp
Left = CenterX - (temp * Scalefactor)
Right = CenterX + (temp * Scalefactor)
temp = (Height / 2)
CenterY = Y + temp
Top = CenterY - (temp * ScaleY)
Bottom = CenterY + (temp * ScaleY)
End If
If FlipX Then DX_SwitchValues Left, Right
If FlipY Then DX_SwitchValues Top, Bottom
TriStrip(0) = CreateTLVertex(Left, Top, 0, 1, color, 0, srcX, srcY) 'top left
TriStrip(1) = CreateTLVertex(Right, Top, 0, 1, color, 0, srcX + srcWidth, srcY) 'top right
TriStrip(2) = CreateTLVertex(Left, Bottom, 0, 1, color, 0, srcX, srcY + srcHeight) 'bottom left
TriStrip(3) = CreateTLVertex(Right, Bottom, 0, 1, color, 0, srcX + srcWidth, srcY + srcHeight) 'bottom right
D3DDevice.SetTexture 0, TextureList(Index).Texture '//Tell the device which texture we want to use...
D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, TriStrip(0), Len(TriStrip(0))
If Alpha < 255 Then D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 0
End Sub
-
Apr 19th, 2009, 02:47 PM
#4
Thread Starter
Member
Re: Having some trouble with VB+DirectX8
I think it's an issue with DX_RenderTexture, since the same issue shows up when I draw the entire texture.
I wish DX worked in pixels instead of % of the source...
Last edited by neotechni; Apr 19th, 2009 at 03:03 PM.
-
Apr 19th, 2009, 03:11 PM
#5
Thread Starter
Member
Re: Having some trouble with VB+DirectX8
The lower image is directx output
You can notice an extra line of pixels on the left, and top. the bottom doormat tile is completely garbled, same for the chimneystack of the right building
I don't understand, it's outputting the correct size
-
Apr 19th, 2009, 04:31 PM
#6
Thread Starter
Member
Re: Having some trouble with VB+DirectX8
I fixed it (we'll see if it stays fixed with different resolution textures) with some tweaking of the renderer srcx/y/width/height values
1) I'd like to thank you, even though you didn't solve it, I appreciate that you even messaged me
2) I don't suppose you know how to draw primitives like a line/circle/square in directx?
Last edited by neotechni; Apr 19th, 2009 at 04:38 PM.
-
Apr 19th, 2009, 05:02 PM
#7
Addicted Member
Re: Having some trouble with VB+DirectX8
Afraid not, im working through the same kind of problems here with vb.net 2008 and dx9..
just started learning it yestuday..
-
Apr 19th, 2009, 05:59 PM
#8
Thread Starter
Member
Re: Having some trouble with VB+DirectX8
arg, now it's ignoring my transparency color
I'm sure the color I'm feeding into
Set .Texture = D3DX.CreateTextureFromFileEx(D3DDevice, Filename, Width, Height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, _
D3DPOOL_MANAGED, D3DX_FILTER_POINT, D3DX_FILTER_POINT, Transcolor, ByVal 0, ByVal 0)
is the same I'm using in the file, as I've checked using mspaint
Apparently I'm not setting the alpha, anyone know the RGBa function for directx?
Last edited by neotechni; Apr 19th, 2009 at 06:03 PM.
-
Apr 19th, 2009, 06:20 PM
#9
Thread Starter
Member
Re: Having some trouble with VB+DirectX8
I found they are supposed to be the following macros:
D3DCOLOR_XRGB
D3DCOLOR_ARGB
Which do nothing in vb...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|