Tuesday, March 10, 2009

Weird texture mapping on Direct3D Mobile

Well, full screen video rendering is necessary on mobile phone-based AR. So, I tried full screen texture mapping with an image file. It is quite simple and works well on emulator as I expected.

However, it shows weird results on my device as shown below. The texture does not occupy the entire screen. It seems that the texture coordinates are wrong. But I used the same code without any changes.

The same code shows different results on the emulator and the device. What is the problem ??
I digged this few hours and finally I found what I did is a little bit wrong when I create texture object.

When I create my texture for background, I wrote the code as below:

&m_pBGTexture) ;

The parameters MY_IMG_WIDTH and MY_IMG_HEIGHT are 320 and 240, respectively. The function D3DMXCreateTexture automatically change the texture size when the width and height paramters are not 2^n. Thus, my texture's dimensions become (512,256) internally.
When I update the texture data in the rectangle (0,0)~(320,240) area, the remaining region in (512,256) of the texture still have no data (black). Thus, when I draw a quad using texture coordinates from 0 to 1, the entire texture (512,256) is mapped on the quad. Consequently, I see the squeezed image on my device's screen. By changing the texture coordinates of the vertices of the quad, my problem is solved now.

I'm not sure why it works well on the emulator. Maybe the emulator supports rectangular texture dimensions, not 2^n ?

No comments:

Post a Comment