Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to rotate an BMP image with 1 degree precision by using OpenGL and i want to Export the Rotated image & save is as BMP file.

Could anyone please tell me is it possible by using standard functions in OpenGL?
Thanks
Posted
Comments
nv3 18-Jun-13 9:26am    
Did you mean OpenCV instead of OpenGL? If yes, see warpAffine.

1 solution

Most of it can be done in OpenGL.

Loading and saving images isn't an OpenGL function though.

To do this you need to load the bitmap into memory.
Create a destination bitmap in memory.
Set Open GL to render to your destination bitmap.
Apply the original bitmap as a texture to a square mesh.
Rotate the mesh.
Render the mesh.
Save the destination bitmap.

This link describes how to render to a texture.
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/[^]

Note that some OpenGL functions use the GL_RGB parameter.
For 24 bit windows bitmaps, you can use GL_BGR instead, as windows has the Red Green and Blue reversed.
For 32 bit windows bitmaps, use GL_BGRA

These settings allow you to use the bitmap buffers directly, without the need for code that corrects the color order.
 
Share this answer
 
v5
Comments
Balaji_mcr 19-Jun-13 2:11am    
Thank you for your reply @jack
I've tried rendering an Image by making it as a texture to a Quad & i am also able to rotate this image(Quad). But i want to save this rotated image. is it possible? can u refer any link regarding this process?
JackDingler 19-Jun-13 13:20pm    
I updated the solution for you.
Balaji_mcr 20-Jun-13 1:33am    
Thank you for your update@jack
i've used glReadPixels() to read this rotated image as a buffer & i exported it. But it takes too much time....
JackDingler 20-Jun-13 11:58am    
I did a bit of googling on glReadPixels() and that seems to be the way to go.

I also saw that GL_BGR(A) tends to be faster on windows machines than GL_(A)RGB...

When you call glReadPixels() you're asking the CPU to copy memory from the graphics card to your machine's RAM. This will take time.

A suggestion I saw a number of times for applications needing a high framerate is to double buffer so that you're rendering on one FBO and copying to the CPU from another. With each operation you swap FBOs.

If you need even faster performance, perhaps using NVidia Hardware and CUDA could be your solution. In CUDA, your CPU and Graphics card share memory, so there's no need to copy across the bus, to another memory region on read.

Balaji_mcr 21-Jun-13 1:53am    
Thank you for your suggestion @jack.
I'm working on it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900