cant see my problem (source included)

Started by
4 comments, last by Misiu 16 years, 10 months ago
all it is a simple class for drawing textured quads i get seem to see where its going wrong, nothing is being displayed at all cpp file


Image2D::Image2D(void)
{
	vbuf = NULL;
	texture = NULL;
}

Image2D::~Image2D(void)
{
	SAFE_RELEASE(vbuf);
	SAFE_RELEASE(texture);
}

bool Image2D::Load(const wchar_t *filename)
{
	if(D3DXCreateTextureFromFileEx(DXUTGetD3DDevice(), filename, D3DX_DEFAULT, D3DX_DEFAULT,
		D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, &info, NULL, &texture) != D3D_OK)
		return false;

	std::cout << "loaded" << std::endl;

	if(DXUTGetD3DDevice()->CreateVertexBuffer(sizeof(vert) * 4, 0, thisfvf, D3DPOOL_MANAGED, &vbuf, NULL) != D3D_OK)
		return false;

	std::cout << "created" << std::endl;

	SetSize(0, 0, info.Width, info.Height);

	return true;
}

void Image2D::Draw()
{
	std::cout << "trying" << std::endl;
	DXUTGetD3DDevice()->SetVertexShader(NULL);
	DXUTGetD3DDevice()->SetFVF(thisfvf);
	DXUTGetD3DDevice()->SetStreamSource(0, vbuf, 0, sizeof(vert));
	DXUTGetD3DDevice()->SetTexture(0, texture);
	DXUTGetD3DDevice()->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
}

bool Image2D::IsVisible()
{
	return visible;
}

void Image2D::SetVisible(bool vis)
{
	visible = vis;
}

void Image2D::SetSize(float x, float y, float x2, float y2)
{
	_x = x;
	_y = y;
	_x2 = x2;
	_y2 = y2;

	vert *data;

	if(vbuf->Lock(0, 0, (void **)&data, 0) == D3D_OK)
	{
		data[0].pos = D3DXVECTOR3(_x, _y, 1.0);
		data[0].color = D3DCOLOR_XRGB(255, 255, 255);
		data[0].tu = 0.0f;
		data[0].tv = 0.0f;

		data[1].pos = D3DXVECTOR3(_x, _y2, 1.0);
		data[1].color = D3DCOLOR_XRGB(255, 255, 255);
		data[1].tu = 0.0f;
		data[1].tv = 1.0f;

		data[2].pos = D3DXVECTOR3(_x2, _y2, 1.0);
		data[2].color = D3DCOLOR_XRGB(255, 255, 255);
		data[2].tu = 1.0f;
		data[2].tv = 1.0f;

		data[3].pos = D3DXVECTOR3(_x2, _y, 1.0);
		data[3].color = D3DCOLOR_XRGB(255, 255, 255);
		data[3].tu = 1.0f;
		data[3].tv = 0.0f;
		
		std::cout << "lock ok" << std::endl;

		vbuf->Unlock();
	}


}

void Image2D::SetLayer(int l)
{
	layer = l;
}

int Image2D::GetLayer()
{
	return layer;
}


h file


class Image2D
{
public:

	Image2D(void);
	~Image2D(void);

	bool Load(const wchar_t *filename);
	void Draw();
	bool IsVisible();
	void SetVisible(bool vis);
	void SetSize(float x, float y, float x2, float y2);
	void SetLayer(int l);
	int GetLayer();

private:

	static const DWORD thisfvf = (D3DFVF_XYZ | D3DFVF_DIFFUSE |D3DFVF_TEX1);
	struct vert
	{
		D3DXVECTOR3 pos;
		DWORD color;
		float tu, tv;
	};

private:

	bool visible;

	D3DXIMAGE_INFO info;
	LPDIRECT3DTEXTURE9 texture;
	LPDIRECT3DVERTEXBUFFER9 vbuf;

	float _x, _y, _x2, _y2;

	int layer;
};


the draw function is being called from the right place and im setting up a correct projection matrix any help would be grateful tnx
Advertisement
1. Of the code posted, nothing looks particularly 'wrong'. But without knowing what the rest of your application is doing, it's difficult to diagnose this kind of thing; there are many, many, many reasons why you can get "nothing is visible" bugs...

2. You say you've set the PROJECTION matrix, but since you're using untransformed vertices, what are your VIEW and WORLD matrices set to?

3. If these textured quads are intended to be used like sprites, D3DFVF_XYZRHW style (aka 'transformed') vertices save a little work since they don't need to go through the transformation pipeline.

4. You set up the texture, but you don't seem to be telling D3D how to apply that texture (i.e. SetTextureStageState()). Those settings may be in a garbage state, or they may be modulating the texture with current light colour which could be black if you haven't set up any D3D lights...

5. DIAGNOSTIC TECHNIQUE: use the debug D3D runtime and check the output from the debugger to see if you get any errors or warnings!

6. DIAGNOSTIC TECHNIQUE: link with D3DX9D.LIB instead of D3DX9.LIB to see if D3DX is unhappy with anything (for example it can't find the texture file in the current path).

7. DIAGNOSTIC TECHNIQUE: where you call IDirect3DDevice9::Clear(), use a clear colour that isn't black so that any black quads drawn on the background that are coming out black are easy to see.

8. DIAGNOSTIC TECHNIQUE: set D3DRS_CULLMODE to D3DCULL_NONE to see if the winding order of your primitive is backwards facing and so causing the primitive to be backface culled.

9. DIAGNOSTIC TECHNIQUE: use PIX, and tools like NVPerfHUD.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Here are some more:

10. DIAGNOSTIC TECHNIQUE: set D3DRS_ZENABLE to false to see if improper coordinates or transformations (including projection) are depth-culling the geometry.

11. DIAGNOSTIC TECHNIQUE: set D3DRS_ALPHABLENDENABLE to false. The geometry may somehow be getting drawn with zero opacity.

12. DIAGNOSTIC TECHNIQUE: set D3DRS_LIGHTING to false in case the geometry is coming out black or invisible. This ties in with 4 and 11.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
thank you

10. DIAGNOSTIC TECHNIQUE: set D3DRS_ZENABLE to false to see if improper coordinates or transformations (including projection) are depth-culling the geometry.


did the trick.

tnx again
Quote:Original post by Misiu
thank you

10. ...

did the trick.

Okay, good. But understand that this is only a temporary measure to help you isolate the problem. I can't imagine you'd want to write a game without the help of the depth-buffer.

The fact that the z-testing is annihilating your geometry suggests a few things to me, depending on the style of your game. Here are some things to consider:

1. Have another look at the initialisation of your projection matrix. In particular, if your near- or far-clipping-planes are set incorrectly, then things are liable to get clipped all over the place (and that's one of the better scenarios).
2. If you are using transformed vertices (as the whole Image2D business would suggest) then double-check the quads' z and rhw components.
3. Ensure that you are clearing the z-buffer with each call you Device.Clear.

There may be more.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
well no messages from the debug dll about any problems


	D3DXMATRIX Ortho2D;		D3DXMATRIX Identity;		D3DXMatrixOrthoOffCenterLH(&Ortho2D, 0.0f, 800.0f, 600.0f, 0.0f, 0.0f, 1.0f);	D3DXMatrixIdentity(&Identity);	DXUTGetD3DDevice()->SetTransform(D3DTS_PROJECTION, &Ortho2D);	DXUTGetD3DDevice()->SetTransform(D3DTS_WORLD, &Identity);	DXUTGetD3DDevice()->SetTransform(D3DTS_VIEW, &Identity);


thats the only ones set

tnx

This topic is closed to new replies.

Advertisement