gmurray Posted May 19, 2015 Report Posted May 19, 2015 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 buffervalues. 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 Quote
sundog Posted May 19, 2015 Report Posted May 19, 2015 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. Quote
gmurray Posted May 21, 2015 Author Report Posted May 21, 2015 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. Quote
Ben Russell Posted May 21, 2015 Report Posted May 21, 2015 See https://www.opengl.org/sdk/docs/man/html/glCopyTexSubImage2D.xhtml For a faster glReadPixels Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.