View Full Version : 2D Rendering
Is there a way to render 2D-graphics and 2d-perspective with OpenGL? I want to do it that way because then the graphics are hardware accelerated and I could take advance of alpha blending, realtime scaling and so on...
Besides that I should have the possibility to load free-sized textures without using the power of 2, but I think this depends on the hardware...
07-25-2004, 06:05 AM
non power of 2 textures require use of extensions and likely will only be available on newest cards (e.g GeForce 6), but it is possible.
2d can be done just as well, gluOrtho(...) will setup a 2d view.
Thank you. However I heared that using glOrtho sets up a slow 2D-drawing.. Is that true, or maybe I'm just confusing something...?
07-25-2004, 09:23 AM
nah just the projection matrix is changed to parallel projection and not perspective to my knowledge
shouldnt be any speed differences
07-25-2004, 11:50 PM
it is possible to use the function gluScaleImage() if your texture image hasn't the power of two.
F.e. if your texture image has the size 150x150 you can call
gluScaleImage(GL_RGB, 150, 150, GL_UNSIGNED_BYTE, oldImage, 128, 128, GL_UNSIGNED_BYTE, newImage)
to get a valid texture.
However I have some other questions related to this topic:
To draw images, I wanted to use a textured Quad for most possible speed, however how can I scale the Quad that it exactly fits to the image size? I dont want the image stretched on the quad like it would be blured. oO
And is it possible to manipulate textures after loading? For example I want to implement color keying without using blending or something. It would be nice if I could just run through the image and set a special masking color to an 0-alpha value, to cut it out.
Thank you in advance...
Sorry for some mistakes in my grammar, english isn't my native language ;)
One nice solution for scaling your quads could be to set glOrtho so that vertex coordinates are the same as actual pixel coordinates on your window, say like glOrtho( 0.0,800.0,600.0,0.0,1.0,200.0); for a 800x600 resolution. Then you can just build your quads so that they are exactly the size of the image they have to display and set you texture coordinates as you like. This worked fine and doesn't have big performance issues as far as i know.
Tinkering around texture coordinates can be useful also if you need non-power-of-two things. You can use a big power of two image and pick different non-power parts with texture coordinates.
About masking, i know redbooks speaks about some masking functions, but they can slow you down A LOT. Probably some kind of additive blending would work much better, i never tired anyway! :(
Hope this was helpful!
07-27-2004, 01:33 PM
To do some on-off "color keying" style transparency :
- from your rgb texture, create a rgba one with alpha set to 0.0 if color = color key, 1.0 else (or 0 and 255 if you use integer values).
- use alpha masking :
glEnable ( GL_ALPHA_TEST);
glAlphaFunc( GL_GREATER, 0.5f);
see the doc
That way you don't need blending, sorting, etc.
Thank you very much for all your answers... You really helped me!
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.