Jump to content

Recommended Posts

Posted

I am trying to draw in front of the instrument panel (3D) using the depth buffer as a mask to completely avoid writing in/over the cockpit windows.

 

Below is the code I have tried (most recently anyway).

My code is invoked within a XPLMRegisterDrawCallback function. I have tried draw phases: xplm_Phase_FirstCockpit, xplm_Phase_Panel,  xplm_Phase_Gauges and xplm_Phase_LastCockpit.

I have tried different values in the depth buffer (xpDepthBuffer) ranging from 0.999 to 0.001. The larger value is what is needed as the cockpit windows have a value of 1.0 and the panel/gauges are less than 0.999.

 

        XPLMBindTexture2d(gTexture, xplm_Tex_GeneralInterface);    
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

        XPLMSetGraphicsState(0/*Fog*/, 1/*TexUnits*/, 0/*Lighting*/, 0/*AlphaTesting*/, 0/*AlphaBlending*/, 1/*DepthTesting*/, 1/*DepthWriting*/);
       

        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, cfgImageWidth, cfgImageHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, xpDepthBuffer);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cfgImageWidth, cfgImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageBuf);
       
        glPushMatrix();
        {
            float d=0.9991f;

            glBegin(GL_QUADS);
            {
                glTexCoord2f(1, 0.0f); glVertex3f((GLfloat)PanelRight, (GLfloat)PanelBottom, d);    // Bottom Right Of The Texture and Quad
                glTexCoord2f(0, 0.0f); glVertex3f((GLfloat)PanelLeft, (GLfloat)PanelBottom, d);    // Bottom Left Of The Texture and Quad
                glTexCoord2f(0, 1.0f); glVertex3f((GLfloat)PanelLeft, (GLfloat)PanelTop, d);    // Top Left Of The Texture and Quad
                glTexCoord2f(1, 1.0f); glVertex3f((GLfloat)PanelRight, (GLfloat)PanelTop, d);    // Top Right Of The Texture and Quad
            }
            glEnd();
        }
        glPopMatrix();
        glFlush();      

 

I can do this: glReadPixels(0, 0, cfgImageWidth, cfgImageHeight , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT,xpDepthBuffer); to obtain the current depth buffer

values. Then by comparing the returned values to 1.0 and setting the Alpha channel in my image buffer (imageBuf) accordingly, I am able to use ALPHA blending to mask out the cockpit windows.Unfortunately the glReadPixels() function is too slow to be of much use for masking in this manner.

 

Has anyone had success using the depth buffer for drawing over the panel/gauges?

Thanks

Posted

Haven't tried exactly what you're doing, but don't you need to change the depth function? Normally the OpenGL depth test will draw stuff that has depth values lower than what's in the buffer, and it sounds like you're trying to do the opposite. glDepthFunc(GL_GREATER) might be what you need. Remember to put it back when you're done.

Posted

Thanks for your reply. I had tried setting glDepthFunc() prior to my post, along with various depth values. No joy. I assume it is some small detail I am missing, such as the one you suggested. I am new to OpenGL which is a bit of an issue in itself, much to learn/understand.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...