Ejemplo n.º 1
0
Archivo: spfx.c Proyecto: zid/naev
/**
 * @brief Sets the cinematic mode.
 *
 * Should be run at the end of the render loop if needed.
 */
void spfx_cinematic (void)
{
   double hw, hh;

   hw = SCREEN_W/2.;
   hh = SCREEN_H/2.;

   gl_renderRect( -hw, -hh,     SCREEN_W, SCREEN_H*0.2, &cBlack );
   gl_renderRect( -hw,  0.6*hh, SCREEN_W, SCREEN_H*0.2, &cBlack );
}
Ejemplo n.º 2
0
/**
 * @brief System editor custom widget rendering.
 */
static void uniedit_render( double bx, double by, double w, double h, void *data )
{
   (void) data;
   double x,y,r;
   StarSystem *sys;
   int i;

   /* Parameters. */
   map_renderParams( bx, by, uniedit_xpos, uniedit_ypos, w, h, uniedit_zoom, &x, &y, &r );

   /* background */
   gl_renderRect( bx, by, w, h, &cBlack );

   /* Render systems. */
   map_renderSystems( bx, by, x, y, w, h, r, 1 );

   /* Render system names. */
   map_renderNames( x, y, 1 );

   /* Render the selected system selections. */
   for (i=0; i<uniedit_nsys; i++) {
      sys = uniedit_sys[i];
      gl_drawCircleInRect( x + sys->pos.x * uniedit_zoom, y + sys->pos.y * uniedit_zoom,
            1.5*r, bx, by, w, h, &cWhite, 0 );
   }
}
Ejemplo n.º 3
0
Archivo: news.c Proyecto: Arakash/naev
/**
 * @brief Renders a news widget.
 *
 *    @param bx Base X position to render at.
 *    @param by Base Y positoin to render at.
 *    @param w Width of the widget.
 *    @param h Height of the widget.
 */
static void news_render( double bx, double by, double w, double h, void *data )
{
   (void) data;
   int i;
   unsigned int t;
   double y, dt;

   t = SDL_GetTicks();

   /* Calculate offset. */
   if (!news_drag) {
      dt = (double)(t-news_tick)/1000.;
      news_pos += dt * 25.;
   }
   news_tick = t;

   /* Make sure user isn't silly and drags it to negative values. */
   if (news_pos < 0.)
      news_pos += (news_font->h + 5.) * news_nlines + h + 3;

   /* background */
   gl_renderRect( bx, by, w, h, &cBlack );

   /* Render the text. */
   i = (int)(news_pos / (news_font->h + 5.));
   if (i > news_nlines + (int)(h/(news_font->h + 5.)) + 3) {
      news_pos = 0.;
      return;
   }

   /* Get start position. */
   y = news_pos - (i+1) * (news_font->h + 5.) - 10.;

   /* Draw loop. */
   while (i >= 0) {

      /* Skip in line isn't valid. */
      if (i >= news_nlines) {
         i--;
         y += news_font->h + 5.;
         continue;
      }

      gl_printMidRaw( news_font, w-40.,
            bx+10 + (double)SCREEN_W/2., by+y + (double)SCREEN_H/2.,
            &cConsole, news_lines[i] );

      /* Increment line and position. */
      i--;
      y += news_font->h + 5.;
   }

}
Ejemplo n.º 4
0
Archivo: gui_osd.c Proyecto: EVWeb/naev
/**
 * @brief Renders all the OSD.
 */
void osd_render (void)
{
   OSD_t *ll;
   double p;
   int i, j, k, l;
   int w, x;
   const glColour *c;

   /* Nothing to render. */
   if (osd_list == NULL)
      return;

   /* Background. */
   gl_renderRect( osd_x-5., osd_y-(osd_rh+5.), osd_w+10., osd_rh+10, &cBlackHilight );

   /* Render each thingy. */
   p = osd_y-gl_smallFont.h;
   l = 0;
   for (k=0; k<array_size(osd_list); k++) {
      ll = &osd_list[k];
      x = osd_x;
      w = osd_w;

      /* Print title. */
      gl_printMaxRaw( &gl_smallFont, w, x, p, NULL, ll->title );
      p -= gl_smallFont.h + 5.;
      l++;
      if (l >= osd_lines)
         return;

      /* Print items. */
      for (i=0; i<ll->nitems; i++) {
         x = osd_x;
         w = osd_w;
         c = (ll->active == i) ? &cConsole : NULL;
         for (j=0; j<ll->items[i].nchunks; j++) {
            gl_printMaxRaw( &gl_smallFont, w, x, p,
                  c, ll->items[i].chunks[j] );
            if (j==0) {
               w = osd_w - osd_hyphenLen;
               x = osd_x + osd_hyphenLen;
            }
            p -= gl_smallFont.h + 5.;
            l++;
            if (l >= osd_lines)
               return;
         }
      }
   }
}
Ejemplo n.º 5
0
/**
 * @brief Renders a rectangle.
 *
 * @usage gfx.renderRect( 10., 30,. 40., 40., col ) -- Renders a 40 side square at position 10,30 of colour col
 * @usage gfx.renderRect( 10., 30,. 40., 40., col, True ) -- Renders a 40 side empty square at position 10,30 of colour col
 *
 *    @luaparam x X position to render at.
 *    @luaparam y Y position to render at.
 *    @luaparam w Width of the rectangle.
 *    @luaparam h Height of the rectangle.
 *    @luaparam col Colour to use.
 *    @luaparam empty Optional parameter on whether or not it should be empty, defaults to true.
 * @luafunc renderRect( x, y, w, h, col, empty )
 */
static int gfxL_renderRect( lua_State *L )
{
   LuaColour *lc;
   double x,y, w,h;
   int empty;

   /* Parse parameters. */
   x     = luaL_checknumber( L, 1 );
   y     = luaL_checknumber( L, 2 );
   w     = luaL_checknumber( L, 3 );
   h     = luaL_checknumber( L, 4 );
   lc    = luaL_checkcolour( L, 5 );
   empty = lua_toboolean( L, 6 );

   /* Render. */
   if (empty)
      gl_renderRectEmpty( x, y, w, h, &lc->col );
   else
      gl_renderRect( x, y, w, h, &lc->col );

   return 0;
}
Ejemplo n.º 6
0
Archivo: map.c Proyecto: isfos/naev
/**
 * @brief Renders the custom map widget.
 *
 *    @param bx Base X position to render at.
 *    @param by Base Y position to render at.
 *    @param w Width of the widget.
 *    @param h Height of the widget.
 */
static void map_render( double bx, double by, double w, double h, void *data )
{
    (void) data;
    int i,j, n,m;
    double x,y,r, tx,ty, fuel;
    StarSystem *sys, *jsys, *hsys, *lsys;
    glColour *col, c;
    GLfloat vertex[8*(2+4)];
    int sw, sh;

    /* Parameters. */
    r = round(CLAMP(5., 15., 6.*map_zoom));
    x = round((bx - map_xpos + w/2) * 1.);
    y = round((by - map_ypos + h/2) * 1.);

    /* background */
    gl_renderRect( bx, by, w, h, &cBlack );

    /*
     * First pass renders everything almost (except names and markers).
     */
    for (i=0; i<systems_nstack; i++) {
        sys = system_getIndex( i );

        /* check to make sure system is known or adjacent to known (or marked) */
        if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
                && !space_sysReachable(sys))
            continue;

        tx = x + sys->pos.x*map_zoom;
        ty = y + sys->pos.y*map_zoom;

        /* draws the disk representing the faction */
        if (sys_isKnown(sys) && (sys->faction != -1)) {
            sw = gl_faction_disk->sw;
            sh = gl_faction_disk->sw;

            col = faction_colour(sys->faction);
            c.r = col->r;
            c.g = col->g;
            c.b = col->b;
            c.a = 0.7;

            gl_blitTexture(
                gl_faction_disk,
                tx - sw/2, ty - sh/2, sw, sh,
                0., 0., gl_faction_disk->srw, gl_faction_disk->srw, &c );
        }

        /* Draw the system. */
        if (!sys_isKnown(sys) || (sys->nfleets==0)) col = &cInert;
        else if (sys->security >= 1.) col = &cGreen;
        else if (sys->security >= 0.6) col = &cOrange;
        else if (sys->security >= 0.3) col = &cRed;
        else col = &cDarkRed;

        gl_drawCircleInRect( tx, ty, r, bx, by, w, h, col, 0 );

        /* If system is known fill it. */
        if (sys_isKnown(sys) && (sys->nplanets > 0)) {
            /* Planet colours */
            if (!sys_isKnown(sys)) col = &cInert;
            else if (sys->nplanets==0) col = &cInert;
            else col = faction_getColour( sys->faction);

            /* Radius slightly shorter. */
            gl_drawCircleInRect( tx, ty, 0.5*r, bx, by, w, h, col, 1 );
        }

        if (!sys_isKnown(sys))
            continue; /* we don't draw hyperspace lines */

        /* draw the hyperspace paths */
        glShadeModel(GL_SMOOTH);
        col = &cDarkBlue;
        /* first we draw all of the paths. */
        for (j=0; j<sys->njumps; j++) {

            jsys = system_getIndex( sys->jumps[j] );
            if (hyperspace_target != -1)
                hsys = system_getIndex( cur_system->jumps[hyperspace_target] );

            /* Draw the lines. */
            vertex[0]  = x + sys->pos.x * map_zoom;
            vertex[1]  = y + sys->pos.y * map_zoom;
            vertex[2]  = vertex[0] + (jsys->pos.x - sys->pos.x)/2. * map_zoom;
            vertex[3]  = vertex[1] + (jsys->pos.y - sys->pos.y)/2. * map_zoom;
            vertex[4]  = x + jsys->pos.x * map_zoom;
            vertex[5]  = y + jsys->pos.y * map_zoom;
            vertex[6]  = col->r;
            vertex[7]  = col->g;
            vertex[8]  = col->b;
            vertex[9]  = 0.;
            vertex[10] = col->r;
            vertex[11] = col->g;
            vertex[12] = col->b;
            vertex[13] = col->a;
            vertex[14] = col->r;
            vertex[15] = col->g;
            vertex[16] = col->b;
            vertex[17] = 0.;
            gl_vboSubData( map_vbo, 0, sizeof(GLfloat) * 3*(2+4), vertex );
            gl_vboActivateOffset( map_vbo, GL_VERTEX_ARRAY, 0, 2, GL_FLOAT, 0 );
            gl_vboActivateOffset( map_vbo, GL_COLOR_ARRAY,
                                  sizeof(GLfloat) * 2*3, 4, GL_FLOAT, 0 );
            glDrawArrays( GL_LINE_STRIP, 0, 3 );
            gl_vboDeactivate();
        }
        glShadeModel( GL_FLAT );
    }

    /* Now we'll draw over the lines with the new pathways. */
    if (map_path != NULL) {
        lsys = cur_system;
        glShadeModel(GL_SMOOTH);
        col = &cGreen;
        fuel = player->fuel;

        for (j=0; j<map_npath; j++) {
            jsys = map_path[j];
            if (fuel == player->fuel)
                col = &cGreen;
            else if (fuel < 100.)
                col = &cRed;
            else
                col = &cYellow;
            fuel -= 100;

            /* Draw the lines. */
            vertex[0]  = x + lsys->pos.x * map_zoom;
            vertex[1]  = y + lsys->pos.y * map_zoom;
            vertex[2]  = vertex[0] + (jsys->pos.x - lsys->pos.x)/2. * map_zoom;
            vertex[3]  = vertex[1] + (jsys->pos.y - lsys->pos.y)/2. * map_zoom;
            vertex[4]  = x + jsys->pos.x * map_zoom;
            vertex[5]  = y + jsys->pos.y * map_zoom;
            vertex[6]  = col->r;
            vertex[7]  = col->g;
            vertex[8]  = col->b;
            vertex[9]  = 0.;
            vertex[10] = col->r;
            vertex[11] = col->g;
            vertex[12] = col->b;
            vertex[13] = col->a;
            vertex[14] = col->r;
            vertex[15] = col->g;
            vertex[16] = col->b;
            vertex[17] = 0.;
            gl_vboSubData( map_vbo, 0, sizeof(GLfloat) * 3*(2+4), vertex );
            gl_vboActivateOffset( map_vbo, GL_VERTEX_ARRAY, 0, 2, GL_FLOAT, 0 );
            gl_vboActivateOffset( map_vbo, GL_COLOR_ARRAY,
                                  sizeof(GLfloat) * 2*3, 4, GL_FLOAT, 0 );
            glDrawArrays( GL_LINE_STRIP, 0, 3 );
            gl_vboDeactivate();

            lsys = jsys;
        }

        glShadeModel( GL_FLAT );
    }

    /*
     * Second pass - System names
     */
    for (i=0; i<systems_nstack; i++) {
        sys = system_getIndex( i );

        /* Skip system. */
        if (!sys_isKnown(sys) || (map_zoom <= 0.5 ))
            continue;

        tx = x + (sys->pos.x+11.) * map_zoom;
        ty = y + (sys->pos.y-5.) * map_zoom;
        gl_print( &gl_smallFont,
                  tx + SCREEN_W/2., ty + SCREEN_H/2.,
                  &cWhite, sys->name );
    }


    /*
     * Third pass - system markers
     */
    for (i=0; i<systems_nstack; i++) {
        sys = system_getIndex( i );

        /* We only care about marked now. */
        if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED))
            continue;

        /* Get the position. */
        tx = x + sys->pos.x*map_zoom;
        ty = y + sys->pos.y*map_zoom;

        /* Count markers. */
        n  = (sys_isFlag(sys, SYSTEM_CMARKED)) ? 1 : 0;
        n += sys->markers_misc;
        n += sys->markers_cargo;
        n += sys->markers_rush;

        /* Draw the markers. */
        j = 0;
        if (sys_isFlag(sys, SYSTEM_CMARKED)) {
            map_drawMarker( tx, ty, r, n, j, 0 );
            j++;
        }
        for (m=0; m<sys->markers_misc; m++) {
            map_drawMarker( tx, ty, r, n, j, 1 );
            j++;
        }
        for (m=0; m<sys->markers_rush; m++) {
            map_drawMarker( tx, ty, r, n, j, 2 );
            j++;
        }
        for (m=0; m<sys->markers_cargo; m++) {
            map_drawMarker( tx, ty, r, n, j, 3 );
            j++;
        }
    }

    /* Selected planet. */
    if (map_selected != -1) {
        sys = system_getIndex( map_selected );
        gl_drawCircleInRect( x + sys->pos.x * map_zoom, y + sys->pos.y * map_zoom,
                             1.5*r, bx, by, w, h, &cRed, 0 );
    }

    /* Current planet. */
    gl_drawCircleInRect( x + cur_system->pos.x * map_zoom,
                         y + cur_system->pos.y * map_zoom,
                         1.5*r, bx, by, w, h, &cRadar_tPlanet, 0 );
}
Ejemplo n.º 7
0
/**
 * @brief Renders the overlay map.
 *
 *    @param dt Current delta tick.
 */
void ovr_render( double dt )
{
   (void) dt;
   int i, j;
   Pilot **pstk;
   int n;
   double w, h, res;
   double x,y;
   glColour c = { .r=0., .g=0., .b=0., .a=0.5 };

   /* Must be open. */
   if (!ovr_open)
      return;

   /* Player must be alive. */
   if (player_isFlag( PLAYER_DESTROYED ) || (player.p == NULL))
      return;

   /* Default values. */
   w     = SCREEN_W;
   h     = SCREEN_H;
   res   = ovr_res;

   /* First render the background overlay. */
   gl_renderRect( 0., 0., w, h, &c );

   /* Render planets. */
   for (i=0; i<cur_system->nplanets; i++)
      if ((cur_system->planets[ i ]->real == ASSET_REAL) && (i != player.p->nav_planet))
         gui_renderPlanet( i, RADAR_RECT, w, h, res, 1 );
   if (player.p->nav_planet > -1)
      gui_renderPlanet( player.p->nav_planet, RADAR_RECT, w, h, res, 1 );

   /* Render jump points. */
   for (i=0; i<cur_system->njumps; i++)
      if ((i != player.p->nav_hyperspace) && !jp_isFlag(&cur_system->jumps[i], JP_EXITONLY))
         gui_renderJumpPoint( i, RADAR_RECT, w, h, res, 1 );
   if (player.p->nav_hyperspace > -1)
      gui_renderJumpPoint( player.p->nav_hyperspace, RADAR_RECT, w, h, res, 1 );

   /* Render pilots. */
   pstk  = pilot_getAll( &n );
   j     = 0;
   for (i=0; i<n; i++) {
      if (pstk[i]->id == PLAYER_ID) /* Skip player. */
         continue;
      if (pstk[i]->id == player.p->target)
         j = i;
      else
         gui_renderPilot( pstk[i], RADAR_RECT, w, h, res, 1 );
   }
   /* Render the targeted pilot */
   if (j!=0)
      gui_renderPilot( pstk[j], RADAR_RECT, w, h, res, 1 );

   /* Check if player has goto target. */
   if (player_isFlag(PLAYER_AUTONAV) && (player.autonav == AUTONAV_POS_APPROACH)) {
      x = player.autonav_pos.x / res + w / 2.;
      y = player.autonav_pos.y / res + h / 2.;
      gl_renderCross( x, y, 5., &cRadar_hilight );
      gl_printRaw( &gl_smallFont, x+10., y-gl_smallFont.h/2., &cRadar_hilight, "GOTO" );
   }

   /* Render the player. */
   gui_renderPlayer( res, 1 );

   /* Render markers. */
   ovr_mrkRenderAll( res );
}


/**
 * @brief Renders all the markers.
 *
 *    @param res Resolution to render at.
 */
static void ovr_mrkRenderAll( double res )
{
   int i;
   ovr_marker_t *mrk;
   double x, y;

   if (ovr_markers == NULL)
      return;

   for (i=0; i<array_size(ovr_markers); i++) {
      mrk = &ovr_markers[i];

      x = mrk->u.pt.x / res + SCREEN_W / 2.;
      y = mrk->u.pt.y / res + SCREEN_H / 2.;
      gl_renderCross( x, y, 5., &cRadar_hilight );

      if (mrk->text != NULL)
         gl_printRaw( &gl_smallFont, x+10., y-gl_smallFont.h/2., &cRadar_hilight, mrk->text );
   }
}
Ejemplo n.º 8
0
/**
 * @brief Sets the cinematic mode.
 *
 * Should be run at the end of the render loop if needed.
 */
void spfx_cinematic (void)
{
   gl_renderRect( 0., 0.,           SCREEN_W, SCREEN_H*0.2, &cBlack );
   gl_renderRect( 0., SCREEN_H*0.8, SCREEN_W, SCREEN_H,     &cBlack );
}
Ejemplo n.º 9
0
Archivo: naev.c Proyecto: ekrumme/naev
/**
 * @brief Renders the load screen with message.
 *
 *    @param done Amount done (1. == completed).
 *    @param msg Loading screen message.
 */
void loadscreen_render( double done, const char *msg )
{
   glColour col;
   double bx,by, bw,bh;
   double x,y, w,h, rh;

   /* Clear background. */
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


   /* Draw stars. */
   space_renderStars( 0. );

   /*
    * Dimensions.
    */
   /* Image. */
   bw = 512.;
   bh = 512.;
   bx = (SCREEN_W-bw)/2.;
   by = (SCREEN_H-bh)/2.;
   /* Loading bar. */
   w  = gl_screen.w * 0.4;
   h  = gl_screen.h * 0.02;
   rh = h + gl_defFont.h + 4.;
   x  = -w/2.;
   if (SCREEN_H < 768)
      y  = -h/2.;
   else
      y  = -bw/2 - rh - 5.;

   /* Draw loading screen image. */
   if (loading != NULL)
      gl_blitScale( loading, bx, by, bw, bh, NULL );

   /* Draw progress bar. */
   /* BG. */
   col.r = cBlack.r;
   col.g = cBlack.g;
   col.b = cBlack.b;
   col.a = 0.7;
   gl_renderRect( x-2., y-2., w+4., rh+4., &col );
   /* FG. */
   col.r = cDConsole.r;
   col.g = cDConsole.g;
   col.b = cDConsole.b;
   col.a = 0.2;
   gl_renderRect( x+done*w, y, (1.-done)*w, h, &col );
   col.r = cConsole.r;
   col.g = cConsole.g;
   col.b = cConsole.b;
   col.a = 0.7;
   gl_renderRect( x, y, done*w, h, &col );

   /* Draw text. */
   gl_printRaw( &gl_defFont, x + gl_screen.w/2., y + gl_screen.h/2 + 2. + h,
         &cConsole, msg );

   /* Flip buffers. */
   SDL_GL_SwapBuffers();
}