Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOTextureSprite.m
Go to the documentation of this file.
1/*
2
3OOTextureSprite.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 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- (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{
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
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
#define OO_ENTER_OPENGL()
#define OOGLBEGIN
Definition OOOpenGL.h:253
@ OPENGL_STATE_OVERLAY
Definition OOOpenGL.h:126
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:136
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:135
#define OOGL(statement)
Definition OOOpenGL.h:251
#define OOGLEND
Definition OOOpenGL.h:254
return nil
float y
float x
OOTexture * texture
id initWithTexture:size:(OOTexture *texture,[size] NSSize spriteSize)
NSSize originalDimensions()
Definition OOTexture.m:313
voidpf void uLong size
Definition ioapi.h:134