[Direct3D] Custom Vertex

shouzama

Active member
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.

Heres the declaration of vertexes:

Code:
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,
Code:
            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
Code:
.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 youve chosen the TransformedColored vertex type instead of TransformedColoredTextured. It looks like your sample is from DirectX4B if Im not mistaken...?

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

Im 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 wont apply any lighting to those triangles so youll get what the vertex color is (Black in your case) or any combination of vertex colors and textures, if youre adding textures.

-nerseus
 
Youre a sensitive or what? :eek:
Yes, you are right, Im using the example given by DirectX4VB.
And yes, Ill want to use TransformedColoredTextured vertexes.

Ok then, Ill 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 dont know if theres something similar in DX9.
Something, I mean, that can tell DX9 what kind of vertexes I want it to process.
 
Last edited by a moderator:
Yes, youll 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 dont know if youll ever have time to look at my code, but Im completely out of ideas...
It seems that I cant figure out how to make my device render some BASIC vertex...

Anyway, if someone is willing to help, heres my code.
 

Attachments

Ok, I solved the problem, dont 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 devices 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 dont need the CPainter class, you could try removing it. Or you could just stick with setting the VertexFormat on every loop. Youll probably end up doing that anyway if youre 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 isnt 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
 
Originally posted by AndreRyan
The VertexFormat should (and probably can only) be set during the Device.BeginScene and Device.EndScene
Thats not true. It can be done at any time. You typically do it there since its 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