Jump to content
  • Advertisement
Sign in to follow this  

Problem loading image data into IDirect3DTexture9

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

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