OpenGL - copy texture from a screen smaller than this screen

I'm trying to grab the screen onto a texture with a lower resolution than the screen itself (to bring it back to the screen and create a blur / bloom effect) and it doesn't work well enough. I understand that mipmaps can be used to do this, but I just cannot get the correct command sequence to work.

My current code:

width=1024;
height=1024;

glGenTextures(1, &texture);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,  GL_MODULATE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, width, height, 0);

// code for rendering the screen back on goes here

      

0


a source to share


1 answer


You cannot capture and downdraft in one go. You must first capture the full screen on a larger texture, and then the mipmaps must be generated, if auto mipmaps are enabled then you can render them again with this texture so that you match the mipmap level exactly.

This will look ugly, however, since auto mipmapgeneration usually uses a box filter.



What I would do is set up some FBOs (Frame Buffer Objects) and GLSL shaders. This gives you finer control over all stages:

  • create original image in texture
  • apply some nice gaussian low pass filtering
  • mix filtering with original image into frame buffer
+2


a source







All Articles