Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Jan 2012
Offline Last Active Jun 11 2012 07:43 AM

Topics I've Started

Porting from OpenGL to Directx

07 January 2012 - 07:23 AM


recently I have been trying to port over the OpenGL interface due to some problems with Intel Graphic chips which have a bad OpenGL driver in Windows. I need help to port a Quad in OpenGL to DirectX. Heres what i have done in OpenGL:

					GL.TexCoord2(x1, y1);
					GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset);
					GL.TexCoord2(x1, y2);
					GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset);
					GL.TexCoord2(x2, y2);
					GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset);
					GL.TexCoord2(x2, y1);
					GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset);

And here is what I am doing for DirectX
rx1 = ((rx1 * 2) / ClientSize.Width)  -1f;
				rx2 = ((rx2 * 2) / ClientSize.Width) - 1f;
				ry1 = ((ry1 * 2) / ClientSize.Height) - 1f;
				ry2 = ((ry2 * 2) / ClientSize.Height) - 1f;

				DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.None);
				stream.WriteRange(new[] {
   				 new TexturedVertex(new Vector3(rx1, ry1, 0), new Vector2(x1, y1)),
   				 new TexturedVertex(new Vector3(rx1, ry2, 0), new Vector2(x1, y2)),
   				 new TexturedVertex(new Vector3(rx2, ry2, 0), new Vector2(x2, y2)),
					new TexturedVertex(new Vector3(rx2, ry1, 0), new Vector2(x2, y1)),
				m_Device.SetTexture(0, _D3DTextures[Texture.index]);
				m_Device.SetStreamSource(0, _VertexBuffer, 0, Marshal.SizeOf(typeof(TexturedVertex)));
				m_Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

Unfortunetely the Textures are mirrored and the alpha Channel is displayed in black. I hope you can help me, I have been trying to get this working for 2 days now =/

Best regards xDarkice