Albus Dumbledore
Albus Dumbledore

Reputation: 12616

Resizing an image using OpenGL

I'd like to resize an image using OpenGL. I'd prefer it in Java, but C++ is OK, too.

I am really new to the whole thing so here's the process in words as I see it:

  1. load the image as a texture into OGL
  2. set some stuff, regarding state & filtering
  3. draw the texture in different size onto another texture
  4. get the texture data into an array or something

Do you think if it would be faster to use OpenGL and the GPU than using a CPU-based BLIT library?

Thanks!

Upvotes: 3

Views: 4720

Answers (2)

kvark
kvark

Reputation: 5351

Instead of rendering a quad into the destination FBO, you can simply use hardware blit functionality: glBlitFramebuffer. Its arguments are straight forward, but it requires a careful preparation of your source and destination FBO's:

  • ensure FBO's are complete (glCheckFramebufferStatus)
  • set read FBO target and write FBO target independently (glBindFramebuffer)
  • set draw buffers and read buffers (glDraw/ReadBuffers)
  • call glBlitFramebuffer, setting GL_LINEAR filter in the argument

I bet it will be much faster on GPU, especially for large images.

Upvotes: 5

Dr. Snoopy
Dr. Snoopy

Reputation: 56357

Depends, if the images are big, it might be faster using OpenGL. But if it's just doing the resize process and no more processing on the GPU side, then it's not worth it as is very likely that is going to be slower than the CPU.

But if you need to resize the image, and you can implement further processing in OpenGL, then is a worthy idea.

Upvotes: 1

Related Questions