PDA

View Full Version : Is 'glDrawPixels' a valid call list command?



jxruan
07-30-2001, 04:56 AM
When a new list is created, will the 'glDrawPixels' be stored in it?

Thank you.

Eric
07-30-2001, 05:06 AM
Yes, it is legal to call glDrawPixels from within a display list.

You can actually also call glReadPixels when compiling a display list but the catch is that this call would be executed immediately instead of being compiled. Here are a few functions that are executed immediately but not compiled into the display list:

glIsList, glGenLists, glDeleteLists, glFeedbackBuffer, glSelectBuffer, glRenderMode, glReadPixels, glPixelStore, glFlush, glFinish, glIsEnabled

As you can see, glDrawPixels is not in there (I took that from MSDN).

Regards.

Eric

jxruan
07-30-2001, 05:24 AM
Thank you.

In fact, what I need to do is to keep the depth buffer and restore it later. The following is my code, but it dosen't work:

//keep the old depth buffer
glGetIntegerv(GL_VIEWPORT, viewport);

m_width = viewport[2];
m_height = viewport[3];
if (m_DepthBuffer == NULL)
m_DepthBuffer = new GLfloat[viewport[2]*viewport[3]];
glReadPixels(0, 0, m_width, m_height, GL_DEPTH_COMPONENT, GL_FLOAT, m_DepthBuffer);

m_nClipList = glGenLists(1);
glNewList(m_nClipList, GL_COMPILE);

GLfloat r, g, b;
myGdiToGlColor(m_Color, r, g, b);
glColor3f(r, g, b);


glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
//...perform some operations that may change the depth buffer


//restore the depth buffer
glDepthMask(GL_TRUE);
//glClear(GL_DEPTH_BUFFER_BIT);
glRasterPos2i(0, 0);
glDrawPixels(m_width, m_height, GL_DEPTH_COMPONENT, GL_FLOAT, m_DepthBuffer);

DFrey
07-30-2001, 05:50 AM
Remember that the raster position is transformed just like any other vertex. So be sure your projection and modelview matrices are properly configured before setting the raster postion.

Eric
07-30-2001, 06:07 AM
Do you actually have to use glRasterPos ? I wouldn't have bothered if I had written this piece of code... Is there any reason why you should use it ?

Now, I can see a potential problem in your code (but it probably does not explain what you are experiencing): if the window is resized and you forget to destroy m_DepthBuffer, its dimensions won't be correct anymore... Say you are running in a 320x200 window. On the first pass, m_DepthBuffer is NULL and is allocated for 320x200. Now someone resizes to 640x480. If you do not destroy m_DepthBuffer and set it to NULL, on the next pass, it won't be reallocated and OpenGL will try to store 640x480 pixels in an array that can contain only 320x200...

Now, when you say "it doesn't work", what do you exactly mean ? (i.e. what are the symptoms ?).

Regards.

Eric

jxruan
07-30-2001, 06:25 AM
I guarantee that it is not a problem about 'm_DepthBuffer'. It must be problem of the raster position. What really confused me is what the coordination of depth buffer is.
Is it the same as color buffer? More frankly,
how will you do when you need to keep the depth buffer for laterly use?

DFrey
07-30-2001, 06:27 AM
You are correct Eric, the raster need not be set since it defaults to (0,0,0,1). However you do have to explicitly set it if it has been changed. But still, even if you were using the default position, wouldn't you still need to ensure the projection and modelview matrices were proper? Or is the raster position only transformed when explicitly set with glRasterPos, i.e does the default position get transformed too? I've written similiar code and always explicitly set the raster position to (0,0,0,1), if nothing else, it does make the code more readable I think.

[This message has been edited by DFrey (edited 07-30-2001).]

Eric
07-30-2001, 06:31 AM
Originally posted by jxruan:
More frankly,
how will you do when you need to keep the depth buffer for laterly use?

There is actually a thread in the Advanced section about this topic:
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/003633.html

Regards.

Eric


[This message has been edited by Eric (edited 07-30-2001).]

Eric
07-30-2001, 06:35 AM
DFrey,

I understand what you mean: it must definitely be clearer to add it (and I am sure it does not cost a lot of CPU cycles http://www.opengl.org/discussion_boards/ubb/wink.gif !).

Actually, I have never tried to understand what the glRasterPos command does... I have just read its man page to have a better idea.

I think I never looked into it because I thought its use would slow down the rendering... Is it a misconception or is it something that was true on older cards ? (or is it still true ?!?).

Regards.

Eric

jxruan
07-30-2001, 06:37 AM
"it doesn't work" means the depth buffer wasn't restored although the 'm_DepthBuffer' contain the correct data of 'old depth buffer'. This is true even when I let all values in 'm_DepthBuffer' equal to 1.0f, which may work the same as "glClear(GL_DEPTH_BUFFER_BIT)".

Eric
07-30-2001, 07:31 AM
Can you e-mail me your source code for checking ?

Regards.

Eric