Problem loading image data into IDirect3DTexture9

Started by
0 comments, last by Gage64 14 years ago
I've written a PCX load to go with my MD2 loader, mostly just for practice and all that good stuff. The problem is, I get weird white hilights when I use my custom loader. Here are some screen shots. In this picture, I replaced the image data going into the texture with black


This is what the model looks like textured with my loader using the actual image data

Using D3DXfunction after converting it to PNG

Here is the code to load the data into the texture, I wrote a small win32 image viewer to check if the image data is loaded properly, and it is. So I believe it's something in this loading code >



//create texture
	IDirect3DTexture9* tempTexture = 0;
	HRESULT hr = device->CreateTexture(this->width,this->height,0,D3DUSAGE_DYNAMIC,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&tempTexture,0);

	//assignment pointer
	D3DCOLOR *Ptr;
	unsigned char *tempPtr = 0; // increment pointer
	int count = 0; //index into color data
	

	//lock texture and get ptr
	D3DLOCKED_RECT rect;
	hr = tempTexture->LockRect(0,&rect,0,D3DLOCK_DISCARD);
	tempPtr = (unsigned char*)rect.pBits;	//assign to unsigned char pointer to make pointer arithmetic smooth
	for(unsigned int i = 0; i < this->height; i++)
	{
		
		tempPtr += rect.Pitch;  //move to next line in texture
		Ptr = (D3DCOLOR*)tempPtr;
		for(unsigned int j = 0; j < this->width; j++)
		{
			Ptr[j] = D3DCOLOR_XRGB(this->imageData[count++],this->imageData[count++],this->imageData[count++]);
		}
		
	}


	tempTexture->UnlockRect(0);


	return tempTexture;


--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
Advertisement
Shouldn't tempPtr be incremented after the inner loop?

BTW, you should probably use the managed pool for textures. Also, unless you're writing to the texture at runtime, there's no need for it to be dynamic (BTW, dynamic textures can't be created in the managed pool).

This topic is closed to new replies.

Advertisement