LCOV - code coverage report
Current view: top level - Core - OOTextureSprite.m (source / functions) Hit Total Coverage
Test: coverxygen.info Lines: 0 2 0.0 %
Date: 2025-05-28 07:50:54 Functions: 0 0 -

          Line data    Source code
       1           0 : /*
       2             : 
       3             : OOTextureSprite.m
       4             : 
       5             : Oolite
       6             : Copyright (C) 2004-2013 Giles C Williams and contributors
       7             : 
       8             : This program is free software; you can redistribute it and/or
       9             : modify it under the terms of the GNU General Public License
      10             : as published by the Free Software Foundation; either version 2
      11             : of the License, or (at your option) any later version.
      12             : 
      13             : This program is distributed in the hope that it will be useful,
      14             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             : GNU General Public License for more details.
      17             : 
      18             : You should have received a copy of the GNU General Public License
      19             : along with this program; if not, write to the Free Software
      20             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
      21             : MA 02110-1301, USA.
      22             : 
      23             : */
      24             : 
      25             : #import "OOTextureSprite.h"
      26             : #import "OOTexture.h"
      27             : #import "OOMaths.h"
      28             : #import "OOMacroOpenGL.h"
      29             : 
      30             : 
      31             : @implementation OOTextureSprite
      32             : 
      33             : - (id)initWithTexture:(OOTexture *)inTexture
      34             : {
      35             :         return [self initWithTexture:inTexture size:[inTexture originalDimensions]];
      36             : }
      37             : 
      38             : 
      39             : - (id)initWithTexture:(OOTexture *)inTexture size:(NSSize)spriteSize
      40             : {
      41             :         if (inTexture == nil)
      42             :         {
      43             :                 [self release];
      44             :                 return nil;
      45             :         }
      46             :         
      47             :         self = [super init];
      48             :         if (self != nil)
      49             :         {
      50             :                 texture = [inTexture retain];
      51             :                 size = spriteSize;
      52             :         }
      53             :         return self;
      54             : }
      55             : 
      56             : 
      57           0 : - (void)dealloc
      58             : {
      59             :         [texture release];
      60             :         
      61             :         [super dealloc];
      62             : }
      63             : 
      64             : - (NSSize)size
      65             : {
      66             :         return size;
      67             : }
      68             : 
      69             : 
      70             : - (void) blitToX:(float)x Y:(float)y Z:(float)z alpha:(float)a
      71             : {
      72             :         OO_ENTER_OPENGL();
      73             :         OOSetOpenGLState(OPENGL_STATE_OVERLAY);
      74             :         
      75             :         a = OOClamp_0_1_f(a);
      76             :         OOGL(glEnable(GL_TEXTURE_2D));
      77             :         OOGL(glColor4f(1.0, 1.0, 1.0, a));
      78             :         
      79             :         // Note that the textured Quad is drawn ACW from the top left.
      80             :         
      81             :         [texture apply];
      82             :         OOGLBEGIN(GL_QUADS);
      83             :                 glTexCoord2f(0.0, 0.0);
      84             :                 glVertex3f(x, y+size.height, z);
      85             :                 
      86             :                 glTexCoord2f(0.0, 1.0);
      87             :                 glVertex3f(x, y, z);
      88             :                 
      89             :                 glTexCoord2f(1.0, 1.0);
      90             :                 glVertex3f(x+size.width, y, z);
      91             :                 
      92             :                 glTexCoord2f(1.0, 0.0);
      93             :                 glVertex3f(x+size.width, y+size.height, z);
      94             :         OOGLEND();
      95             :         
      96             :         OOGL(glDisable(GL_TEXTURE_2D));
      97             :         
      98             :         OOVerifyOpenGLState();
      99             : }
     100             : 
     101             : 
     102             : - (void) blitCentredToX:(float)x Y:(float)y Z:(float)z alpha:(float)a
     103             : {
     104             :         float   xs = x - size.width / 2.0;
     105             :         float   ys = y - size.height / 2.0;
     106             :         [self blitToX:xs Y:ys Z:z alpha:a];
     107             : }
     108             : 
     109             : 
     110             : - (void) blitBackgroundCentredToX:(float)x Y:(float)y Z:(float)z alpha:(float)a
     111             : {
     112             :         // Without distance, coriolis stations would be rendered behind the background image.
     113             :         // Set an arbitrary value for distance, might not be sufficient for really huge ships.
     114             :         float   distance = 512.0f;
     115             :         
     116             :         size.width *= distance; size.height *= distance;
     117             :         [self blitCentredToX:x Y:y Z:z * distance alpha:a];
     118             :         size.width /= distance; size.height /= distance;
     119             : }
     120             : 
     121             : @end

Generated by: LCOV version 1.14