Jump to content
  • Advertisement
Sign in to follow this  

texture streching problem

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

hi, im having some trouble getting the texturing of some simple square right the texture is stretching across in a funny way. i think my problem is in the texture coordinates but i'm not sure. the funny things is that im using the same texture as on the ground at the moment and comes out fine. Heres what it looks like. http://img3.imageshack.us/i/oddtexturing.jpg/ as you can see the square with the circles around them are the ones with the problem. heres the code im using to initialize and draw these squares it pretty messy. anyone know why the textures are rendering this way?
#include "global.h"


void RenderTrees(TreeObject* TreesToRender)
	D3DXMATRIX FillerMatrix;
	d3ddev->SetTexture(NULL, TreeTexture);
	d3ddev->SetTransform(D3DTS_WORLD, D3DXMatrixIdentity(&FillerMatrix));
	d3ddev->SetStreamSource(NULL, *TreesToRender->pVertexBufer, NULL, sizeof(vertexStructure));
	HRESULT error3 = d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, TreesToRender->NumberOfTrees * 4, 0, TreesToRender->NumberOfTrees * 2);

TreeObject* InitTrees(void)
	static TreeObject Trees;
	vertexStructure TreeVertexs[40];
	Trees.NumberOfTrees = 10;

	HRESULT error = D3DXCreateTextureFromFileEx(d3ddev, "dirt.bmp", D3DX_DEFAULT, D3DX_DEFAULT, 

	for(int i = 0; i < Trees.NumberOfTrees * 4; i += 4) {
		TreeVertexs.x = i*2;
		TreeVertexs.y = 15;
		TreeVertexs.z = 10;
		TreeVertexs.u = 0;
		TreeVertexs.v = TreeVertexs.z - 10.0f;
		TreeVertexs.colour = 0xffffffff;

		TreeVertexs[i+1].x = TreeVertexs.x + 1;
		TreeVertexs[i+1].y = 15;
		TreeVertexs[i+1].z = 10;
		TreeVertexs[i+1].u = 1;
		TreeVertexs[i+1].v = TreeVertexs[i+1].z - 10.0f;
		TreeVertexs[i+1].colour = 0xffffffff;

		TreeVertexs[i+2].x = TreeVertexs[i+1].x;
		TreeVertexs[i+2].y = 15;
		TreeVertexs[i+2].z = 11;
		TreeVertexs[i+2].u = 1;
		TreeVertexs[i+2].v = TreeVertexs[i+2].z - 10.0f;
		TreeVertexs[i+2].colour = 0xffffffff;

		TreeVertexs[i+3].x = TreeVertexs.x;
		TreeVertexs[i+3].y = 15;
		TreeVertexs[i+3].z = 11;
		TreeVertexs[i+3].u = 0;
		TreeVertexs[i+3].v = TreeVertexs[i+3].z - 10.0f;
		TreeVertexs[i+3].colour = 0xffffffff;

	HRESULT error2 = d3ddev->CreateVertexBuffer((Trees.NumberOfTrees * 4) * sizeof(vertexStructure), NULL, CUSTOMFVF, D3DPOOL_MANAGED, &TempVertexBuffer, NULL);
	void* pVertexBuffer;
	TempVertexBuffer->Lock(0, 0, (void**) &pVertexBuffer, NULL);
	memcpy(pVertexBuffer, TreeVertexs, sizeof(TreeVertexs));

	Trees.pVertexBufer = &TempVertexBuffer;

	short Indices[60];

	for(int i = 0; i < Trees.NumberOfTrees; ++i) {
		Indices[i*6] = i*4;
		Indices[i*6+1] = i*4+1;
		Indices[i*6+2] = i*4+2;
		Indices[i*6+3] = i*4+2;
		Indices[i*6+4] = i*4+3;
		Indices[i*6+5] = i*4;

	static LPDIRECT3DINDEXBUFFER9 TempIndexBuffer;
	d3ddev->CreateIndexBuffer(Trees.NumberOfTrees * 6 * sizeof(short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &TempIndexBuffer, NULL);
	void* pIndexBuffer;
	TempIndexBuffer->Lock(0, 0, (void**) &pIndexBuffer, NULL);
	memcpy(pIndexBuffer, Indices, sizeof(Indices));

	Trees.pIndexBuffer = &TempIndexBuffer;
	return &Trees;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!