# rescaling areas

• 02-27-2006
hannibar
rescaling areas
I'm making a gui, in which you can (basically) create windows, and areas. Areas are just 'areas' inside the window, in which you can draw. Each area is defined by its drawArea, which is calculated like this :

Code:

```void getDrawArea(Area* a, Rect *area){         Window *win;         win = a->parentWindow;         area->x = a->bottomLeftPoint->x;         area->y = a->bottomLeftPoint->y;         area->w = a->topRightPoint->x - area->x;         area->h = a->topRightPoint->y - area->y;         if (a->drawEdges){                 int w = a->edgeWidth;                 area->x = area->x + w;                 area->y = area->y + w;                 area->w = area->w - 2*w;                 area->h = area->h - 2*w;         } }```
The problem happens when I want to rescale the window. When the window is rescaled, a scalefactor is calculated like this :
Code:

```getClientRectCoords(win, clientRect); scalex = (double)(clientRect->w) / (double)(clientRectOrig->w); scaley = (double)(clientRect->h) / (double)(clientRectOrig->h);```
When I rescale the window (and so also the areas), I want the width of the areaEdges to remain the same, so I replace the getDrawArea() function by this :
Code:

```void getDrawArea(Area*a, Rect *area){         Window *win;         win = a->parentWindow;         area->x = a->bottomLeftPoint->x * scalex;         area->y = a->bottomLeftPoint->y * scaley;         area->w = a->topRightPoint->x - area->x * scalex;         area->h = a->topRightPoint->y - area->y * scaley;         if (a->drawEdges){                 int w = a->edgeWidth;                 area->x = area->x + w;                 area->y = area->y + w;                 area->w = area->w - 2*w;                 area->h = area->h - 2*w;         } }```
Now the problem is that there are sometimes small spaces between the drawn areas. It looks like a rounding error, but I don't know how it is caused. Can someone help me on this ?

An example of a wrongly resized window can be found here :
original : http://users.pandora.be/willem.packet1/original.jpg
wrongly resized : http://users.pandora.be/willem.packet1/resized.jpg
The black stripes is where it went wrong.

In case it is needed, here is a part of the drawing routine :
Code:

```void drawAreaDefault(int areaHandle){         Area*a;         Window *win;         Color *c;         Rect area;         int x, y, w, h;         a = getAreaFace(areaHandle);         win = a->parentWindow;         getArea(a, &area);         x = area.x;         y = area.y;         w = area.w;         h = area.h;         c = a->backGroundColor;         glViewport(x, y, w, h);         glScissor(x, y, w, h);         glMatrixMode (GL_PROJECTION);         glLoadIdentity();         glOrtho(0, w, 0, h, -1, 1);         glMatrixMode (GL_MODELVIEW);         glLoadIdentity();         glEnable(GL_BLEND);         glColor4f(c->r, c->g, c->b, c->a);         glBegin(GL_QUADS);                 glVertex2i(0, 0);                 glVertex2i(0, h);                 glVertex2i(w, h);                 glVertex2i(w, 0);         glEnd();         glDisable(GL_BLEND); } void drawAreaEdgesDefault(int areaHandle){         Area*a;         Window *win;         Color *c;         Rect area;         int x, y, w, h, width;         a = getArea(areaHandle);         win = a->parentWindow;         c = a->parent->edgeColor;         width = a->edgeWidth;         getDrawArea(a, &area);         x = area.x - width;         y = area.y - width;         w = area.w + width + width;         h = area.h + width + width;         glViewport(x, y, w, h);         glScissor(x, y, w, h);         glMatrixMode (GL_PROJECTION);         glLoadIdentity();         glOrtho(0, w, 0, h, -1, 1);         glMatrixMode (GL_MODELVIEW);         glLoadIdentity();         //draws the edges as 4 rectangles         glColor3f(c->r, c->g, c->b);         glBegin(GL_QUADS);                 glVertex2i(0, 0);                 glVertex2i(0, h);                 glVertex2i(width, h);                 glVertex2i(width, 0);                 glVertex2i(w - width, 0);                 glVertex2i(w - width, h);                 glVertex2i(w, h);                 glVertex2i(w, 0);                 glVertex2i(0, 0);                 glVertex2i(0, width);                 glVertex2i(w, width);                 glVertex2i(w, 0);                 glVertex2i(0, h - width);                 glVertex2i(0, h);                 glVertex2i(w, h);                 glVertex2i(w, h - width);         glEnd();         //to give the edges a more '3d look'         glLineWidth(1.0f);         glBegin(GL_LINES);                 glColor3f(c->r + 0.1f, c->g + 0.1f, c->b + 0.1f);                 glVertex2i(width - 1, width - 1);                 glVertex2i(width - 1, h - width + 1);                 glVertex2i(width - 1, width - 1);                 glVertex2i(w - width + 1, width - 1);                 glColor3f(c->r - 0.1f, c->g - 0.1f, c->b - 0.1f);                 glVertex2i(w - width, width - 1);                 glVertex2i(w - width, h - width + 1);                 glVertex2i(width - 1, h - width);                 glVertex2i(w - width + 1, h - width);         glEnd(); }```
• 02-28-2006
dwks
You might want to try posting this in the Game Programming forum (or asking a moderator to move it there).

I don't know much OpenGL, but I do know that you will get rounding errors if you just pass a double to a function that expects an int. Try this rounding code:
Code:

```void function(int x); double d = something; function((int)(d+.5));```
• 02-28-2006
swoopy
>scalex = (double)(clientRect->w) / (double)(clientRectOrig->w);
>scaley = (double)(clientRect->h) / (double)(clientRectOrig->h);
Are scalex and scaley declared as doubles?