Skip to main content
GameDev.net gamedev.net
🔒 Locked

glReadPixels

Started by idinkin Oct 16, 2003 at 7:20 AM 31 replies 1.8k views
Original Post
idinkin
idinkin
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); }
Sometimes movement is a result of a kick in the ass!
ShlomiSteinberg
ShlomiSteinberg
Oh my god!! Cross posting this in the Lounge !!! Haha!! u aer teh funie!!!

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
ShlomiSteinberg
ShlomiSteinberg
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!"
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
idinkin
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]
Sometimes movement is a result of a kick in the ass!
ShlomiSteinberg
ShlomiSteinberg
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]
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
idinkin
idinkin
Can you answer the question??
Sometimes movement is a result of a kick in the ass!
ShlomiSteinberg
ShlomiSteinberg
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!"
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
idinkin
idinkin
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);
}
Sometimes movement is a result of a kick in the ass!
ShlomiSteinberg
ShlomiSteinberg
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]
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
idinkin
idinkin
*name of wothless kid goes here*, you crap poster!
Will you help me?
Sometimes movement is a result of a kick in the ass!
overflowed
overflowed
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.
idinkin
idinkin
I run it on ATI 3d RAGE PRO II!!!!
Sometimes movement is a result of a kick in the ass!
ShlomiSteinberg
ShlomiSteinberg
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!"
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
ShlomiSteinberg
ShlomiSteinberg
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]
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
idinkin
idinkin
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?
Sometimes movement is a result of a kick in the ass!
ShlomiSteinberg
ShlomiSteinberg
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!"
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
idinkin
idinkin
2Shlomi: It does not work...
Sometimes movement is a result of a kick in the ass!
ShlomiSteinberg
ShlomiSteinberg
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]
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
ShlomiSteinberg
ShlomiSteinberg
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!"
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)
idinkin
idinkin
Can anybody post here a working code with glReadPixels?
Sometimes movement is a result of a kick in the ass!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.