• Advertisement
Sign in to follow this  

Managed Directx and CustomVertex.TransformedColored issues

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm having the wierdest of issues plotting pixels... here is the code:
private void InitializePoints() 
{ 
        Random rand = new Random(); 


        numberOfPrims = 2000; 


        m_random_data = new CustomVertex.TransformedColore­d[numberOfPrims]; 
        int zeroCount = 0; 
        for (int count=0;count < numberOfPrims;count++) 
        { 
                m_random_data[count].X=rand.Ne­xt(this.Width); 
                m_random_data[count].Y=rand.Ne­xt(this.Height); 
                m_random_data[count].Z=rand.Ne­xt(0, 2); 
                //m_random_data[count].Z=1.0f; 
                m_random_data[count].Rhw=1.0f; 
                m_random_data[count].Color = Color.Violet.ToArgb(); 
        } 



} 

private void Render() 
{ 
        long startFrameTime = hpTime.CurrentTime; 

        device.Clear(ClearFlags.Target­, Color.Black.ToArgb() , 1.0f, 0); 


        device.BeginScene(); 


        device.VertexFormat= CustomVertex.TransformedColore­d.Format; 


        device.DrawUserPrimitives(Prim­itiveType.PointList, 
                numberOfPrims, 
                m_random_data); 


        device.EndScene(); 


        device.Present(); 


        //Control execution time by waiting at least 10 milliseconds 
        float elapsedTime = (hpTime.CurrentTime - startFrameTime) / 
hpTime.TicksPerMs; 
        while( elapsedTime < 10 ) 
        { 
                elapsedTime = (hpTime.CurrentTime - startFrameTime) / 
hpTime.TicksPerMs; 
        } 



} 
In the InitializePoints function I fill an array of CustomVertex.TransformedColore­d structures. The problem is with the Z dimension. As you can see there is a commented out line that sets all the pixels Z to 1.0f. This is the recomendation of the tutorial I started with and what makes sense to me. However, when I specify this value the screen is blank. The program does not throw any exceptions but seemingly runs fine, except ofcourse that it doesn't seem to draw the pixels. The line thats uncommented sets the Z dimension to either 0 or 1. The ones set to 0 display; I've tested this by lowering the number of primitives down to 10 and outputing the result of the random and adding up how many I see and how many 0's or 1's were set. I tried setting all the pixels Z dimension to 0.0f (and just 0) but that has the same result as setting it to 1.0f, nothing. Actually thats not true, when i lower the primitives to 24 or less and set the Z dimension to 0.0f, it works. 25 or more and nothing. When I set the number of primitives to 2000 and use the random (resulting in either 0 or 1), it usually produces something like 1700 pixels with z=0, and all of these pixels display. Can someone give me some guidance, this is blowing my mind. :! Try testing the code yourself if that helps. If you get it to work... please let me know. I'm using dx 9.0c and the following device setup:
private void InitializeDevice() 
{ 
        PresentParameters presentParams = new PresentParameters(); 


        presentParams.Windowed = false; 
        presentParams.BackBufferFormat = Format.X8R8G8B8; 
        presentParams.BackBufferHeight = this.Size.Height; 
        presentParams.BackBufferWidth = this.Size.Width; 
        presentParams.PresentationInte­rval = PresentInterval.Immediate; 


        presentParams.SwapEffect = SwapEffect.Discard; 
        presentParams.AutoDepthStencil­Format = DepthFormat.D16; 
        presentParams.EnableAutoDepthS­tencil = true; 


        device = new Device(0, DeviceType.Hardware, this, 
CreateFlags.SoftwareVertexProc­essing, presentParams); 

}
Thank you for your time. [Edited by - demiurgeinc on March 15, 2005 7:13:48 AM]

Share this post


Link to post
Share on other sites
Advertisement
I fixed the problem, instead of:


m_random_data[count].X=rand.Ne­xt(this.Width);
m_random_data[count].Y=rand.Ne­xt(this.Height);
m_random_data[count].Z=1.0f;
m_random_data[count].Rhw=1.0f;
m_random_data[count].Color = Color.Violet.ToArgb();


using this worked:


m_random_data[count].Position =
new Vector4( rand.Next(this.Width), rand.Next(this.Height), 1.0f, 1.0f );
m_random_data[count].Color = Color.Violet.ToArgb();


P.S. I started making this from a tut DrunkenHyena created. I noticed he is an active member of this forum, so if your reading this, you might want to update your tut. ;) P.S.P.S. Your tuts are missing the utility file you created.

Share this post


Link to post
Share on other sites
You are creating a Z-Buffer but aren't clearing it. The original tutorial didn't set up a Z-Buffer. Since a Z value is the farthest value if there is anything in the ZBuffer than nothing will be rendered.

Either get rid of the ZBuffer, or if you plan on using it you need to pass the ZBuffer clear flag as well as the Target one.

The utility stuff is linked here:
http://www.drunkenhyena.com/cgi-bin/view_article.pl?chapter=1;article=1;lang=cpp

Share this post


Link to post
Share on other sites
Actually, I had tried clearing the z-buffer and later removed it. Then I start using a VertexBuffer for the points and using DrawPrimitives() instead of DrawUserPrimitives() (I've read this is faster since it stores it in video memory instead of copying the data from system memory each frame). None of this worked. Not until I set the position with the code mentioned above (using Position = new Vector4()).

However I later realized that it only worked with the DeviceType set to Reference. When I set it to Hardware it only worked with less then 25 points. I sent exe to a friend using DeviceType.Hardware and 600 points and it worked fine for him. So my only thoughts are that my gfx card (Geforce 2 MX 440) doesn't support dx9 properly. I had a nicer card but it fried itself last month. I knew I couldn't do some of the more advanced aspects of dx9 with my current card, but I thought I could draw points :!

Is my thinking correct?

P.S. Thanks for the response DrunkenHyena; I didn't see the link on your site, but I probably just missed it.

Share this post


Link to post
Share on other sites
The first thing I'd try is downloading the Exe for that tutorial from my site and see if it runs properly. If it does then you know it's not your card, but your code.

When things don't work we tend to try different approaches and it's very easy to leave behind remnants of previous attempts while trying new ones. Creating a ZBuffer but not clearing it in the code you posted is a good example of that. After you verify that the Exe runs properly (it should, your card is more than sufficient) you should go back to my original code and then start playing with it from a base that's known to work.

Share this post


Link to post
Share on other sites
I would of tried that, but I get a system.io.filenotfoundexception when I run most of your samples. I assume this is due to the updates in directx as many samples I find for dx9 don't run. (for example, setposition is no longer a function of CustomVertexs). Don't get me wrong, I am very grateful for your tutorials, they have provided a lot of insight, and I have learned a lot from reading your tutorials.

Share this post


Link to post
Share on other sites
Okay I downloaded all the source and got it to compile. With DeviceType.Reference it works, with DeviceType.Hardware it doesn't. As you said, my gfx card should be able capable of drawing points... but apparently not?

P.S. I assume the problem with your exe is that it was built with older versions of managed dx9 assemblies and the new release available from MS only includes the latest assemblies. Correct?

Share this post


Link to post
Share on other sites
Quote:
Original post by demiurgeinc
Okay I downloaded all the source and got it to compile. With DeviceType.Reference it works, with DeviceType.Hardware it doesn't. As you said, my gfx card should be able capable of drawing points... but apparently not?


That's not good. It's likely one (or more) of:
1) DirectX is whacked. Try running DxDiag.exe and see if the tests run.
2) Uninstall, reboot, install latest video drivers
3) Upgrade to latest motherboard drivers (AGP especially)

Quote:

P.S. I assume the problem with your exe is that it was built with older versions of managed dx9 assemblies and the new release available from MS only includes the latest assemblies. Correct?

Quite possibly. There are reasons I stopped doing the Managed DX tutorials...

Share this post


Link to post
Share on other sites
I'm running out the door right now, but when I get back I'll do the dxdiag test and try to upgrade as you suggested. However, I'm quite interested in your "reasons" for stopping development of your managed dx tutorials. Is there anywhere that you've listed or explained these reasons already? If not would you mind informing here? Thanks a lot for all you help thus far, its greatly appreciated.

Share this post


Link to post
Share on other sites
I did the dxdiag test and everything worked fine; but I think I found the problem, least it works when I set up the device this way:

device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, presentParams);
I had it set like this:

device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);

Is this a common mistake or a fluke on my computer, its seems logical...

In the future I'll ofcourse add code to test what is available on the system the app is running on, but typically speaking, HardwareVertexProcessing is what I should pass if its supported, correct? Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement