How does one rotate a scanned image in openGL?
glRotate() only works with geometric data. Correct?
I've got an image - glDrawPixels() - displayed on my screen which
is slightly off kilter. Is there a way in openGL to rotate the
image slightly?
I've googled the problem, but I get tons of chaff and no wheat.
Something like this:
GLfloat newX = localX * cos(radians) - localY * sin(radians);
GLfloat newY = localX * sin(radians) + localY * cos(radians);
is only good for object vertexes. How about the whole enchilada?
thanks.
I've got an image - glDrawPixels() - displayed on my screen which
is slightly off kilter. Is there a way in openGL to rotate the
image slightly?
I've googled the problem, but I get tons of chaff and no wheat.
Something like this:
GLfloat newX = localX * cos(radians) - localY * sin(radians);
GLfloat newY = localX * sin(radians) + localY * cos(radians);
is only good for object vertexes. How about the whole enchilada?
thanks.
The easiest way would be to use the image as a texture and draw it on a rotated quad.
- Alex Diener
- Alex Diener
Easier, and substantially faster -- DrawPixels is sloooooooooooooow!
Ah yes. But here's the rub. My images are very large and not a power
of 2. Actually the one in question is 2047x1997
Aren't textures limited to something like 1024x1024?
Speed is not a concern as the rotation will be made only once and not
in real time.
I don't suppose Adobe would be will to share some Photoshop rotate
code
of 2. Actually the one in question is 2047x1997
Aren't textures limited to something like 1024x1024?
Speed is not a concern as the rotation will be made only once and not
in real time.
I don't suppose Adobe would be will to share some Photoshop rotate
code
Just to tell you how to actually do it:
// Bind your texure
glRotatef (angle, 0, 0, 1);
glBegin (GL_QUADS);
glTexCoord2f (0, 0); glVertex2f (-10, -10);
glTexCoord2f (1, 0); glVertex2f (10, -10);
glTexCoord2f (1, 1); glVertex2f (10, 10);
glTexCoord2f (0, 1); glVertex2f (-10, 10);
glEnd();
...provided that your projection makes those coordinates visible.
// Bind your texure
glRotatef (angle, 0, 0, 1);
glBegin (GL_QUADS);
glTexCoord2f (0, 0); glVertex2f (-10, -10);
glTexCoord2f (1, 0); glVertex2f (10, -10);
glTexCoord2f (1, 1); glVertex2f (10, 10);
glTexCoord2f (0, 1); glVertex2f (-10, 10);
glEnd();
...provided that your projection makes those coordinates visible.
the texture size limit depends on your video card. ATI cards better than the Rage 128 can do up to 2048x2048, and NVidia cards can do 4096x4096.
ATI cards better than the Rage 128 and NVidia cards also support the EXT_texture_rectangle extension, which lets you use non-power-of-two textures if you can put up with some more restrictions (no mipmaps, no REPEAT, integer texture coordinates)
If you can't put up with those restrictions, load the image into a sub-portion of a larger, power-of-two texture, and only display the relevant section.
If your image is larger than the maximum texture size, split it into several sub-images and draw several quads.
ATI cards better than the Rage 128 and NVidia cards also support the EXT_texture_rectangle extension, which lets you use non-power-of-two textures if you can put up with some more restrictions (no mipmaps, no REPEAT, integer texture coordinates)
If you can't put up with those restrictions, load the image into a sub-portion of a larger, power-of-two texture, and only display the relevant section.
If your image is larger than the maximum texture size, split it into several sub-images and draw several quads.
On the Mac, only the Rage128 limits you to 1024 x 1024, all the rest are 2048 and higher. Also, the Rage128 is the only one that won't allow NPOT (non power of two) textures that I'm aware of. It doesn't really matter anyway since all you have to do is be creative about how you use your textures. You could just as easily break your image up into several smaller textures and put them on quads right next to each other to fake a single seamless image. And yet another thing to be aware of is that you're only limited to NPOT textures for the initial call to glTexImage2D. After that, all you have to do is call glTexSubImage2D to update that texture with a NPOT texture. It can be confusing to wrap your mind around at first, but it's really not that complicated in the end. Rest assured, textured quads is *the* way to go with what you're doing. When I first ran into this same problem a couple years ago, I too found it bizarre that there wasn't a good way to upload directly to a frame buffer. There just isn't. Textured quads is how it's done.
Darn it! I JUST missed OSC. I even previewed and it wasn't there. I can't edit it to delete it with this new forum theme so I guess it'll just have to be a duplicate. Sorry.
Ok, you've convinced me. I can live with 1028x1028 textures until I buy a new Mini or iMac.
Actually, I can also crop or fill the image to a POT. Come on TIGER!
However, just for argument's sake, I'm having trouble visualizing the part about splitting
up the Big image into say 4 smaller ones and then rotating each one. I don't think that
will work. This is obviously not a mathematical proof, but I took and old photo of an ex
girl-friend and cut it into 4 equal parts. 4 rotations was not the same as 1 rotation of the entire photo. However, I could be wrong and it was fun cutting up the photo.
Thanks.
Actually, I can also crop or fill the image to a POT. Come on TIGER!
However, just for argument's sake, I'm having trouble visualizing the part about splitting
up the Big image into say 4 smaller ones and then rotating each one. I don't think that
will work. This is obviously not a mathematical proof, but I took and old photo of an ex
girl-friend and cut it into 4 equal parts. 4 rotations was not the same as 1 rotation of the entire photo. However, I could be wrong and it was fun cutting up the photo.
Thanks.
clearly, you don't rotate each quad around its center. You can, however, perfectly easily position four quads, each rotated, in such a way as to reconstruct the full image.
I just came across this code in google. Seems like it might allow image
rotation of an arbitrarily large image programatically.
http://www.cs.umu.se/~dva95rng/twister/
uses bmp files. My favorite
rotation of an arbitrarily large image programatically.
http://www.cs.umu.se/~dva95rng/twister/
uses bmp files. My favorite
if you don't care about speed
Or just about anything else for that matter
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
OpenGL's model matrix can help you do this without using a lot of math. Notice that Fenris' code makes a quad that is centered at the origin. If you tesselate this quad, you can use the exact same single glRotate command, and each quad will be rotated appropriately. e.g.
Code:
glRotatef (angle, 0, 0, 1);
for(int i=-1;i<=1;i++){
for(int j=-1;j<=1;j++){
// bind texture i,j
glBegin (GL_QUADS);
glTexCoord2f (0, 0); glVertex2f (0+i*5, 0+j*5);
glTexCoord2f (1, 0); glVertex2f (5+i*5, 0+j*5);
glTexCoord2f (1, 1); glVertex2f (5+i*5, 5+j*5);
glTexCoord2f (0, 1); glVertex2f (0+i*5,5+j*5);
glEnd();
}
}
Of course if you are doing this with textures, you'll have to worry about filtering artifacts at the seams between quads. Apple's sample code shows how to do this correctly (usual bloated Apple code warning applies...)
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL Image Textures | mikey | 52 | 19,970 |
Jun 30, 2009 10:42 AM Last Post: AnotherJake |
|
| Cube auto-rotate | sakrist | 2 | 2,625 |
May 5, 2009 03:31 AM Last Post: Ingemar |
|
| Displaying image with OpenGL and DevIL in C? | leRiCl | 13 | 8,219 |
Jan 23, 2007 01:25 PM Last Post: djork |
|
| OpenGL Preferred Image Format (BMP, TIFF, ect) | Justin Brimm | 7 | 4,176 |
Apr 18, 2006 03:28 PM Last Post: arekkusu |
|
| 2D Image Generation & openGL | LWStrike | 2 | 2,892 |
Mar 28, 2006 03:34 PM Last Post: OneSadCookie |
|

