Add bitmap as background for 3D subject

This topic contains 4 replies, has 2 voices, and was last updated by  renaissance 7 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30317

    Hi there:

    I am trying to use a bitmap as the full background of current display (say 640 by 480), while still keeping my rotating 3D target in front of it. What is the best way to implement this design using openGL ES? 

     

    Thank you very much,

     

    renaissance
    #34431

    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

    Thanks,

    Renaissance
    #34432

    Joe Davis
    Member

    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. 640×480 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

    #34433

    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;
    pTexData0[j*TEX_SIZE+i] = col;
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, pTexData0);

     

    Basically, the above is based on the trainingcourse 04_Texturing in PVR package, which is

    glGenTextures(1, &m_uiTexture);
     glBindTexture(GL_TEXTURE_2D, m_uiTexture);

    /* GLuint* pTexData0 = new GLuint[TEX_SIZE*TEX_SIZE];
     for (int i=0; i<TEX_SIZE; i++)
     for (int j=0; j<TEX_SIZE; j++)
     {
      GLuint col = (255L<<24) + ((255L-j*2)<<16) + ((255L-i)<<8) + (255L-i*2);
      if ( ((i*j)/8) % 2 ) col = (GLuint) (255L<<24) + (255L<<16) + (0L<<8) + (255L);
      pTexData0[j*TEX_SIZE+i] = col;
     }
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, pTexData0);
     delete [] pTexData0;

     

    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 ….)

     

    Renaissance

     

    #34434

    The two pictures ( (the original image and the image mapped as texture)< ?: PREFIX = O />) are located at

     

    I also attached the texture image for trainingcourse 04_Texturing project and the texture I reconstructed in matlab

     
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.