Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Jul 2011
Offline Last Active Jun 25 2014 07:36 AM

Topics I've Started

slimdx drawing a square

13 December 2012 - 01:31 AM

I'm trying to render a square in SlimDX.
public class Square
		public Buffer vertexBuffer;
		public Square(Vector3 origin, float edge, Device device)
			DataStream Vertices;
			Vertices = new DataStream(12 * 5, true, true);
			Vertices.Write(new Vector3(1, 1, 0));
			Vertices.Write(new Vector3(-1, 1, 0));
			Vertices.Write(new Vector3(-1, -1, 0));
			Vertices.Write(new Vector3(1, -1, 0));
			Vertices.Write(new Vector3(1, 1, 0));
			Vertices.Position = 0;
			vertexBuffer = new Buffer(device, Vertices, 12 * 5, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
		public void Draw(Device device)
			device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineStrip;
			device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 12, 0));
			device.ImmediateContext.Draw(4, 0);
However, only first four elements of DataStream Vertices are rendered. For square, it corresponds to 3 lines. I tried other PrimitiveTopology like TriangleList, TriangleStrip or PointList, they all behave the same - load only first 4 vertices no matter how big original DataStream is. I remember to create vertexBuffer with the same size as DataStream and tried to make it bigger as well.

pixel shader 3.0 for sprites

03 August 2011 - 09:06 PM

I'm using pixel shader in my game based on sprites and "starter" looks like this:
sampler2D textureSampler;
float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0
	float4 Color;
	Color = tex2D(textureSampler, Tex);
    return Color;

technique PostProcess
	pass Pass1
    	VertexShader = null;
    	PixelShader = compile ps_2_0 MyShader();

I want to use pixel shader 3.0 to use VPOS input semantic but whne i use PixelShader = compile ps_3_0 MyShader(); whole screen has uniform color. Can someone tell how ps 3 should look like ?

access to member of a child class

12 July 2011 - 10:55 AM

How do I do that ?
#include <iostream>

class Mother {

class Son : public Mother{
	int f_iA;
	Son(int _in){f_iA = _in;}
	int GetInt(){return f_iA;}

Mother* pSon;

int main()
	pSon = new Son(5);
	std::cout<<pSon->GetInt(); //'GetInt' : is not a member of 'Mother'
	return 0;

D3DX9 sprite z sort

08 July 2011 - 08:55 PM

I figured out how to "z sort" my sprites (ID3DXSprite) so i don't have to worry about which sprites are rendered first. I just change the z value for coordinates. However, i noticed some stupid flaw in this method. Look at the attached image. On the picture on the left, upper fern is rendered later so it covers lower fern, everything is ok. On the right i changed the z coord of the lower fern to make it cover the upper one. At the edges of the fern i can see the ground. Somehow the upper fern is not rendered correctly. Textures are TGA files.
Things that i think are relevant:
pp.BackBufferFormat = D3DFMT_A8R8G8B8;
pp.AutoDepthStencilFormat = D3DFMT_D16;
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x0000FF00, 1.0f, 0L );
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
Thank you.