shouzama Posted January 31, 2003 Posted January 31, 2003 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: 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, 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 .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? Quote
shouzama Posted January 31, 2003 Author Posted January 31, 2003 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. Quote
*Experts* Nerseus Posted January 31, 2003 *Experts* Posted January 31, 2003 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
shouzama Posted January 31, 2003 Author Posted January 31, 2003 (edited) 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. Edited January 31, 2003 by shouzama Quote
*Experts* Nerseus Posted January 31, 2003 *Experts* Posted January 31, 2003 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. :) Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
shouzama Posted February 1, 2003 Author Posted February 1, 2003 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.project.zip Quote
shouzama Posted February 1, 2003 Author Posted February 1, 2003 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. Quote
*Experts* Nerseus Posted February 1, 2003 *Experts* Posted February 1, 2003 Your zip is missing form1.vb... can't do much without it :) -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
shouzama Posted February 2, 2003 Author Posted February 2, 2003 Sorry, seems like I need more sleep... :p Here's the right version ^_^ (Updated with the .VertexFormat in the "Render" sub)project.zip Quote
*Experts* Nerseus Posted February 2, 2003 *Experts* Posted February 2, 2003 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
shouzama Posted February 3, 2003 Author Posted February 3, 2003 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! Quote
AndreRyan Posted February 23, 2003 Posted February 23, 2003 The VertexFormat should (and probably can only) be set during the Device.BeginScene and Device.EndScene Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
DrunkenHyena Posted February 24, 2003 Posted February 24, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.