From 14fed140c3df436f403742ced3d7a9520ed223f6 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Fri, 28 Jun 2013 13:05:32 +0100
Subject: [PATCH] [Change] A little opengl code cleanup.

---
 src/opengl.c | 24 ++++++++++++++++++------
 src/opengl.h |  5 +++++
 src/player.c | 12 ++++++++++--
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/src/opengl.c b/src/opengl.c
index 8033ab7..cce5504 100644
--- a/src/opengl.c
+++ b/src/opengl.c
@@ -460,7 +460,7 @@ void gl_blitSprite(const glTexture* sprite, const double bx, const double by,
   x = bx - VX(*gl_camera) - sprite->sw/2. + gui_xoff;
   y = by - VY(*gl_camera) - sprite->sh/2. + gui_yoff;
 
-  /* Don't draw if offscreen. */
+  /* Check if inbounds. */
   if((fabs(x) > SCREEN_W/2 + sprite->sw) ||
       (fabs(y) > SCREEN_H/2 + sprite->sh))
     return;
@@ -473,6 +473,23 @@ void gl_blitSprite(const glTexture* sprite, const double bx, const double by,
   gl_blitTexture(sprite, x, y, tx, ty, c);
 }
 
+/* Blit the sprite at pos (blits absolute position). */
+void gl_blitStaticSprite(const glTexture* sprite, const double bx,
+    const double by, const int sx, const int sy, const glColour* c) {
+  
+  double x, y, tx, ty;
+
+  x = bx - (double)SCREEN_W/2.;
+  y = by - (double)SCREEN_H/2.;
+
+  /* Texture coords. */
+  tx = sprite->sw*(double)(sx)/sprite->rw;
+  ty = sprite->sh*(sprite->sy-(double)sy-1)/sprite->rh;
+
+  /* Actual blitting. */
+  gl_blitTexture(sprite, x, y, tx, ty, c); 
+}
+
 /* Like gl_blitSprite but will use the actual direction, for things that */
 /* can just rotate around. */
 void gl_blitRotate(const glTexture* texture,
@@ -485,11 +502,6 @@ void gl_blitRotate(const glTexture* texture,
   x = bx - VX(*gl_camera) - texture->sw/2. + gui_xoff;
   y = by - VY(*gl_camera) - texture->sh/2. + gui_yoff;
 
-  /* Don't draw if offscreen. */
-  if((fabs(x) > SCREEN_W/2 + texture->sw) ||
-      (fabs(y) > SCREEN_H/2 + texture->sh))
-    return;
-
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glRotated(dir, 0., 0., 1.);
diff --git a/src/opengl.h b/src/opengl.h
index 334f232..f32ca4d 100644
--- a/src/opengl.h
+++ b/src/opengl.h
@@ -74,6 +74,11 @@ void gl_freeTexture(glTexture* texture);
 void gl_blitSprite(const glTexture* sprite, const double bx, const double by,
                    const int sx, const int sy, const glColour* c);
 
+/* Blit a sprite, absolute position. */
+void gl_blitStaticSprite(const glTexture* sprite,
+    const double bx, const double by,
+    const int sx, const int sy, const glColour* c);
+
 /* Blits a texture rotated, relative pos. */
 void gl_blitRotate(const glTexture* texture,
     const double bx, const double by,
diff --git a/src/player.c b/src/player.c
index 324afc8..19f9916 100644
--- a/src/player.c
+++ b/src/player.c
@@ -34,6 +34,9 @@
 
 #define START_DATA    "../dat/start.xml"
 
+#define TARGET_WIDTH  128
+#define TARGET_HEIGHT 96
+
 /* Player stuff. */
 Pilot* player = NULL; /* extern in pilot.h */
 static Ship* player_ship = NULL;        /* Temp ship to hold when naming it. */
@@ -640,9 +643,8 @@ void player_render(void) {
   /* Render the targetted pilot. */
   if(j != 0) gui_renderPilot(pilot_stack[j]);
 
-  /* Player. */
+  /* The + sign in the middle of the radar represents the player. */
   glBegin(GL_LINES);
-    /* Player. -- Drawn last. */
     COLOUR(cRadar_player);
     glVertex2d( 0., -3.);
     glVertex2d( 0.,  3.);
@@ -726,7 +728,13 @@ void player_render(void) {
   if(player_target != PLAYER_ID) {
     p = pilot_get(player_target);
 
+    /* Blit the pilot target. */
     gl_blitStatic(p->ship->gfx_target, gui.target.x, gui.target.y, NULL);
+    /* Blit the pilot space image. */
+    /*x = gui.target.x + (TARGET_WIDTH - p->ship->gfx_space->sw)/2.;
+    y = gui.target.y + (TARGET_HEIGHT - p->ship->gfx_space->sh)/2.;
+    gl_blitStaticSprite(p->ship->gfx_space,
+        x, y, p->tsx, p->tsy, NULL);*/
 
     /* Target name. */
     gl_print(NULL, gui.target_name.x, gui.target_name.y,