Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Super wacky fun fun DirectX! Big Smiles!

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
cbx Posted - Jan 16 2005 : 7:52:25 PM
It's official I'm cursed. OK so at around 4am today I downloaded the DaBooda Turbo engine and the sample apps, and thought it was pretty cool, and made me all nostalgic inside for classic arcade gamming. I spent time looking at the engine source code and thought a few areas in the rendering pipline could use improvement. It was late so I went to sleep. After I woke up I started writing a similar 2D renderer of my own called DaFlak (not an engine just a renderer). And as I began to create the 2nd example app for it I came across this strange problem (view the image below)...

Download Attachment: strange dx.gif<br>25.28 KB

As you can see there is a double blended image in the example app but I am not even manipulating the texture coordanants of the geometry! The texture you see consists of 2 polygons that simulate a 2D sprite.

Example_SingleSprite sample app (executable only). To use the app use the 3 mouse buttons to manipulate the sprite...
Download Attachment: Example_SingleSprite.zip<br>100.5 KB

DaFlak source code (preliminary proof of concept). The only part you need to focus on is the Renderer.vb in the DaFlakRenderer project. That is where all the relavant rendering code is located ...
Download Attachment: DaFlak.zip<br>101.34 KB

Does anyone have a clue as to what could be causing this? It only seems to mutate the texture if you scale the sprite geometry to a small size and rotate it. I am using current video card drivers for my ATI X800 Pro as well as the current DirectX libraries (Dec 2004)

Another problem I seem to be having is that I can't get Lighting to work properly. It does not seem to matter if the D3DDevice.RenderState.Lighting property is true or false the sprite geometry is always visible!

As the title of the subject suggests "Super wacky fun fun DirectX! Big Smiles!" Loosly translated means "All the 'Issues' I have been having with DirectX latley are starting to make me go insane!"
9   L A T E S T    R E P L I E S    (Newest First)
Eric Coleman Posted - Jan 19 2005 : 11:00:18 AM
Yes, that screenshot was from an ATI DirectX demo showing how to project an AVI file as a texture. I originally took that screenshot as proof that it's not just my code or VB that causes the problem.
Almar Posted - Jan 19 2005 : 10:08:54 AM
Do I see VC6 Eric? :)
Eric Coleman Posted - Jan 17 2005 : 11:09:53 AM
Ok, it's official, you're now crazy

As for my video card, I'm using ATI drivers for a DiamondMM branded Radeon 7000. It's possible that it's a driver issue. I've had my share of driver issues, and it's a pain in the ass. I've had problems with an ATI card saying that it supported certain alpha blending modes when it really didn't, an nVidia card not reading surface data correctly (it would return the color black instead of the requested pixel color), and a 3DFX driver issue that would seriously deform the rendered geometry when applying a standard (built in) DirectX matrix transformation to the texture corrdinates.
cbx Posted - Jan 17 2005 : 12:24:37 AM
Hahahah ... Hahaha,... Mua hahahah, lol lol That's juts too dam funny, hahaha...

It would appear as though I have solved the problem! And it is as simple as changing the references from the Dec 2004 managed DX libraries and referencing the Originally released Summer update 2003 managed dx libs. IE version 1.0.900.0

... ... Hahahah,... Hahahaha lol I'm sorry but just I can't stop laughing,... From where I stand the only release of managed directx that has consistantly worked for me has been the 1.0.900.0 managed dx libraries. Can you believe it! The first release of managed dx is the most stable/reliable. Since then (atleast for me) the managed dx libs have been sliding down the slippery slope of shame towards utter piss me off lameness,... Whaaaaa hahahahaha ...

With all me troubles with managed dx I'm thinking about writing a detailed document that compiles a list of things that has gone bad for me, regarding managed dx, and submiting it to microsoft, but I think i'll wait until feburary (the next sceduled release for dx) and see what happens.

I'm betting anyone that they screw it up even further! Now if you don't mind I have more laughing to do, Mua hahaha .....
cbx Posted - Jan 16 2005 : 11:09:07 PM
BTW the commented out code you see in the RenderSprite method...

  
            'If mblnSpriteBeninCalled = False Then mobjSprite.Begin(mintSpriteRenderFlags)  
            'Me.mobjSprite.Draw2D(mobjTexCB(Sprite.TextureIndex), Sprite.Rectangle, DR, _  
            '                 New Point(CInt(Sprite.CenterX), CInt(Sprite.CenterY)), Sprite.Rotation, _
            '                 New Point(CInt(Sprite.PositionX), CInt(Sprite.PositionY)), Sprite.Color)
            'If mblnSpriteBeninCalled = False Then mobjSprite.End()  
  


... Was the original code I was using to draw the sprite. But then as usual I discovered a wierd problem with that also. Seems that if you draw a sprite at location x:256 by y:0 with a 45 deg rotation the sprite does not show up anywhere near x:256 by y:0 on the screen like you would expect it to. The fallowing attachment demonstrates the use and effects of the fallowing code ...

  
            If mblnSpriteBeninCalled = False Then mobjSprite.Begin(mintSpriteRenderFlags)  
            Me.mobjSprite.Draw2D(mobjTexCB(Sprite.TextureIndex), Sprite.Rectangle, DR, _  
                             New Point(CInt(Sprite.CenterX), CInt(Sprite.CenterY)), Sprite.Rotation, _  
                             New Point(CInt(Sprite.PositionX), CInt(Sprite.PositionY)), Sprite.Color)  
            If mblnSpriteBeninCalled = False Then mobjSprite.End()  
  


Download Attachment: Example_SingleSprite Revised.zip
100.6 KB
cbx Posted - Jan 16 2005 : 10:53:28 PM
quote:
Originally posted by Eric Coleman
<br>I looked through your code and I honestly don't understand the managed stuff. I read through the code multiple times trying to find out where DirectX is actually initlized or where the program starts it's execution, but I couldn't find it. I'm not sure how this managed stuff is supposed to make things easier for programmers. I guess I'm officially old fashioned for preferring the DirectX where you had to explicitly create your objects instead of relying some some magic to create them for you. I guess what I'm trying to say is that I tried, but I'm not much help anymore.



Viola! 240 lines of rendering code in the code Renderer.vb file as it currently exists on my computer. The only methods that are important are these 2 ...

The class constructor
Public Sub New(ByVal Ctrl As Control, ByVal Callback As TextureCallback)  

And the RenderSprite method that does the actual rendering.
Public Overrides Sub RenderSprite(ByVal Sprite As DaFlak.Sprite)  


As for Managed DX and vb.net being hard to understand and quote "magical" I find managed DX is actually very similar to DirectX8 in many ways. At this point I find myself pointing the finger towards a video card driver issue, but if that were the case then eric should not be seeing the same thing I am, and yet he is! Aside from the alpha blending.

BTW Eric what graphics card were you using to run the app?


  
Imports Microsoft.DirectX  
Imports Microsoft.DirectX.Direct3D.DeviceType  
Imports Microsoft.DirectX.Direct3D.CreateFlags  
Imports Microsoft.DirectX.Direct3D.Geometry  
Imports Microsoft.DirectX.Direct3D.ClearFlags  
  
Public Class Renderer  
    Inherits DaFlak.Renderer  
    Implements IDisposable  
  
  
    Private Enum RenderingState As Integer
        None = 0  
        SceneRender = 1  
        LayerRender = 2  
        SpriteRender = 3  
    End Enum
  
    Public Delegate Function TextureCallback(ByVal Index As Integer) As Direct3D.Texture  
    Protected Friend mobjTexCB As TextureCallback  
    Protected Friend mintSpriteRenderFlags As Direct3D.SpriteFlags  
    Protected Friend WithEvents mobjGFX As Direct3D.Device  
    Protected Friend mobjPresent As New Direct3D.PresentParameters()  
    Protected Friend mobjSprite As Direct3D.Sprite  
    Private mobjVB As Direct3D.VertexBuffer  
    Private mblnSpriteBeninCalled As Boolean = False
    Private mintRenderState As RenderingState = RenderingState.None  
    Private mobjTarget As Control  
    Protected Friend mobjBackgroundColor As Color = Color.Black  
  
    Public Property BackgroundColor() As Color  
        Get
            Return mobjBackgroundColor  
        End Get
        Set(ByVal Value As Color)  
            mobjBackgroundColor = Value  
        End Set
    End Property
  
    Public Function GetDevice() As Direct3D.Device  
        Return mobjGFX  
    End Function
  
    Public Overrides Sub RenderLayer(ByVal Layer As DaFlak.Layer)  
        If Layer.Visible = False Then Exit Sub
        ' render sprites  
        Dim idx As Integer
        For idx = 0 To Layer.Sprites.Count - 1  
            Me.RenderSprite(Layer.Sprites(idx))  
        Next
    End Sub
  
    Public Overrides Sub RenderScene(ByVal Scene As DaFlak.DaFlak)  
        Me.mintRenderState = RenderingState.SceneRender  
  
        With Me.mobjGFX  
             .Clear(Target Or ZBuffer, mobjBackgroundColor, 1, 0)  
            .BeginScene()  
            mobjSprite.Begin(mintSpriteRenderFlags)  
            mblnSpriteBeninCalled = True
  
            ' render layers  
            Dim idx As Integer
            For idx = 0 To Scene.Layers.Count - 1  
                If Scene.Layers(idx).Visible Then
                    Me.RenderLayer(Scene.Layers(idx))  
                End If
            Next
  
            mobjSprite.End()  
            mblnSpriteBeninCalled = False
            .EndScene()  
            .Present()  
        End With
        Me.mintRenderState = RenderingState.None  
    End Sub
  
    Public Overrides Sub RenderSprite(ByVal Sprite As DaFlak.Sprite)  
        If Sprite.Visible = False Then Exit Sub
        If Me.mintRenderState <> RenderingState.None Then
            Dim DR As SizeF  
            DR.Width = Sprite.Rectangle.Width * Sprite.ScaleX  
            DR.Height = Sprite.Rectangle.Height * Sprite.ScaleY  
  
            Dim Tex As Direct3D.Texture = mobjTexCB(Sprite.TextureIndex)  
  
            mobjGFX.Transform.Projection = Matrix.OrthoOffCenterLH(0, mobjTarget.Width, mobjTarget.Height, 0, 0, 1000)  
            Dim M As Matrix = Matrix.Identity  
            M.Multiply(Matrix.Scaling(DR.Width, DR.Height, 0))  
            M.Multiply(Matrix.Translation(-(Sprite.CenterX * Sprite.ScaleX), -(Sprite.CenterY * Sprite.ScaleY), 0))  
            M.Multiply(Matrix.RotationYawPitchRoll(0, 0, Sprite.Rotation))  
            M.Multiply(Matrix.Translation(Sprite.PositionX, Sprite.PositionY, 0))  
            mobjGFX.Transform.World = M  
  
            M = Matrix.Identity  
            M.Multiply(Matrix.Scaling(DR.Width, DR.Height, 0))  
            Dim Desc As Direct3D.SurfaceDescription = Tex.GetSurfaceLevel(0).Description  
            M.Multiply(Matrix.Translation(CSng(Sprite.Rectangle.Left / Desc.Width), _  
                                          CSng(Sprite.Rectangle.Top / Desc.Height), 0))  
            '' M.Transformation2D()  
            'M.M31 = CSng(Sprite.Rectangle.Left / Desc.Width)  
            'M.M32 = CSng(Sprite.Rectangle.Top / Desc.Height)  
            mobjGFX.SetTransform(Direct3D.TransformType.Texture0, M)  
  
            Dim Mat As Direct3D.Material  
            Mat.Ambient = Sprite.Color  
            Mat.Diffuse = Sprite.Color  
            mobjGFX.Material = Mat  
  
            mobjGFX.SetTexture(0, Tex)  
            mobjGFX.SetStreamSource(0, mobjVB, 0)  
            mobjGFX.VertexFormat = mobjVB.Description.VertexFormat  
            mobjGFX.DrawPrimitives(Direct3D.PrimitiveType.TriangleFan, 0, 2)  
  
            'If mblnSpriteBeninCalled = False Then mobjSprite.Begin(mintSpriteRenderFlags)  
            'Me.mobjSprite.Draw2D(mobjTexCB(Sprite.TextureIndex), Sprite.Rectangle, DR, _  
            '                 New Point(CInt(Sprite.CenterX), CInt(Sprite.CenterY)), Sprite.Rotation, _
            '                 New Point(CInt(Sprite.PositionX), CInt(Sprite.PositionY)), Sprite.Color)
            'If mblnSpriteBeninCalled = False Then mobjSprite.End()  
        End If
    End Sub
  
    Public Sub New(ByVal Ctrl As Control, ByVal Callback As TextureCallback)  
  
  
        Me.mobjTexCB = Callback  
        Me.mintSpriteRenderFlags = Direct3D.SpriteFlags.AlphaBlend  
        With mobjPresent  
            .MultiSample = Direct3D.MultiSampleType.None  
            .MultiSampleQuality = 0  
  
            .Windowed = True
            .EnableAutoDepthStencil = True
            .AutoDepthStencilFormat = Direct3D.DepthFormat.D16  
            .BackBufferWidth = Ctrl.ClientSize.Width  
            .BackBufferHeight = Ctrl.ClientSize.Height  
            .BackBufferCount = 1  
            .SwapEffect = Direct3D.SwapEffect.Copy  
            .PresentationInterval = Direct3D.PresentInterval.Immediate  
            .DeviceWindow = Ctrl  
        End With
  
        Try
            Me.mobjGFX = New Direct3D.Device(0, Hardware, Ctrl, HardwareVertexProcessing Or FpuPreserve, Me.mobjPresent)  
  
        Catch ex As Exception  
            'ERR: handle error?  
        End Try
  
        ' setup device  
        With Me.mobjGFX  
            .RenderState.FillMode = Direct3D.FillMode.Solid  
            .RenderState.ZBufferEnable = True
            .RenderState.CullMode = Direct3D.Cull.None  
            .RenderState.Lighting = False
            .RenderState.AlphaBlendEnable = True
            .RenderState.SourceBlend = Direct3D.Blend.SourceAlpha  
            .RenderState.DestinationBlend = Direct3D.Blend.InvSourceAlpha  
            .SamplerState(0).MinFilter = Direct3D.TextureFilter.None  
            .SamplerState(0).MagFilter = Direct3D.TextureFilter.None  
            .SamplerState(0).MipFilter = Direct3D.TextureFilter.None  
            .RenderState.Ambient = Color.Black  
            .TextureState(0).TextureTransform = Direct3D.TextureTransform.Count2  
  
  
            '.RenderState.AmbientMaterialSource = Direct3D.ColorSource.Material  
            '.RenderState.DiffuseMaterialSource = Direct3D.ColorSource.Material  
            '.RenderState.MultiSampleAntiAlias = False  
  
            'Dim aspect As Single = CSng(Ctrl.ClientSize.Width / Ctrl.ClientSize.Height)  
            '.Transform.Projection = Matrix.PerspectiveFovLH(DegreeToRadian(90), aspect, 0, 1000)  
            '.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, -Ctrl.ClientSize.Width / 2.0F), New Vector3(), New Vector3(0, 1, 0))  
        End With
  
        Dim mobjVerts(3) As Direct3D.CustomVertex.PositionTextured  
        mobjVerts(0) = New Direct3D.CustomVertex.PositionTextured(0, 0, 0, 0, 0)  
        mobjVerts(1) = New Direct3D.CustomVertex.PositionTextured(1, 0, 0, 1, 0)  
        mobjVerts(2) = New Direct3D.CustomVertex.PositionTextured(1, 1, 0, 1, 1)  
        mobjVerts(3) = New Direct3D.CustomVertex.PositionTextured(0, 1, 0, 0, 1)  
        mobjVB = New Direct3D.VertexBuffer(mobjVerts(0).GetType, 4, mobjGFX, 0, mobjVerts(0).Format, Direct3D.Pool.Managed)  
        mobjVB.SetData(mobjVerts, 0, Direct3D.LockFlags.None)  
        Erase mobjVerts  
  
        Me.mobjSprite = New Direct3D.Sprite(Me.mobjGFX)  
        Me.mobjTarget = Ctrl  
    End Sub
  
    Public Property SpriteRenderFlags() As Direct3D.SpriteFlags  
        Get
            Return mintSpriteRenderFlags  
        End Get
        Set(ByVal Value As Direct3D.SpriteFlags)  
            mintSpriteRenderFlags = Value  
        End Set
    End Property
  
#Region " IDisposable Support "  
    Private disposed As Boolean = False
  
    ' IDisposable  
    Private Overloads Sub Dispose(ByVal disposing As Boolean)  
        If Not Me.disposed Then
            If disposing Then
                mobjSprite.Dispose()  
                mobjSprite = Nothing  
                mobjVB.Dispose()  
                mobjVB = Nothing  
                mobjPresent = Nothing  
                mobjGFX.Dispose()  
                mobjGFX = Nothing  
                mobjTarget = Nothing  
                mobjTexCB = Nothing  
            End If
  
            ' TODO: put code to free unmanaged resources here  
        End If
        Me.disposed = True
    End Sub
  
    ' This code added by Visual Basic to correctly implement the disposable pattern.  
    Public Overloads Sub Dispose() Implements IDisposable.Dispose  
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.  
        Dispose(True)  
        GC.SuppressFinalize(Me)  
    End Sub
  
    Protected Overrides Sub Finalize()  
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.  
        Dispose(False)  
        MyBase.Finalize()  
    End Sub
#End Region  
  
    Private Sub mobjGFX_DeviceResizing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles mobjGFX.DeviceResizing  
        If Me.mobjTarget.ClientSize.Width < 1 Then e.Cancel = True
        If Me.mobjTarget.ClientSize.Height < 1 Then e.Cancel = True
    End Sub
End Class  
  
  
Eric Coleman Posted - Jan 16 2005 : 10:43:57 PM
I looked through your code and I honestly don't understand the managed stuff. I read through the code multiple times trying to find out where DirectX is actually initlized or where the program starts it's execution, but I couldn't find it. I'm not sure how this managed stuff is supposed to make things easier for programmers. I guess I'm officially old fashioned for preferring the DirectX where you had to explicitly create your objects instead of relying some some magic to create them for you. I guess what I'm trying to say is that I tried, but I'm not much help anymore.
cbx Posted - Jan 16 2005 : 10:00:04 PM
quote:
Originally posted by Eric Coleman
<br>When I run the demo the texture's coordinates get shifted when I resize the square. I don't see any alpha blending like your screenshot though.



Yep that's what I said. And the only place where I define my vertexes is in the contructor for the Renderer.vb file ...

  
        Dim mobjVerts(3) As Direct3D.CustomVertex.PositionTextured  
        mobjVerts(0) = New Direct3D.CustomVertex.PositionTextured(0, 0, 0, 0, 0)  
        mobjVerts(1) = New Direct3D.CustomVertex.PositionTextured(1, 0, 0, 1, 0)  
        mobjVerts(2) = New Direct3D.CustomVertex.PositionTextured(1, 1, 0, 1, 1)  
        mobjVerts(3) = New Direct3D.CustomVertex.PositionTextured(0, 1, 0, 0, 1)  
        mobjVB = New Direct3D.VertexBuffer(mobjVerts(0).GetType, 4, mobjGFX, 0, mobjVerts(0).Format, Direct3D.Pool.Managed)  
        mobjVB.SetData(mobjVerts, 0, Direct3D.LockFlags.None)  
        Erase mobjVerts  


... The code above is the only code that I use to manupulate the vertexes. Everything else is done through matricies, and even then I don't event specify to transform the texture0 matrix ala
D3DDevice.SetTransform(Direct3D.TransformType.Texture0, SomeMatrix)  
.

I just can't think of a reason why this could be happening... I've stared dumfounded at the code but can't seem to provide an answer as to why it would be doing this.

The only varibles I'm modifying is the world transform matrix for the D3DDevice...

Dim M As Matrix = Matrix.Identity  
M.Multiply(Matrix.Scaling(DR.Width, DR.Height, 0))  
M.Multiply(Matrix.Translation(-(Sprite.CenterX * Sprite.ScaleX), -(Sprite.CenterY * Sprite.ScaleY), 0))  
M.Multiply(Matrix.RotationYawPitchRoll(0, 0, Sprite.Rotation))  
M.Multiply(Matrix.Translation(Sprite.PositionX, Sprite.PositionY, 0))  
mobjGFX.Transform.World = M  
Eric Coleman Posted - Jan 16 2005 : 9:49:40 PM
When I run the demo the texture's coordinates get shifted when I resize the square. I don't see any alpha blending like your screenshot though.

VBGamer © Go To Top Of Page
This page was generated in 0.78 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.