[SDL] 2D with openGL & SDL

Matthias Weigand weigole at gmx.de
Tue Jul 17 02:19:24 PDT 2007


Mike Powell wrote:
> benang at cs.its.ac.id wrote:
>   
>> 1. Performance wise, will this make my application faster or slower? FYI,
>> the intended machine is a VIA EPIA Mini ITX embedded with Linux openSuSE
>> 10.1 as the OS.
>>     
>
> On this point I'm really not sure, but I would guess that, so long as you have a good graphics card, and you keep the sprites in video RAM as textures, it'll probably be faster. Plus, certain types of operations, such as scaling or rotating sprites, will be much faster.
>
>   
I think your graphics chip is a VIA Unichrome Pro. For usual 
applications the 3D functionality of this chip will be faster. As Mike 
said, rotation and scaling is for free. But i've encountered some limits 
with this chip:
lines and points rendered with opengl were very slow on this chip 
(glBegin(GL_LINES)). If you need to draw lines, you should render a thin 
quad.
Also i wasn't able to make use of the multitexture feature, although the 
chip exposes the appropriate extension. Same code worked on every other 
graphics card. If you have to do complex blendings you might have to do 
it by several steps (like you would do now).
But this may have been fixed with new driver versions.

>> 2. Do I need to implement shader languages (I think maybe Cg)?
>>     
>
> Not unless you want to do some pretty fancy special effects. If your game is based entirely on drawing 2D images on top of each other with alpha channels, then just use OpenGL's standard blending modes and you'll be fine.
>
>   
In case of the VIA Unichrome you won't be able to do that, since the 
chip doesn't support any shading language. Maybe Unichrome Pro does.
>> 3. What's the settings for openGL so that the 2D environment looked just
>> like when I blit it directly to an SDL Surface (eg, the viewport, 1 points
>> equals to 1 pixel, etc)?
>>     
>
> Leave the viewport alone unless you actually want to restrict drawing to limited portion of the screen. The standard state of the viewport is the same as the screen/window that the game is drawn into.
>
> For setting it up to have 1 point per pixel, gluOrtho2D() is your friend. Specifically:
>
> glMatrixMode(GL_PROJECTION);
> glLoadIdentity();
> gluOrtho2D(0, width, 0, height);
>
> Where "width" and "height" are the screen resolution.
>
> Note that OpenGL's coordinate system is based in the lower-left corner, not the upper-left corner like you might be used to. I BELIEVE the the call to gluOrtho2D, as I just demonstrated, will flip it vertically so it will map to what you expect. However, no promises on that. If that doesn't work, you can always use the modelview matrix to scale everything by -1.0 on the y axis.
>
>   
>> 4. AFAIK, to add a texture, the width & height of the image should be a
>> power of 2. So how do I make a sprite with width and/or height not of
>> power of 2?
>>     
>
> This was true in the old versions of OpenGL, but I know it's been fixed by OpenGL 2.0. Not sure, offhand, exactly which version made the shift, but if your version is up to date, you should be able to use any texture size. Provided, of course, it's not larger then your implementation's maximum texture size. These days, that's usually either 512 or 1024, so you probably won't have a problem there.
>   
Again, the onboard graphics card might be far away from OpenGL 2.0. I 
suggest to look for the extensions provided by your graphics chip. For 
the use of non-power-of-two-textures OpenGL 2.0 would be great, but the 
extension GL_ARB_texture_rectangle supports it, too (less comfortable 
and minor limits). I think the Unichrome chip doesn't support any of 
these. So you have to preprocess images by yourself or let gluScaleImage 
do it for you on the fly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070717/b2c0cb03/attachment.htm 


More information about the SDL mailing list