glReadPixels doesnt work

i used glReadPixels to provide saving of frames in my CAD program.but iam getting nothing. more over i used glGetIntegerv(GL_VIEWPORT,array) but iam getting nothing in that array. i donno what is the problem .
glReadPixels(0,0,array[2],array[3],GL_BGR_EXT,GL_UNSIGNED_BYTE,buffer) is used in my rendering func but iam getting nothing in to that buffer. it is as same as before calling the glReadPixels() function.
is there is any thing that iam missing?

Edit, OK I see what you’re saying now.

Well it looks about right. Have you tried hardwiring the width & height instead of querrying just incase its a problem isolated to that call. It may also be that the viewport is set to some bogus value.

Also make sure your OpenGL context is current when you make the querry and perform the read. You could also try and use array [0] and [1] for the read if you get it working.

[This message has been edited by dorbie (edited 03-03-2004).]

yup dorbie, thanks for the answer . but i already did gave staticc values in height a nd width values in glReadPixels. moreover iam having only one rendering Context so there no more repeated making it current context i think. and get glGetIntegerv() does not work it gives a very large -ve value. anmd i forgot to tell iam Usin MFC. and also i just tried the code from the openGL superBible for that reading the frame buffer. but still there is no use.my disk saving routine is ok its working the only problem is glReadPixels doent do any thing at all!
here is the code that iam using

bool Bitmap::ReadFrameBuffer()
{
long i,j,
bitsize,
width;
GLint myviewport[4];
//GLubyte buffer;
glGetIntegerv(GL_VIEWPORT,myviewport);
myviewport[2]=256;
myviewport[3]=256;
width=myviewport[2]3;
width=(width+3) & ~3;
bitsize = width
myviewport[3];
TRACE0(“in ReadFrameBuffer()”);
bits=(GLubyte
)calloc(bitsize,1);
memset(bits,128,bitsize);
TRACE1(“memrequired for BMP=%d”,bitsize);
if(bits==NULL)
return false;
glFinish();
glPixelStorei(GL_PACK_ALIGNMENT,4);
glPixelStorei(GL_PACK_ROW_LENGTH,0);
glPixelStorei(GL_PACK_SKIP_ROWS,0);
glPixelStorei(GL_PACK_SKIP_PIXELS,0);
glReadPixels(0,0,myviewport[2],myviewport[3],GL_BGR_EXT,GL_UNSIGNED_BYTE,bits);

//ok lets initialize the bitmap header
iHeader.biSize=sizeof(BITMAPINFOHEADER);
iHeader.biWidth=myviewport[2];
iHeader.biHeight=myviewport[3];
iHeader.biPlanes=1;
iHeader.biBitCount=24;
iHeader.biCompression=BI_RGB;
iHeader.biSizeImage=bitsize;
iHeader.biXPelsPerMeter=2952;/*75 DPI*/
iHeader.biYPelsPerMeter=2952;
iHeader.biClrUsed=0;
iHeader.biClrImportant=0;
return true;

}

plz i really want some help! iam waiting !
-indra

oh mighty OpenGl GOD , kindly send a angel to help me with my problem! a angel with answer to my question.

and forgot to tell ! my pixel format in the program is “6” . i donno what does it mean :[
-indra

Please do us a favor

GLubyte* vendor=glGetString(GL_VENDOR);
GLubyte* renderer=glGetString(GL_RENDERER);
printf("Vendor is %s
",vendor);
printf("Renderer is %s
",renderer);

Please insert that into your routine and post the results.

My suspicion is that you might be in software mode (“Microsoft GDI generic”), and don’t have support for the GL_BGR_EXT format.

Your code does a lot of stuff and it’s hard to tell where it fails. Try something simpler, like

GLubyte* read_buffer=(GLubyte*)malloc(100*100*3*sizeof(GLubyte));
glReadPixels(0,0,100,100,GL_RGB,GL_UNSIGNED_BYTE,read_buffer);