[Add] Using clipping planes on starmap for better results.

This commit is contained in:
Allanis 2013-04-22 14:30:07 +01:00
parent b156c96662
commit 35bcabdf16
2 changed files with 43 additions and 17 deletions

View File

@ -163,11 +163,9 @@ static void map_render(double bx, double by, double w, double h) {
// Draw the system name.
tx = x + 7. + sys->pos.x * map_zoom;
ty = y - 5. + sys->pos.y * map_zoom;
if((map_zoom >= 1.) && // Can't be tiny.
((tx > bx) && (ty > by) && (ty < by+h-6.))) // Width checking.
gl_printMax(&gl_smallFont, (bx+w)-(tx),
tx + gl_screen.w/2., ty + gl_screen.h/2.,
&cWhite, sys->name);
gl_print(&gl_smallFont,
tx + gl_screen.w/2., ty + gl_screen.h/2.,
&cWhite, sys->name);
// Draw the hyperspace paths.
glShadeModel(GL_SMOOTH);
@ -181,20 +179,17 @@ static void map_render(double bx, double by, double w, double h) {
col = &cRed;
else col = &cDarkBlue;
glBegin(GL_LINE_STRIP);
ACOLOUR(*col, 0.);
tx = x + sys->pos.x * map_zoom;
ty = y + sys->pos.y * map_zoom;
if(!((tx < bx) || (tx > bx + w) || (ty < by) || (ty > by+h)))
ACOLOUR(*col, 0.);
tx = x + sys->pos.x * map_zoom;
ty = y + sys->pos.y * map_zoom;
glVertex2d(tx, ty);
COLOUR(*col);
tx += (systems_stack[sys->jumps[j]].pos.x - sys->pos.x)/2. * map_zoom;
ty += (systems_stack[sys->jumps[j]].pos.y - sys->pos.y)/2. * map_zoom;
if(!((tx < bx) || (tx > bx+w) || (ty < by) || (ty > by+h)))
COLOUR(*col);
tx += (systems_stack[sys->jumps[j]].pos.x - sys->pos.x)/2. * map_zoom;
ty += (systems_stack[sys->jumps[j]].pos.y - sys->pos.y)/2. * map_zoom;
glVertex2d(tx, ty);
ACOLOUR(*col, 0.);
tx = x + systems_stack[sys->jumps[j]].pos.x * map_zoom;
ty = y + systems_stack[sys->jumps[j]].pos.y * map_zoom;
if(!((tx < bx) || (tx > bx+w) || (ty < by) || (ty > by+h)))
ACOLOUR(*col, 0.);
tx = x + systems_stack[sys->jumps[j]].pos.x * map_zoom;
ty = y + systems_stack[sys->jumps[j]].pos.y * map_zoom;
glVertex2d(tx, ty);
glEnd();
}

View File

@ -144,6 +144,8 @@ static void toolkit_renderCust(Widget* cst, double bx, double by);
static void toolkit_renderInput(Widget* inp, double bx, double by);
static void toolkit_drawOutline(double x, double y, double w,
double h, double b, glColour* c, glColour* lc);
static void toolkit_clip(double x, double y, double w, double h);
static void toolkit_unclip(void);
static void toolkit_drawRect(double x, double y, double w, double h,
glColour* c, glColour* lc);
// Dialogues..
@ -627,6 +629,32 @@ static void toolkit_drawRect(double x, double y, double w, double h,
glEnd();
}
// Set up 2d clipping planes around a rectangle.
static void toolkit_clip(double x, double y, double w, double h) {
GLdouble ctop[4] = { 0., 1., 0., -y };
GLdouble cbot[4] = { 0., -1., 0., y+h };
GLdouble clef[4] = { 1., 0., 0., -x };
GLdouble crig[4] = { -1., 0., 0, x+w };
glClipPlane(GL_CLIP_PLANE0, ctop);
glClipPlane(GL_CLIP_PLANE1, cbot);
glClipPlane(GL_CLIP_PLANE2, clef);
glClipPlane(GL_CLIP_PLANE3, crig);
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
}
static void toolkit_unclip(void) {
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
}
// Render a window.
static void window_render(Window* w) {
int i;
@ -984,7 +1012,10 @@ static void toolkit_renderCust(Widget* cst, double bx, double by) {
toolkit_drawOutline(x-1, y, cst->w+1, cst->h+1, 1.,
toolkit_colDark, NULL);
}
toolkit_clip(x+1, y+1, cst->w, cst->h);
(*cst->dat.cst.render) (x, y, cst->w, cst->h);
toolkit_unclip();
}
// Render an input widget.