Archived

This topic is now archived and is closed to further replies.

idinkin

glReadPixels

Recommended Posts

I get 205 for red, green and blue after I call glReadPixels although the screen is not gray... I tried to call the function before and after SwapBuffers... What do I do wrong? Here is the function: bool __declspec(dllexport) PrintScreen(CGraphController controller) { FILE *f; GLubyte *buf = new GLubyte[controller.screenWidth * controller.screenHeight * 3]; char *dimensions = new char[20]; glReadPixels(0, controller.screenHeight, controller.screenWidth, controller.screenHeight, GL_RGB, GL_UNSIGNED_BYTE, (void *)buf); if(!(f = fopen("screenie.idg", "w"))) { Log("Can not open file for writing!", __FUNCSIG__); return false; } sprintf(dimensions, "%d %d ", controller.screenWidth, controller.screenHeight); fputs(dimensions, f); fwrite(buf, controller.screenWidth * controller.screenHeight * 3, 1, f); fclose(f); }

Share this post


Link to post
Share on other sites
And you better delete [] ''dimensions'' and ''buf'' or your app will consume 1440020 bytes, 1.3 Mbytes every frame, in case you are calling this per frame... Think about it: 82.4 Mbytes/s (60 fps), isn''t it great...

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
Any body knows what is the problem with my code?
2Shlomi:
How do you know how much bytes my app will consume per frame?

[edited by - idinkin on October 16, 2003 10:36:16 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by idinkin
Any body knows what is the problem with my code?
2Shlomi:
How do you know how much bytes my app will consume per frame?

[edited by - idinkin on October 16, 2003 10:36:16 AM]


In case that your resolution is 800*600 than this code will consume xxx(-> look above <-) MBytes per call...

Your code has many problems like not being written between the [ source ]...[ /source ] tags...


edit: stupid tags...

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

[edited by - shlomisteinberg on October 16, 2003 11:37:58 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by idinkin
Can you answer the question??



Put your code between the [ source ]...[ /source ] tags so I would be able to read it, then I will answer your question....


"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
Oh.. I''m sorry.. Now I remember. You have sight problems!
 bool __declspec(dllexport) PrintScreen(CGraphController controller)
{
FILE *f;
GLubyte *buf = new GLubyte[controller.screenWidth * controller.screenHeight * 3];
char *dimensions = new char[20];
glReadPixels(0, controller.screenHeight, controller.screenWidth, controller.screenHeight,
GL_RGB, GL_UNSIGNED_BYTE, (void *)buf);
if(!(f = fopen("screenie.idg", "w")))
{
Log("Can not open file for writing!", __FUNCSIG__);
return false;
}

sprintf(dimensions, "%d %d ", controller.screenWidth, controller.screenHeight);
fputs(dimensions, f);
fwrite(buf, controller.screenWidth * controller.screenHeight * 3, 1, f);
fclose(f);
}

Share this post


Link to post
Share on other sites
quote:
Original post by idinkin
blablablabla
*worthless code goes here*


You idiot!! Where the spaces/tabs?! This more readable?! YOU BIG DONKEY!!!


edit:
*looks at code without understanding anything*
Of course it doesn't work!! You run it on a GeForce 3 Ti200!! Buy that new FX 5200 64MB (!) and then check that code!!

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

[edited by - shlomisteinberg on October 16, 2003 2:41:19 PM]

Share this post


Link to post
Share on other sites
Check you glReadPixels call. You''re starting the read from the end of the screen (glReadPixels(0, controller.screenHeight...) so all you''re getting is off-screen memory.

And ignore Steinberg.

Share this post


Link to post
Share on other sites
Between shouldn''t you "specify a color buffer as the source for subsequent glReadPixels and glCopyPixels commands" (msdn, ya Microsoft)? I mean glReadBuffer(GL_FRONT / GL_BACK);

For (i)Donkey:
GL_FRONT - Front color buffer
GL_BACK - Back color buffer


"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
quote:
Original post by idinkin
*name of wothless kid goes here*, you crap poster!
Will you help me?



I did. Look up man!! ^^^^^^^^
Oh yes. I forgot, your GeForce 3 is teh brok...


edit: Yes crap posting is teh fun!! It is a side effect of the Lounge...

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

[edited by - shlomisteinberg on October 16, 2003 2:49:35 PM]

Share this post


Link to post
Share on other sites
Ok, I''ll ignore him!
2Steinberg: Be ware I''ll ignore you in school!!

The code is right... The first two parameters of the call is the bottom left corner of the area I want to read pixels from.
Any ideas?

Share this post


Link to post
Share on other sites
quote:
Original post by idinkin
2Steinberg: Be ware I''ll ignore you in school!!




Finnaly!! Yay thanks god!!

btw, did you try my advice?

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
YOU ARE BOTH ARE IDIOTS! JUST LIKE ARIEL SHARON! DIE IN HELL

Share this post


Link to post
Share on other sites
quote:
Original post by idinkin
2Shlomi: It does not work...



Duh, you don't know how to program.... email me that code (NO SDL/GLUT please) and all problems solved in <25.21 minutes, GUARANTED (spelling?)!!!

edit: call me

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

[edited by - shlomisteinberg on October 16, 2003 3:05:54 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
YOU ARE BOTH ARE IDIOTS! JUST LIKE ARIEL SHARON! DIE IN HELL


No politics please...


"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
quote:
Original post by idinkin
Can anybody post here a working code with glReadPixels?



It didn''t work what I told you?!

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
overflowed already told you what is wrong with your call to glReadPixels. The first pair is the start of the buffer, with origin in the lower left corner. That means your starting coordinate (0, screenHeight) is in the upper left corner. Then you''re reding an image that is screenHeight high, ending at coordinate 2*screenHeight. So you''re trying to read from the rectange (0, screenHeight) to (screenWidth, 2*screenHeight), and that is outside the window, which ranges from (0,0) to (screenWidth, screenHeight).

Share this post


Link to post
Share on other sites
quote:
Original post by Brother Bob
overflowed already told you what is wrong with your call to glReadPixels. The first pair is the start of the buffer, with origin in the lower left corner. That means your starting coordinate (0, screenHeight) is in the upper left corner. Then you''re reding an image that is screenHeight high, ending at coordinate 2*screenHeight. So you''re trying to read from the rectange (0, screenHeight) to (screenWidth, 2*screenHeight), and that is outside the window, which ranges from (0,0) to (screenWidth, screenHeight).



This is what I told him, on phone.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
I changed the code but it still does not work... Now the first 3rd part of the screen is black and the two 3rds that remains are gray but with the color (253, 253, 253) ;(

I changed the code as follows:
bool __declspec(dllexport) PrintScreen(CGraphController controller)
{
FILE *f;
GLubyte **buf = new GLubyte*[3];
GLubyte *writebuf = new GLubyte[controller.screenWidth * controller.screenHeight * 3];
buf[0] = new GLubyte[controller.screenWidth * controller.screenHeight];
buf[1] = new GLubyte[controller.screenWidth * controller.screenHeight];
buf[2] = new GLubyte[controller.screenWidth * controller.screenHeight];
char *dimensions = new char[20];

glReadBuffer(GL_BACK);

glReadPixels(0, 0, controller.screenWidth, controller.screenHeight,
GL_RED, GL_UNSIGNED_BYTE, (void *)buf[0]);
glReadPixels(0, 0, controller.screenWidth, controller.screenHeight,
GL_GREEN, GL_UNSIGNED_BYTE, (void *)buf[1]);
glReadPixels(0, 0, controller.screenWidth, controller.screenHeight,
GL_BLUE, GL_UNSIGNED_BYTE, (void *)buf[2]);
GLenum error = glGetError();

if(!(f = fopen("screenie.idg", "w")))
{
Log("Can not open file for writing!", __FUNCSIG__);
return false;
}

for(int i = 0; i < controller.screenWidth * controller.screenHeight; i++)
{
writebuf[i] = buf[0][i];
writebuf[i+1] = buf[1][i];
writebuf[i+2] = buf[2][i];
}

sprintf(dimensions, "%d %d ", controller.screenWidth, controller.screenHeight);
fputs(dimensions, f);
fwrite(writebuf, controller.screenWidth * controller.screenHeight * 3, 1, f);
fclose(f);
delete [] buf;
delete [] writebuf;
}


[edited by - idinkin on October 16, 2003 5:18:06 PM]

Share this post


Link to post
Share on other sites