Archived

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

Alternative to glReadPixels?

This topic is 5995 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

I have writtem a code which copies the actual screen (res 1024 * 768) to a texture by using glReadPixels() then a call to gluScaleImgage() for resizing the image to a power of 2 then a call to glteximage2d() but this seems to be very slow. Is there another way of creating a texture from a screen with a 4:3 aspect ratio at resolutions other then powers of 2 (800 * 600). i put my code i used for it here. void TEXTURE::CreateFromScreen(void) { GLubyte *SimageData; int P2ScreensizeX,P2ScreensizeY; P2ScreensizeX = 256; P2ScreensizeY = 256; tbpp = 24; glGenTextures(1, &ID); glBindTexture(GL_TEXTURE_2D, ID); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); imageData=(GLubyte *)malloc(Width * Height * 3); SimageData=(GLubyte *)malloc(P2ScreensizeX * P2ScreensizeY * 3); glReadPixels(0,0,Width,Height,GL_RGB,GL_UNSIGNED_BYTE,imageData); gluScaleImage(GL_RGB,Width,Height,GL_UNSIGNED_BYTE,imageData,P2ScreensizeX,P2ScreensizeY,GL_UNSIGNED_BYTE,SimageData); if(imageData!=NULL) free(imageData); glGenTextures(1, &ID); glBindTexture(GL_TEXTURE_2D, ID); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,P2ScreensizeX,P2ScreensizeY,0,GL_RGB,GL_UNSIGNED_BYTE,SimageData); if(SimageData!=NULL) free(SimageData); }

Share this post


Link to post
Share on other sites
readpixels shouldnt be that slow but gluscaleimage is perhaps find a quicker algorithm that sacrifices quality for speed

>>I have writtem a code which copies the actual screen (res 1024 * 768) to a texture by using glReadPixels()<<

to copy a part from a screen (or all of it) to a texture use glCopyTexSubImage2D(..) fastest method out there

Share this post


Link to post
Share on other sites