[Direct3D] Custom Vertex

shouzama

Freshman
Joined
Jan 20, 2003
Messages
38
Location
Another World
Ok, back on my "tile-engine", I decided to go the way Nerseus showed me and (finally) use D3D.

Problem is, the engine seems to consider my vertexes as it likes.

Here's the declaration of vertexes:

Visual Basic:
Dim tristrip(3) As Microsoft.DirectX.Direct3D.CustomVertex.TransformedColored

(this is only a test, so I only need to "color" vertexes to obtain a black square)

The following is the "initialization" of the vertexes listed above,
Visual Basic:
            With tristrip(0)
                .X = 10
                .Y = 10
                .Z = 0
                .Color = Color.Black.ToArgb
                .Rhw = 1
            End With

            With tristrip(1)
                .X = 210
                .Y = 10
                .Z = 0
                .Color = Color.Black.ToArgb
                .Rhw = 1
            End With

            With tristrip(2)
                .X = 10
                .Y = 210
                .Z = 0
                .Color = Color.Black.ToArgb
                .Rhw = 1
            End With

            With tristrip(3)
                .X = 210
                .Y = 210
                .Z = 0
                .Color = Color.Black.ToArgb
                .Rhw = 1
            End With

Finally, when I draw them
Visual Basic:
.DrawUserPrimitives(Microsoft.DirectX.Direct3D.PrimitiveType.TriangleStrip, 2, tristrip)

The engine shows me a 200x200 square, but colored in a sort of dark magenta...
This is independent of the color set on any of the vertexes.

Any clues?
 
Playing with numbers a little, I found an interesting thing:
Changing the clear color in Device.Clear changes the color of the rectangle.

It seems that the rectangle color is a darkened version of the .Clear color.
 
Without seeing your code, I can only guess. It appears that you've chosen the TransformedColored vertex type instead of TransformedColoredTextured. It looks like your sample is from DirectX4B if I'm not mistaken...?

The vertex type you've chosen are being lit by Direct3D. Assuming you have no lights or maybe an ambient one, it's distorting your "black" triangles.

I'm guessing you want the TransformedColoredTextured vertex type. This is used for "sprites" where you want to specify the X and Y coordinates in screen space. Direct3D won't apply any lighting to those triangles so you'll get what the vertex color is (Black in your case) or any combination of vertex colors and textures, if you're adding textures.

-nerseus
 
You're a sensitive or what? :eek:
Yes, you are right, I'm using the example given by DirectX4VB.
And yes, I'll want to use TransformedColoredTextured vertexes.

Ok then, I'll try and use them and let you know (a matter of minutes)

EDIT: ok, back.
I used TCT vertex but there were no changes.
In VB6 and DX8, you should use and instruction such as
.SetVertexFormat, I don't know if there's something similar in DX9.
Something, I mean, that can tell DX9 what kind of vertexes I want it to process.
 
Last edited:
Yes, you'll have to set it on your device, something like:

dev.VertexFormat = CustomVertex.TransformedColoredTextured.Format;

-nerseus

PS I had *just* looked at sample 4 from DirectX4b last night for a post on the VB6 message boards and noticed the "weird" X/Y values of 10 and 210 - the sames ones you were using. :)
 
Again, no result...
I don't know if you'll ever have time to look at my code, but I'm completely out of ideas...
It seems that I can't figure out how to make my device render some BASIC vertex...

Anyway, if someone is willing to help, here's my code.
 

Attachments

Ok, I solved the problem, don't ask me how.

Putting the
Device.VertexFormat
in the device creation gave me the glitches I listed before
BUT
if I put the Device.VertexFormat INSIDE the Render sub, IT WORKS.

Now, I think it depends on my visualization (rendering to a picturebox instead of full screen) and some strange behavior of DirectX.
 
It looks as though calling Begin on a Sprite object will reset the device's VertexFormat. Your project is using CEngine, which declares an instance of CPainter, which has an instance of Sprite. When you call c3DEngine.BeginScene, it calls Begin on the Sprite object which is resetting the vertex format.

If you don't need the CPainter class, you could try removing it. Or you could just stick with setting the VertexFormat on every loop. You'll probably end up doing that anyway if you're using 3D, as almost all 3D apps are going to display sprites at some point (for a hud, a player name, score, etc.) and that will require changing the vertex format.

-nerseus
 
Thanks a lot Nerseus.
Since I plan to use a Sprite object to display everything that isn't a tile, I think I must set the VertexFormat every frame.

Thanks again!
 
The VertexFormat should (and probably can only) be set during the Device.BeginScene and Device.EndScene
 
AndreRyan said:
The VertexFormat should (and probably can only) be set during the Device.BeginScene and Device.EndScene
That's not true. It can be done at any time. You typically do it there since it's rare to only use a single vertex format, which means you have to change back and forth during rendering.

If you were to only use a single format then you could set it after the device was created and never look at it again.


The Sprite interface can end up changing a few states, you have to be careful about that.
 
Back
Top