weird SDL Rect handling on SDL module

Rafael Jannone <jannone-bf/[email protected]> Fri, 19 Aug 2005 20:02:22 -0300
Newsgroups gmane.comp.lang.lua.luacheia
Message-ID <[email protected]>
Hi all,

This is my first message on the list, so I apologize if this matter has
been covered before.

Anyway, I'm having a bit of a problem with SDL_FillRect in my code:
everytime I use negative values on the rectangle, the fill occurs with a
1 pixel offset to the left.

So I checked and re-checked on my code, found nothing. Until I came
accross this section on the luacheia SDL module (sdl_module.cpp):

#define /* SDL_Rect* */ glua_getRectTbl(i)  ( glua_getTable(i) ? \
           ( _rect_store.x= (int)(glua_getTable_num("x")+0.5), \
             _rect_store.y= (int)(glua_getTable_num("y")+0.5), \
             _rect_store.w= (int)(glua_getTable_num("w")+0.5), \
             _rect_store.h= (int)(glua_getTable_num("h")+0.5), \
              &_rect_store ) : NULL /*'nil' table*/ )

Which strikes me as odd... could be that the +0.5 offset is causing the
artifact?

Suppose for example x = -1, so the actual int value would end up as 0,
right? (since -1 + 0.5 = -0.5)

I think this might be the source of the problem after all.

What do you guys think?
Thanks in advance,

--
Rafael Jannone


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf