Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

agent666

Texture Not drawing on some computers

This topic is 5367 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m building a tool for a game that uses D3D. Basically it allows you to add cheaters for the game so that you won''t play them again. I''v had to hook the d3d interface so i can make use of the games use of D3D. Basically i have a function which draws a texture on screen in screen coordinates, it draws the texture on my computer but when i tested it on some other computers, it does not. Heres the function to draw a box with a texture on it:
void DrawTextureBox(float Xpos, float Ypos, float width, float height, LPDIRECT3DTEXTURE8 g_texture, float MaxMagnify)
{
	HRESULT hr;
	unsigned char *Temp_Vertexbuff;
	DWORD OldBlend;
	DWORD OldColorArg1;
	DWORD OldAlphaOp;
	DWORD OldAlphaArg;
	DWORD OldColorOp;

	LPDIRECT3DBASETEXTURE8 Old_Texture;
	
	g_d3d_device->GetTextureStageState(0, D3DTSS_COLOROP, &OldColorOp);
	g_d3d_device->GetTextureStageState(0, D3DTSS_COLORARG1, &OldColorArg1);
	g_d3d_device->GetTextureStageState(0, D3DTSS_ALPHAOP, &OldAlphaOp);
	g_d3d_device->GetTextureStageState(0, D3DTSS_ALPHAARG1, &OldAlphaArg);


	g_d3d_device->SetVertexShader(D3D8T_CUSTOMVERTEX);
    g_d3d_device->SetTextureStageState(0,D3DTSS_COLOROP,   D3DTOP_SELECTARG1);
    g_d3d_device->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);	
    g_d3d_device->SetTextureStageState(0,D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
    g_d3d_device->SetTextureStageState(0,D3DTSS_MINFILTER, D3DTEXF_LINEAR);

	//This enables Alpha Blending
   g_d3d_device->GetRenderState(D3DRS_ALPHABLENDENABLE, &OldBlend);
   g_d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);

   g_d3d_device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
   g_d3d_device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);

	g_d3d_device->GetTexture(0, &Old_Texture);
	g_d3d_device->SetTexture(0, g_texture);
	
	//top left of box
	g_square_vertices[0].color = 0xFFFFFFFF;
	g_square_vertices[0].x = Xpos;
	g_square_vertices[0].y = Ypos;
	g_square_vertices[0].z = 0.0f;
	g_square_vertices[0].rhw = 0.0f;
	g_square_vertices[0].tu = 0.0f;
	g_square_vertices[0].tv = 0.0f;

	//bottom left of box
	g_square_vertices[1].color = 0xFFFFFFFF;
	g_square_vertices[1].x = Xpos;
	g_square_vertices[1].y = Ypos + height;
	g_square_vertices[1].z = 0.0f;
	g_square_vertices[1].rhw = 0.0f;
	g_square_vertices[1].tu = 0.0f;
	g_square_vertices[1].tv = MaxMagnify;

	//top right of box
	g_square_vertices[2].color = 0xFFFFFFFF;
	g_square_vertices[2].x = Xpos + width;
	g_square_vertices[2].y = Ypos;
	g_square_vertices[2].z = 0.0f;
	g_square_vertices[2].rhw = 0.0f;
	g_square_vertices[2].tu = MaxMagnify;
	g_square_vertices[2].tv = 0.0f;

	//bottom right of box
	g_square_vertices[3].color = 0xFFFFFFFF;
	g_square_vertices[3].x = Xpos + width;
	g_square_vertices[3].y = Ypos + height;
	g_square_vertices[3].z = 0.0f;
	g_square_vertices[3].rhw = 0.0f;
	g_square_vertices[3].tu = MaxMagnify;
	g_square_vertices[3].tv = MaxMagnify;

	hr=g_square->Lock(0, 0, &Temp_Vertexbuff, 0);

	memcpy(Temp_Vertexbuff, g_square_vertices, sizeof(g_square_vertices));

	hr=g_square->Unlock();

	g_d3d_device->BeginScene();
	
	g_d3d_device->SetVertexShader(D3D8T_CUSTOMVERTEX); 

	g_d3d_device->SetStreamSource(0, g_square, sizeof(my_vertex));

	g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

	g_d3d_device->EndScene();

	

    g_d3d_device->SetTextureStageState(0,D3DTSS_COLOROP, OldColorOp);	
    g_d3d_device->SetTextureStageState(0,D3DTSS_COLORARG1, OldColorArg1);
	g_d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE,OldBlend);
    g_d3d_device->SetTexture(0, Old_Texture);
	g_d3d_device->SetTextureStageState(0,D3DTSS_ALPHAOP,OldAlphaOp);
    g_d3d_device->SetTextureStageState(0,D3DTSS_ALPHAARG1,OldAlphaArg);

}
 
You''ll notice, anything i change, it restores back for safety of not recking the games graphics. It may also be my texture loading code that may be the fault, so i''ll put that here:
	
	hr=D3DXCreateTextureFromResourceEx(g_d3d_device, //Our Direct3D device
                                     HDll,   //Our ''instance'', NULL uses current
                                     (LPCSTR) ANTIBACK,
									 D3DX_DEFAULT,
									 D3DX_DEFAULT,
									 D3DX_DEFAULT,
									 0,
									 D3DFMT_A8R8G8B8,
									 D3DPOOL_MANAGED, 
                                     D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, 
                                     D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, 
                                     0, NULL, NULL, 
                                     &AntBack);

	 
Is there a SetRenderState that may disable textures from being drawn??? Is there anything wrong with my Texture loading code? Is there any other SetRenderStates i might need to enable?

Share this post


Link to post
Share on other sites
Advertisement
Are you sure it''s finding the textures correctly? The number one cause of "textures work in situation A, but not in situation B" is that you''re running the program in a manner that it has a different working directory, one in which it cannot find the textures.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
The textures are in the programs resource, so it should be able to find it with the D3DXCreateTextureFromResource API. I even checked the retuen value of the API to make sure it was not FAILED, and it seems to load the texture correctly even on computers that don''t display the texture.

Share this post


Link to post
Share on other sites
I bet it renders correctly on an ATI card, hehe

I did a box like that for my UI (see post GeForce vs ATI).
ATI works fine with rhw = 0.0f, but GeForce needs rhw = 1.0f,
both cards work when you set rhw = 1.0f

also :
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

you need to set a FVF for TLVERTEX's

Hope this helps

[edited by - Mythar on March 7, 2004 10:35:26 AM]

Share this post


Link to post
Share on other sites
ok, i got what you meant on the first part, but what do you mean by this:

also :
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

you need to set a FVF for TLVERTEX''s

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!