Sign in to follow this  

Problem loading image data into IDirect3DTexture9

Recommended Posts

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
	unsigned char *tempPtr = 0; // increment pointer
	int count = 0; //index into color data

	//lock texture and get ptr
	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++]);


	return tempTexture;

Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this