Sign in to follow this  
Maarten Baert

[D3D9] very strange problem

Recommended Posts

I have created a D3D9 engine for my game, but I have a very strange problem. The program should look like this: But on some computers (not mine) it looks like this: You can download it here: Demo (zip) d3dx9_41.dll (zip) You will only need the DLL if it is not installed already. As you can see in the screenshots, the background and the overlay are not working correctly. I think this is because they use pretransformed vertices. Everything (even rendering (untransformed vertices) to a texture) works correctly, but the lighting seems to be different too. What am I doing wrong? code for drawing the background:
// draw background
{
	
	int i,j,w,h;
	float marquee;
	
	w = intceil(float(window->GetRenderTargetW())/20.0f);
	h = intceil(float(window->GetRenderTargetH())/20.0f);
	
	window->EnableZBuffer(false,false);
	window->EnableLighting(false);
	window->SetCullingMode(DXCULL_NONE);
	stateblock_texturedisable->Apply();
	for(j=0;j<h;++j) {
		for(i=0;i<w;++i) {
			marquee = 2.0f*float(timer)+10.0f*float(i)+10.0f*float(j);
			window->DrawRectangle(2.0f+20.0f*float(i),2.0f+20.0f*float(j),17.0f+20.0f*float(i),17.0f+20.0f*float(j),
DXCOLORARGB(255,255,64+intround(90.0f+90.0f*sin(deg2rad(marquee+0.0f))),0));
			window->DrawRectangle(4.0f+20.0f*float(i),4.0f+20.0f*float(j),15.0f+20.0f*float(i),15.0f+20.0f*float(j),
DXCOLORARGB(255,255,64+intround(90.0f+90.0f*sin(deg2rad(marquee+30.0f))),0));
			window->DrawRectangle(6.0f+20.0f*float(i),6.0f+20.0f*float(j),13.0f+20.0f*float(i),13.0f+20.0f*float(j),
DXCOLORARGB(255,255,64+intround(90.0f+90.0f*sin(deg2rad(marquee+60.0f))),0));
			window->DrawRectangle(8.0f+20.0f*float(i),8.0f+20.0f*float(j),11.0f+20.0f*float(i),11.0f+20.0f*float(j),
DXCOLORARGB(255,255,64+intround(90.0f+90.0f*sin(deg2rad(marquee+90.0f))),0));
		}
	}
	
}
functions used:
void dxWindow::DrawRectangle(float x1, float y1, float x2, float y2, unsigned long color) {
	vertex2D *vertices;
	vertices = (vertex2D*) QueuePrimitive(DXPT_LINELIST,FORMAT_VERTEX2D,sizeof(vertex2D),8);
	if(vertices!=NULL) {
		SETVERTEX2D(vertices[0],x1,y1,0.0f,1.0f,color,0.0f,0.0f);
		SETVERTEX2D(vertices[1],x2,y1,0.0f,1.0f,color,0.0f,0.0f);
		SETVERTEX2D(vertices[2],x2,y1,0.0f,1.0f,color,0.0f,0.0f);
		SETVERTEX2D(vertices[3],x2,y2,0.0f,1.0f,color,0.0f,0.0f);
		SETVERTEX2D(vertices[4],x2,y2,0.0f,1.0f,color,0.0f,0.0f);
		SETVERTEX2D(vertices[5],x1,y2,0.0f,1.0f,color,0.0f,0.0f);
		SETVERTEX2D(vertices[6],x1,y2,0.0f,1.0f,color,0.0f,0.0f);
		SETVERTEX2D(vertices[7],x1,y1,0.0f,1.0f,color,0.0f,0.0f);
	}
}

void* dxWindow::QueuePrimitive(unsigned long _primitivetype , unsigned long _vertexformat, unsigned long _vertexsize, unsigned long vertexcount) {
	void *ptr;
	if(_primitivetype==DXPT_LINESTRIP || _primitivetype==DXPT_TRIANGLESTRIP || _primitivetype==DXPT_TRIANGLEFAN
|| _primitivetype!=primitivetype || _vertexformat!=vertexformat || _vertexsize!=vertexsize) {
		NewVertexFormat(_primitivetype,_vertexformat,_vertexsize);
	}
	ptr = GetVertexBuffer(vertexcount);
	if(ptr!=NULL) {
		switch(_primitivetype) {
			case DXPT_POINTLIST:     primitivecount += vertexcount; break;
			case DXPT_LINELIST:      primitivecount += vertexcount/2; break;
			case DXPT_TRIANGLELIST:  primitivecount += vertexcount/3; break;
			case DXPT_LINESTRIP:     primitivecount += vertexcount-1; break;
			case DXPT_TRIANGLESTRIP: primitivecount += vertexcount-2; break;
			case DXPT_TRIANGLEFAN:   primitivecount += vertexcount-2; break;
		}
	}
	return ptr;
}

void dxWindow::NewVertexFormat(unsigned long _primitivetype, unsigned long _vertexformat, unsigned long _vertexsize) {
	FlushVertices();
	primitivetype = _primitivetype;
	vertexformat = _vertexformat;
	vertexsize = _vertexsize;
	if(vbwritepos%vertexsize!=0) {
		vbreadpos = vbwritepos += vertexsize-vbwritepos%vertexsize;
	}
}

void* dxWindow::GetVertexBuffer(unsigned long vertexcount) {
	unsigned char *ptr;
	if(vbwritepos+vertexcount*vertexsize>vbsize || vbdiscard) {
		FlushVertices();
		vbreadpos = vbwritepos = 0;
		if(vertexcount*vertexsize>vbsize) {
			return NULL;
		}
		if(FAILED(vb->Lock(0,0,&vbptr,D3DLOCK_DISCARD))) {
			return NULL;
		}
		vbdiscard = false;
	} else {
		if(vbptr==NULL) {
			if(FAILED(vb->Lock(0,0,&vbptr,D3DLOCK_NOOVERWRITE))) {
				return NULL;
			}
		}
	}
	ptr = (unsigned char*)vbptr+vbwritepos;
	vbwritepos += vertexcount*vertexsize;
	return ptr;
}

Share this post


Link to post
Share on other sites
1. Have you run your app with the debug runtimes active? Make sure you do this, and look for any warnings or error messages in the debug spew.

2. Run your app with the reference rasterizer active. If it produces correct output, then your code is okay and you probably stumbled across a driver bug. If it produces the bad output...then you've got a bug in your code.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
1. Have you run your app with the debug runtimes active? Make sure you do this, and look for any warnings or error messages in the debug spew.

2. Run your app with the reference rasterizer active. If it produces correct output, then your code is okay and you probably stumbled across a driver bug. If it produces the bad output...then you've got a bug in your code.


Thank you for your fast reply.

1. The program does not produce the bug on my computer, and I can't run the program in debug mode on the other computer.

2. Good idea, I will try that now. The person who reported this problem said he had a 'modified' version of Windows XP, maybe that's the program. If this is a driver problem, what should I do to fix it? Using untransformed vertices and ortho projection instead?

Share this post


Link to post
Share on other sites
Quote:
Original post by Maarten Baert
1. The program does not produce the bug on my computer, and I can't run the program in debug mode on the other computer.


That doesn't really matter. You should still enable the debug runtimes and watch if you're doing something wrong. Even if it produces the correct (from your viewpoint) visible result, you might still be doing something terribly wrong.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this