Problems with C# and DirectX

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 4782 Views - Last Post: 18 September 2009 - 01:50 PM Rate Topic: -----

#1 Lunchbox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-August 09

Problems with C# and DirectX

Posted 26 August 2009 - 01:25 AM

Hello together,
I have a problem with Direct X using C#:
I'm writing some kind of 3D-Engine class which I can use in different programs.
The problem is that the 3D models which I load from x-files were not shown correctly.
The models seem to consist of vertical stripes.
This is "just" an error in graphics so can anyone make diagnostics so far without seeing the code?
When I run the program on another PC I can't see any models at all and I think it has something to do with the general Direct X settings or something. I started learning the use of Direct X with a tutorial which worked perfectly on this PC, so its not a general Direct X problem it seems to be that my program is the reason for this strange view.
In the attached screenshot you can see a model of a sword and a rotating x-Wing (from Riemers Tutorial for those who know).

I use Win XP, SP 2 and DX 9.0c on a Lenovo Notebook.

Greets, Lunchbox

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Problems with C# and DirectX

#2 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: Problems with C# and DirectX

Posted 26 August 2009 - 05:30 AM

First of all the Screenshot.zip is corrupted.Attach the pic

Quote

The models seem to consist of vertical stripes.

Show a sample code how you setup your device .
Please post this in GameProgramming forum this forum is for C#
In GameProgramming forum you will get more help .
Was This Post Helpful? 0
  • +
  • -

#3 Lunchbox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-August 09

Re: Problems with C# and DirectX

Posted 26 August 2009 - 06:35 AM

This is C# programming that's why I posted it here.
The downloaded zip worked on my pc but I can also attach the pic.

The Device-Initialization looks like this:
public static void InitializeDevice(Form form)
{
	owner = form;
	PresentParameters presentParams = new PresentParameters();
	presentParams.BackBufferWidth = xResolution;
	presentParams.BackBufferHeight = yResolution;
	presentParams.BackBufferFormat = Format.R5G6B5;
	presentParams.Windowed = false;
	presentParams.SwapEffect = SwapEffect.Discard;
	presentParams.AutoDepthStencilFormat = DepthFormat.D16;
	presentParams.EnableAutoDepthStencil = true;
	device = new D3D.Device(0, D3D.DeviceType.Hardware, owner, CreateFlags.SoftwareVertexProcessing, presentParams);

	setRenderStates();

	device.DeviceReset += new EventHandler(HandleResetEvent);
}


The function is called from another class - the form, which sends itself as a parameter.
SetRenderStates does actually nothing more than setting the font for the text and turning lighting off.

I hope this helped

Attached image(s)

  • Attached Image

This post has been edited by Lunchbox: 26 August 2009 - 06:40 AM

Was This Post Helpful? 0
  • +
  • -

#4 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: Problems with C# and DirectX

Posted 26 August 2009 - 08:44 AM

I know its a C# program but its about Games Programming so you will get more help in Games Programming forum try it

Got your pic

Sorry for this
[qoute]
Show a sample code how you setup your device
[/qoute]
it should be
Show a sample code how you setup your device and render it.

So as per me to know where is the problem ,if its your code or the graphic card or dirextx setting , just use the Rendering mesh sample in DirectX SDK ,run it and see the tiger mesh properly rendering on screen or not.
Was This Post Helpful? 0
  • +
  • -

#5 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Problems with C# and DirectX

Posted 26 August 2009 - 08:53 AM

debjit625 is right, you may get a better response in the game programming forums.

Could you also post the code you are using to draw the models?
Was This Post Helpful? 0
  • +
  • -

#6 Lunchbox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-August 09

Re: Problems with C# and DirectX

Posted 26 August 2009 - 10:50 AM

Okay, if I don't get any ideas I will open a topic at the game development area...

The Drawing routine is copied from a tutorial as well and worked in another program:
//Draws a mesh
private static void DrawMesh(Mesh mesh, Material[] meshmaterials, Texture[] meshtextures)
		{
			for (int i = 0; i < meshmaterials.Length; i++)
			{
				device.Material = meshmaterials[i];
				device.SetTexture(0, meshtextures[i]);
				mesh.DrawSubset(i);
			}
		}

//gets called on the onPaint-Event
		public static void paint(Form form)
		{
			angle += 0.1f;
			if (angle > Math.PI * 2) angle = 0;

			try
			{
				device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);

				device.BeginScene();

				for (int i = 0; i < entities.Count; i++)
				{
					entity e = entities.ElementAt<entity>(i);
					if (e.visib)
					{
						e.zAngle = angle;
						device.Transform.World = Matrix.RotationYawPitchRoll(e.xAngle, e.yAngle, e.zAngle) * Matrix.Translation(e.position - cameraPosition);
						DrawMesh(e.mesh, e.material, e.texture);
					}
				}

				device.EndScene();

				device.Present();
				form.Invalidate();
			}
			catch (DeviceLostException)
			{
				HandleResetEvent(owner, null);
			}


		}

	}


I deleted the lines with the text drawings from the Paint-Function.
The angle stuff is just to rotate the models around the z-axis.

If you mean the rotating Cube with the Direct X Logo on it: yes, it worked fine and 3D games with Direct X do also work.

This post has been edited by Lunchbox: 26 August 2009 - 11:03 AM

Was This Post Helpful? 0
  • +
  • -

#7 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Problems with C# and DirectX

Posted 26 August 2009 - 11:10 AM

Moving this to Game Programming. Hope you have some better luck there.
Was This Post Helpful? 0
  • +
  • -

#8 Lunchbox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-August 09

Re: Problems with C# and DirectX

Posted 26 August 2009 - 11:20 AM

View PostSixOfEleven, on 26 Aug, 2009 - 10:10 AM, said:

Moving this to Game Programming. Hope you have some better luck there.

Thx :D
I hope so too ...

So guys, anyone here who can help me? ^^
Was This Post Helpful? 0
  • +
  • -

#9 Aeternalis  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 291
  • Joined: 13-July 09

Re: Problems with C# and DirectX

Posted 26 August 2009 - 12:15 PM

Personally just looking at the picture it looks like a materials problem . have you tried substituting a different material or a different model ...do you get the same results?

I would try to substitute in a model you have had success with on that setup. Like the Tiger mesh.. use the tiger mesh in your new code and see if it makes a difference. If it doesn't, and you get the same results.. you have eliminated the mesh model.

I would then start looking at lighting maybe? have you tried adding more light to the scene? It can have strange effects on the model if it is not lit properly.

I am trying to focus on things that might have changed from the tutorial.. as it seems like you are saying you have had this working before? Or did I misinterpret that?

Aet
Was This Post Helpful? 0
  • +
  • -

#10 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: Problems with C# and DirectX

Posted 26 August 2009 - 12:17 PM

Welcome to GameProgramming and also in DreamInCode

Quote

If you mean the rotating Cube with the Direct X Logo on it: yes, it worked fine and 3D games with Direct X do also work.


No I didnt mean the rotating Cube with the Direct X Logo on it.
What i am talking about is a sample given in DirectX SDK (mine is JUNE 2006) it have a SampleBrowser where some examples are given.

Dont worry its a silly mistake or you are very new to DirectX programming
Here you are clearing the backbuffer but not the depthbuffer(ZBuffer)
device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);


you should do this
device.Clear(ClearFlags.Target|ClearFlags.ZBuffer,Color.DarkSlateBlue, 1.0f, 0);



Hope it helped

This post has been edited by debjit625: 26 August 2009 - 12:20 PM

Was This Post Helpful? 1
  • +
  • -

#11 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Problems with C# and DirectX

Posted 26 August 2009 - 12:22 PM

View Postdebjit625, on 26 Aug, 2009 - 12:17 PM, said:

What i am talking about is a sample given in DirectX SDK (mine is JUNE 2006)



Good lord, you really need to update.
Was This Post Helpful? 0
  • +
  • -

#12 Lunchbox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-August 09

Re: Problems with C# and DirectX

Posted 26 August 2009 - 12:55 PM

View Postdebjit625, on 26 Aug, 2009 - 11:17 AM, said:

Welcome to GameProgramming and also in DreamInCode
you should do this
device.Clear(ClearFlags.Target|ClearFlags.ZBuffer,Color.DarkSlateBlue, 1.0f, 0);



Hope it helped


Yes it did - you're a god :D

Why did I have to move the thread into this area before you answered me right? :P
Was This Post Helpful? 0
  • +
  • -

#13 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: Problems with C# and DirectX

Posted 26 August 2009 - 01:54 PM

Quote

Why did I have to move the thread into this area before you answered me right?

Hey after all its called GameProgramming forum(kidding).This is why I was asking for the code of setup and rendering of your device and i saw it after this topic was moved here.

Good luck

And to KYA yes i have updated version (March 2009)but updated versions no more provide documentation for managed extention .
Was This Post Helpful? 0
  • +
  • -

#14 Lunchbox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-August 09

Re: Problems with C# and DirectX

Posted 27 August 2009 - 02:11 AM

Okay so far everything works BUT I have a new problem:

When setting the cull mode only the polygons were rendered that face the camera counterclockwise.
If I switch the cullmode only those that face the camera clockwise were rendered (of course).
cullmode.none is actually much slower and not recommended for games and does actually produce a wrong rendering too.

Does anyone know how to solve this problem?
I can see through some polygons the models spin around although they look good in the DirectX Viewer and the x-Wing worked also in the tutorial program (where it didn't spin).

Attached Image
Between the wings you can see the error but its really obvious when the model moves

This post has been edited by Lunchbox: 27 August 2009 - 07:25 AM

Was This Post Helpful? 0
  • +
  • -

#15 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: Problems with C# and DirectX

Posted 27 August 2009 - 11:52 AM

Hey ,Managed DirectX 3d Fixed Pipeline have only these three cull mode type Clockwise,CounterClockWise and None .One of them must work.But I think its not the problem ,I guess you have dynamic lights on and your mesh have no texture ,try with a mesh which have texture or add texture to the current mesh.this is causing because of lights set them properly
It may be not but atleast try.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3