Jump to content
  • Advertisement
Sign in to follow this  
Kilickaya

Untitled

This topic is 2801 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


When my program executes the line "Direct3D objD3D = new Direct3D ()", a red rectangle as big as the screen is drawn and a red line from up-left of the screen to right-down of it and another red line from up-right of the screen to left-down of it. With what functions is that appearance got rid of?

Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Without source code this is impossible to even begin to help with. Try posting the constructor of the Direct3D class, and anything else that you feel might be relevant.

Share this post


Link to post
Share on other sites
Quote:
Original post by Burnt_Fyr
Without source code this is impossible to even begin to help with. Try posting the constructor of the Direct3D class, and anything else that you feel might be relevant.


---------------------------
This is my source code. It should draw a triangle. If you inform me what else is wrong with my whole code, I be glad.

private void Form1_Paint (object sender, PaintEventArgs e)
{
Direct3D objDirect3D = new Direct3D ();
PresentParameters pp = new PresentParameters ();
pp.BackBufferHeight = 1080;
pp.BackBufferWidth = 1920;
Device dvc = new Device (objDirect3D, 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, pp);
VertexBuffer VrtxBuf = new VertexBuffer (dvc, 3 * 3 * 4, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
DataStream VrtxStrm = VrtxBuf.Lock (0, 0, LockFlags.None);
float [] VrtxData = { 50f, 0f, 0f, 0f, 50f, 0f, 0f, 25f, 0f };
VrtxStrm.WriteRange (VrtxData);
VrtxBuf.Unlock ();
dvc.Clear (ClearFlags.All, Color.Black, 1f, 0);
dvc.BeginScene ();
dvc.SetStreamSource (0, VrtxBuf, 0, 12);
dvc.DrawPrimitives (PrimitiveType.TriangleList, 0, 1);
dvc.EndScene ();
dvc.Present ();
VrtxStrm.Dispose ();
VrtxBuf.Dispose ();
dvc.Dispose ();
objDirect3D.Dispose ();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Kilickaya
When my program executes the line "Direct3D objD3D = new Direct3D ()", a red rectangle as big as the screen is drawn


-I don't suppose that line alone is guilty of the drawn primitives.

VrtxData and DrawPrimitives() on the other hand, may have something to do with it.

What do you want the code to do, what would you consider "correct" behaviour?

Share this post


Link to post
Share on other sites
Quote:
Original post by SuperVGA
Quote:
Original post by Kilickaya
When my program executes the line "Direct3D objD3D = new Direct3D ()", a red rectangle as big as the screen is drawn


-I don't suppose that line alone is guilty of the drawn primitives.

VrtxData and DrawPrimitives() on the other hand, may have something to do with it.

What do you want the code to do, what would you consider "correct" behaviour?


---------------------------------------
My code should draw only a triangle. Even if I write only the first line which is "Direct3D objD3D = new Direct3D ()" the red rectangle and the two lines are drawn.

Share this post


Link to post
Share on other sites
First of all: IMHO it is not a good idea to create Direct3D and the device in your form's paint handler. You rather create it at your application start or at least in your form's constructor. Otherwise you create your device every time your form redraws. Similar can be said for the vertex buffer: create it once and only change it when your geometry changes, in the paint handler you just do the rendering. Where did you get that code from ?

Then: I can't quite remember if MDX automatically sets the FVF (device.VertexFormat) if you hook up the stream. Rather set it manually. Anyway: You use a VertexFormat.None which is AFAIR only valid if you setup your own vertex declaration, which you don't either. Guessing from 3 * 3 * 4, your stream stride and your float array, you have a vertex format of position only, so the FVF is VertexFormat.Position. Actually MDX provides some handy structs for some FVF combinations to start with, so in your case you could use CustomVertex.PositionOnly.

Furthermore you don't set any transformation states and other - relevant - render states.

Share this post


Link to post
Share on other sites
The big red rectangle is how the system handles exceptions thrown during the paint event.

Are you using MDX or SlimDX?

As stated, you don't want to create the Direct3D object and Device each paint event. Create them once in your Load event and then use them when needed. Also, make sure to Dispose them in your Closing event.

Now, the bigger thing is: why are you using Direct3D for this? Or more importantly, why are you using Direct3D in this fashion? If you're using it for simple 2D, GDI would probably be more than sufficient (which is pretty much how you're using Direct3D right now anyway.) If you're using it for anything else, you're going to want it running in a tight loop, not only when the window get's repainted (which is rarely.)

Also, for future reference, when posting source code please use the source tags [ source ] and [ /source ] (without spaces of course.)

Share this post


Link to post
Share on other sites
Quote:
Original post by unbird
First of all: IMHO it is not a good idea to create Direct3D and the device in your form's paint handler. You rather create it at your application start or at least in your form's constructor. Otherwise you create your device every time your form redraws. Similar can be said for the vertex buffer: create it once and only change it when your geometry changes, in the paint handler you just do the rendering. Where did you get that code from ?

Then: I can't quite remember if MDX automatically sets the FVF (device.VertexFormat) if you hook up the stream. Rather set it manually. Anyway: You use a VertexFormat.None which is AFAIR only valid if you setup your own vertex declaration, which you don't either. Guessing from 3 * 3 * 4, your stream stride and your float array, you have a vertex format of position only, so the FVF is VertexFormat.Position. Actually MDX provides some handy structs for some FVF combinations to start with, so in your case you could use CustomVertex.PositionOnly.

Furthermore you don't set any transformation states and other - relevant - render states.

------------------------------------------
Would you please write the correct appearance of my code upwards? Namely, how should it be seen in my Form class (when its parts are seperated into the methods of my Form class)?


Share this post


Link to post
Share on other sites
Oops, my bad, I think it's SlimDX, since he's using DataStream (in MDX it's called GraphicsStream). So forget about my hint for CustomVertex. You could use Vector3 if you stay with position only. But as soon as your vertex's has more properties, go for self-defined structs.

Admittedly, Programmer16 is right: For doing simple 2D in a paint handler, i.e. non-realtime, GDI+ is far more appropriate. And before I spoon-feed a "solution" you rather tell us where you want to go after painting triangles.

Share this post


Link to post
Share on other sites
Original post by Programmer16

Now, the bigger thing is: why are you using Direct3D for this? Or more importantly, why are you using Direct3D in this fashion? If you're using it for simple 2D, GDI would probably be more than sufficient (which is pretty much how you're using Direct3D right now anyway.) If you're using it for anything else, you're going to want it running in a tight loop, not only when the window get's repainted (which is rarely.)

---------------------------------------
My goal is not 2-D drawing. I'm learning Direct3D and that simple triangle is only a start.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!