Problem setting texture to a square (of vertices)

Started by
7 comments, last by GameDev.net 19 years, 7 months ago
It seems that color of the outer edge of the bitmap is being 'averaged' (blended?) and is spread uniformly over the whole polygon. I know the texture is being loaded correctly because using Draw() with my sprite device renders it correctly, and none of my functions are failing. If someone wants to see code I'll post some, but I seem to remeber seeing this exact problem here about 5+ months ago.
Advertisement
I don't remember much about Direct3D, but at least to bump up your thread:

Are your texture coordinates correctly set?
Does this happen everytime or sometimes only?
Have you enabled some special feature, or are you just simply texturing a quad?
Are all your textures stored in the same file format, maybe a problem in the loader?
[size="2"]I like the Walrus best.
Sounds like your uv's are a little buggered and you've got the texture address mode set to clamp. This smears the edge of the texture over any areas of the face where the uv coordinates are over 1.

You need to make sure that you are setting sensible uvs first. If the texture is set to clamp, then all your uvs must be between 0.0 and 1.0.

A quick test to see if this is actually the case would be to set the texture address mode to wrap.
Thanks for the responces. I'm not using any features as far as I know. Here is where I set the vertices and texture coordinates for the square:
	vertices[0].x=200;	vertices[0].y=200;	texture_coords[0].x=1;	texture_coords[0].y=1;	vertices[1].x=100;	vertices[1].y=200;	texture_coords[1].x=0;	texture_coords[1].y=1;	vertices[2].x=200;	vertices[2].y=100;	texture_coords[2].x=1;	texture_coords[2].y=0;	vertices[3].x=100;	vertices[3].y=100;	texture_coords[0].x=0;	texture_coords[0].y=0;Game->Display.LoadVertexData(vertices,texture_coords,colors,4000);


void DISPLAY::LoadVertexData(D3DXVECTOR3 *coordinates,D3DXVECTOR2 *texture_coordinates,D3DCOLOR *colors,int number_of_vertices){	VOID* pVertices;	if(FAILED(D3DVertexBuffer->Lock(0,0,(void**) &pVertices,D3DLOCK_DISCARD/*entire buffer is overwritten*/)))	{		MessageBox(window,"Failed to lock the vertex buffer!","error!",MB_ICONEXCLAMATION | MB_OK);		return;	}	for(int index=0;index<number_of_vertices;index++)	{		screen_vertices[index].x=coordinates[index].x;		screen_vertices[index].y=coordinates[index].y;		screen_vertices[index].z=coordinates[index].z;		screen_vertices[index].u=coordinates[index].x;		screen_vertices[index].v=coordinates[index].y;//		screen_vertices[index].color=colors[index];		screen_vertices[index].rhw=1.0f;	}	memcpy(pVertices,screen_vertices,sizeof(screen_vertices));	if(FAILED(D3DVertexBuffer->Unlock()))		MessageBox(window,"Failed to unlock the vertex buffer!","error!",MB_ICONEXCLAMATION | MB_OK);}


As for the texture address mode, I'd try setting it to wrap but I dont know how.
I understand what you're saying but it still looks to me like I have 0,0 in the top left (100,100) and 1,1 is correlating to (200,200) top right.

edit: woooooooooooooooops.. i goofed up the index number of the fourth texture coordinate

[Edited by - Unliterate on September 3, 2004 2:27:32 PM]
sorry i was being a complete retard...ignore me

deleted my last post
"Without the 0, alot of big numbers would just sit around looking rather stupid"
ok. silly mistake on your part I believe!

screen_vertices[index].u=coordinates[index].x;screen_vertices[index].v=coordinates[index].y;


should be

screen_vertices[index].u=texture_coordinates[index].x;screen_vertices[index].v=texture_coordinates[index].y;

christ, the fact that i keep making simple mistakes like that is starting to frighten me. thanks tho that was the exact prob. I guess when I was copy/pasting as I added textures to my vertices I forgot to make the change, I looked over that function 10+ times . I cant fathom how i missed that so many times.

now to discover the incredibly obvious typo im making that prevents me from using non-pretransformed vertices (see my post on beginers forum).
No worries. I still do stuff like that and it's my job!

Normally I find stuff like that when I've actually got up to talk to someone about what's wrong. Mid explanation I'll suddenly realise what an idiot I've been and shuffle back to my desk... It happens!

This topic is closed to new replies.

Advertisement