Search the Community
Showing results for tags 'Depth buffer and panel draw'.
-
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