Jump to content
  • Advertisement

Archived

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

Texture Mapping Help

This topic is 6150 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

Hello, I am working on a height map loader, which works fine. However, I am having trouble loading a texture to my 256x256 grid of quads. I am using Direct3d 8.0. The problem is that the texture is distorted SLIGHTLY (i am working on getting a screen shot up) It looks "normal" but the texture is skewed very little on every vertex. Here is the vertex buffer locking code (ignore the part w/ the height map stuff in it)
  
   if( FAILED( g_pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 ) ) )		{return E_FAIL;}
	for( int x=0; x<256; x++ )
	{
	for( int y=0; y<256; y++ )
		{
		pVertices[x*256*4+4*y].position = D3DXVECTOR3( x-5.0f, y+1.0f-5.0f, heightMap[y+1][x] );
		if(y==255 || y==0 || x==0 || x==255) pVertices[x*256*4+4*y].position = D3DXVECTOR3( x-5.0f, y+1.0f-5.0f,0);
         pVertices[x*256*4+4*y].color    = D3DRGB(heightMap[y][x]/255.0f,heightMap[y][x]/255.0f,heightMap[y][x]/255.0f);
         pVertices[x*256*4+4*y].tu       = (float)(x/256);
         pVertices[x*256*4+4*y].tv       = (float)((255-y/256.0)-(1/256.0));



         pVertices[x*256*4+4*y+1].position = D3DXVECTOR3( x+1.0f-5.0f, y+1.0f-5.0f, heightMap[y+1][x+1]);
		 if(y==255 || y==0 || x==0 || x==255) pVertices[x*256*4+4*y+1].position = D3DXVECTOR3( x-5.0f, y+1.0f-5.0f,0);
         pVertices[x*256*4+4*y+1].color    = D3DRGB(heightMap[y][x]/255.0f,heightMap[y][x]/255.0f,heightMap[y][x]/255.0f);
         pVertices[x*256*4+4*y+1].tu       = (float)((x/256.0)+(1/256.0));
         pVertices[x*256*4+4*y+1].tv       = (float)((255-y/256.0)-(1/256.0));



		 pVertices[x*256*4+4*y+2].position = D3DXVECTOR3( x-5.0f, y-5.0f, heightMap[y][x]);
		 if(y==255 || y==0 || x==0 || x==255) pVertices[x*256*4+4*y+2].position = D3DXVECTOR3( x-5.0f, y+1.0f-5.0f,0);
         pVertices[x*256*4+4*y+2].color    = D3DRGB(heightMap[y][x]/255.0f,heightMap[y][x]/255.0f,heightMap[y][x]/255.0f);
         pVertices[x*256*4+4*y+2].tu       = (float)(x/256.0);
         pVertices[x*256*4+4*y+2].tv       = (float)(255-y/256.0);		 



		 pVertices[x*256*4+4*y+3].position = D3DXVECTOR3( x+1.0f-5.0f, y-5.0f, heightMap[y][x+1]);
		 if(y==255 || y==0 || x==0 || x==255) pVertices[x*256*4+4*y+3].position = D3DXVECTOR3( x-5.0f, y+1.0f-5.0f,0);
         pVertices[x*256*4+4*y+3].color    = D3DRGB(heightMap[y][x]/255.0f,heightMap[y][x]/255.0f,heightMap[y][x]/255.0f);
         pVertices[x*256*4+4*y+3].tu       = (float)((x/256.0)+(1/256.0));
         pVertices[x*256*4+4*y+3].tv       = (float)(255-y/256.0);


		}
	}
    g_pVB->Unlock();
  
Can anyone tell me what''s wrong? I think that only one or two verticies per quad (because of only a slight distortion) have the wrong UV coordinates set on them but I can''t tell which ones/how to fix them. Thanks, --Mohotmoz

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!