Sign in to follow this  

glDrawPixels and depth test

This topic is 3096 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I have some trouble when using glDrawPixels. I got a sequence of pairs of inputs. To display them, I want to composite each pair of inputs by calling glDrawPixels twice with depth test enabled. void present() { initImage(); for(all input1 and input2) { prepareOutput(input1, input2); update(); } } A texture is initialized first in initImage() such that I can fill it later with the pixels I got from other calculations. void initImage() { if(!glXQueryExtension(getDisplay(), NULL, NULL)) { NODE_ERROR_STREAM(getParent(), "GLDisplay> no GLX extension!!!" << endl); return false; } glXMakeCurrent(getDisplay(), getWindow(), _ctx); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); char* colorBits = new char[w*h*3]; //texture creation.. glGenTextures(1,&texture); glBindTexture(GL_TEXTURE_2D,texture); glTexImage2D(GL_TEXTURE_2D,0,3,w,h,0,GL_RGB,GL_UNSIGNED_BYTE, colorBits) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); delete[] colorBits; glEnable(GL_DEPTH_TEST); glClearColor(0.0, 0.0, 0.0, 1.0); } void prepareOutput(unsigned char* input1, unsigned char* input2) { glDrawPixels(512,512,GL_RGBA,GL_UNSIGNED_BYTE, input1); glDrawPixels(512,512,GL_RGBA,GL_UNSIGNED_BYTE, input2); //save data to texture using glCopyTexImage2D glBindTexture(GL_TEXTURE_2D,texture); glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,w,h,0); } void resizeGL() { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,w,0,h); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void update() { glFlush(); resizeGL(); glXSwapBuffers(getDisplay(), getWindow()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } The compositing didn't work. Basically the second glDrawPixels didn't bring anything and the drawing was just input1. All glX related stuffs work, they are not the reason for this problem. Is that possible to use glDrawPixels together with depth test at all? Where is my problem in the current implementation? Anyone can help? Thanks in advance!! Shanshan

Share this post


Link to post
Share on other sites
Since the default depth test function is GL_LESS, and I don't see you changing it, only fragments with less depth value that the depth buffer passes the depth test. Equal depth buffer values fails the test.

Since you make two consecutive calls to glDrawPixels, without changing the raster position in between, the depth for the generated fragments will be the same, and so the second image won't be drawn, since the depth would be equal and fail the depth test. Either disable the depth test, set it to GL_LEQUAL which pass for equal depth values as well, or adjust the raster position so the second image is closer to the near clip plane and have a lower depth value.

And just a tip. In initImage, pass 0 as the pointer to glTexImage instead of colorBits if you just want to pre-allocate a texture. You don't have to allocate and delete some temporary junk data just to have a valid pointer. Passing 0 instead allocates the image as normal, but doesn't fill it with data.

Share this post


Link to post
Share on other sites

This topic is 3096 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this