Is this a correct way to do this without using any other library?
- Read the bitmap into memory as texture buffer
- Construct a plane which is far behind the current 3D target to make sure the plane covers the whole screen view.
- Map the texture onto this plane
Your correct that the best approach is to draw a full screen quad and texture it. If you do this in orthographic projection it will be easy to draw a quad that exactly fits the view port.
When doing this, you should still perform a clear operation. The reason for this is that the cost of a clear is negligible on POWERVR hardware and it informs the hardware that there is no reason to read the colour of the previous render.
When applying the texture, you should use a texture that exactly matches the resolution of the display (e.g. 640x480 in your case), perform point sampling (you will only ever need to match one texel to one pixel) and disable mipmaps (as you will be point sampling, there is no need to mipmapping).
You should also use as few triangles for your plane (two for a quad) as possible and use VBOs and IBOs so that this information does not have to be repeatedly submitted to the hardware.
You should disable depth writes when drawing this plane and enable them again once the plane has drawn so that objects rendered afterwards (e.g. your rotating object) will draw over the background image.
You should also remember to change your projection matrix from orthographic to whatever your application requires after the plane has been drawn (e.g. perspective) so that the objects in your scene are drawn as intended.Joe2010-10-20 11:53:47
Thank you so much, Joe. <?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Several questions regarding your explanation
- Should the size of the texture image be the power of 2?
- How to disable depth writes when drawing this plane and enable them again once the plane has drawn?
Actually, I am very close to reach my goal now. I am using VBO as you suggested and two triangles to construct the plane. I can see the image has been mapped as the texture of the plane. Before I can do this, I have to resize the image to 512 by 512. Otherwise, the color of the whole view is very strange and distorted.
Now I have one problem left. The image mapped as the texture of the plane is not correct. Currently, I load the image by copying its RGB compoents and convert it via the following formula.
TEX_SIZE = 512
GLuint col = (R<<24) + (G<<16) + (B<<8) + A;
Basically, the above is based on the trainingcourse 04_Texturing in PVR package, which is
/* GLuint* pTexData0 = new GLuint[TEX_SIZE*TEX_SIZE];
However, I found that if I did the same in matlab, the texture defined inside pTexData0 is not the same as I saw when I run the trainingcourse 04_Texturing project. Can you explain why?
Thank you very much for your feedback.
I attached the images in my test (the original image and the image mapped as texture)
I also attached the texture image for trainingcourse 04_Texturing project and the texture I reconstructed in matlab (I failed to upload the images ....)
The two pictures ( (the original image and the image mapped as texture)<?: PREFIX = O /><O:P></O:P>) are located at