Starsector API
Loading...
Searching...
No Matches
CampaignEngineGlowIndividualEngine.java
Go to the documentation of this file.
1package com.fs.starfarer.api.util;
2
3import java.awt.Color;
4
5import org.lwjgl.opengl.GL11;
6import org.lwjgl.util.vector.Vector2f;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.graphics.SpriteAPI;
10
12
13 protected float angle;
14 protected float length;
15 protected float glowSize;
16 protected float width;
17 protected float flameTexSpanMult = 1f;
18 protected Vector2f offset;
19
20 protected Color fringe;
21 protected Color core;
22 protected Color flameColor;
23 protected FaderUtil fader = new FaderUtil(0f, 1f, 1f);
24
26 protected float texOffset;
27
28
30
31 transient protected SpriteAPI glow;
32 transient protected SpriteAPI flame;
33
34 public CampaignEngineGlowIndividualEngine(float angle, float length, float width, float glowSize,
37 this.angle = angle;
38 this.length = length;
39 this.glowSize = glowSize;
40 this.width = width;
41 this.offset = offset;
42 this.main = main;
43
44 fader.fadeIn();
45
47 }
48
49 protected Object readResolve() {
50 glow = Global.getSettings().getSprite("campaignEntities", "campaign_engine_glow");
51 flame = Global.getSettings().getSprite("campaignEntities", "campaign_engine_flame");
52// flame = Global.getSettings().getSprite("graphics/fx/beam_chunky_fringe.png");
53// flame = Global.getSettings().getSprite("graphics/fx/beamfringe.png");
54// flame = Global.getSettings().getSprite("graphics/fx/beamfringec.png");
55// flame = Global.getSettings().getSprite("graphics/fx/engineglow32.png");
56 return this;
57 }
58
59 public void advance(float amount) {
62
64 while (texOffset < 0) texOffset += 1f;
65 }
66
67
68 public void render(Vector2f center, float facing, float alphaMult) {
69 alphaMult *= fader.getBrightness();
70
71 float f = main.getFlickerMult().getCurr();
72 if (f > 0) {
73 alphaMult *= (1f - flicker.getBrightness() * f);
74 //alphaMult *= flicker.getBrightness() * f;
75 }
76
77 if (alphaMult <= 0) return;
78
79 GL11.glPushMatrix();
80 GL11.glTranslatef(center.x, center.y, 0f);
81 GL11.glRotatef(facing, 0, 0, 1);
82 GL11.glTranslatef(offset.x, offset.y, 0f);
83
84
85 renderFlame(alphaMult);
86 renderGlow(alphaMult);
87
88
89 GL11.glPopMatrix();
90 }
91
92 protected void renderFlame(float alphaMult) {
93 float lengthMult = main.getLengthMult().getCurr();
94 float widthMult = main.getWidthMult().getCurr();
95
96 if (lengthMult <= 0f || widthMult <= 0f || width <= 0f || length <= 0f) return;
97
98 flame.bindTexture();
99
100 Color base = main.getFlameColor().getCurr();
101 if (flameColor != null) base = flameColor;
102 Color dim = Misc.setAlpha(base, 0);
103
104 //System.out.println("FC red: " + base.getRed());
105
106 float w = width * widthMult;
107 float len = length * lengthMult;
108
109// len *= 2f;
110// w *= 1.5f;
111
112 float bit = 0.01f;
113 float fadeInPortion = Math.min(w/2f, len/4f);
114 float fadeInTex = fadeInPortion / len;
115 float flameTexSpan = 1f;
116 //flameTexSpan = len / flame.getWidth();
117
118 flameTexSpan = len / w * 0.25f;
119 //System.out.println("FTX: " + flameTexSpan);
121 //flameTexSpan *= 0.5f;
122 //flameTexSpan *= 2f;
123
124
125 GL11.glEnable(GL11.GL_TEXTURE_2D);
126 GL11.glEnable(GL11.GL_BLEND);
127 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
128
129 float num = 11f;
130 //num = 6f;
131 for (float f = 1f; f <= num; f++) {
132 float b = alphaMult * f / num;
133 float wMult = 1f - ((f - 1f) / (num - 1f));
134 float lMult = f / num;
135 lMult = 0.5f + 0.5f * lMult;
136 //lMult = (float) Math.sqrt(lMult);
137
138 float texPlus = (f - 1f) * 1.0f / num;
139
140 GL11.glBegin(GL11.GL_QUAD_STRIP);
141 Misc.setColor(dim, alphaMult * b);
142 GL11.glTexCoord2f(texOffset + texPlus, 0 + bit);
143 GL11.glVertex2f(0f, -w/2f * wMult);
144 GL11.glTexCoord2f(texOffset + texPlus, 1 - bit);
145 GL11.glVertex2f(0f, w/2f * wMult);
146
147 Misc.setColor(base, alphaMult * b);
148 GL11.glTexCoord2f(texOffset + fadeInTex + texPlus, 0 + bit);
149 GL11.glVertex2f(-fadeInPortion * lMult, -w/2f * wMult);
150 GL11.glTexCoord2f(texOffset + fadeInTex + texPlus, 1 - bit);
151 GL11.glVertex2f(-fadeInPortion * lMult, w/2f * wMult);
152
153 Misc.setColor(dim, alphaMult * b);
154 GL11.glTexCoord2f(texOffset + flameTexSpan + texPlus, 0 + bit);
155 GL11.glVertex2f(-len * lMult, -w/2f * wMult);
156 GL11.glTexCoord2f(texOffset + flameTexSpan + texPlus, 1 - bit);
157 GL11.glVertex2f(-len * lMult, w/2f * wMult);
158 GL11.glEnd();
159 }
160
161 }
162
163
164 protected void renderGlow(float alphaMult) {
165 float w = glowSize;
166 float h = glowSize;
167
168 float glowScale = main.getGlowMult().getCurr();
169 //glowScale = 0.1f;
172
173
174 if (glowScale <= 0f) return;
175
177 if (fringe != null) fringeColor = fringe;
178
180 if (core != null) coreColor = core;
181
182 glow.setColor(fringeColor);
183 glow.setAdditiveBlend();
184
185 glow.setAlphaMult(alphaMult * 0.5f);
186 glow.setSize(w * fringeScale, h * fringeScale);
187 glow.renderAtCenter(0f, 0f);
188
189 glow.setColor(coreColor);
190 //for (int i = 0; i < 5; i++) {
191 for (int i = 0; i < 2; i++) {
192 w *= 0.3f;
193 h *= 0.3f;
194 glow.setSize(w * coreScale, h * coreScale);
195 glow.setAlphaMult(alphaMult * 0.67f);
196 glow.renderAtCenter(0f, 0f);
197 }
198 }
199
200
201 public float getAngle() {
202 return angle;
203 }
204
205 public void setAngle(float angle) {
206 this.angle = angle;
207 }
208
209 public float getLength() {
210 return length;
211 }
212
213 public void setLength(float length) {
214 this.length = length;
215 }
216
217 public float getGlowSize() {
218 return glowSize;
219 }
220
221 public void setGlowSize(float glowSize) {
222 this.glowSize = glowSize;
223 }
224
225 public float getWidth() {
226 return width;
227 }
228
229 public void setWidth(float width) {
230 this.width = width;
231 }
232
234 return offset;
235 }
236
237 public void setOffset(Vector2f offset) {
238 this.offset = offset;
239 }
240
241 public Color getFringe() {
242 return fringe;
243 }
244
245 public void setFringe(Color fringe) {
246 this.fringe = fringe;
247 }
248
249 public Color getCore() {
250 return core;
251 }
252
253 public void setCore(Color core) {
254 this.core = core;
255 }
256
258 return main;
259 }
260
262 this.main = main;
263 }
264
265 public SpriteAPI getGlow() {
266 return glow;
267 }
268
269 public void setGlow(SpriteAPI glow) {
270 this.glow = glow;
271 }
272
274 return fader;
275 }
276
278 return flameColor;
279 }
280
282 this.flameColor = flameColor;
283 }
284
285 public float getFlameTexSpanMult() {
286 return flameTexSpanMult;
287 }
288
290 this.flameTexSpanMult = flameTexSpanMult;
291 }
292
293
294}
295
296
297
298
static SettingsAPI getSettings()
Definition Global.java:51
CampaignEngineGlowIndividualEngine(float angle, float length, float width, float glowSize, Vector2f offset, CampaignEngineGlowUtil main)
static void setColor(Color color)
Definition Misc.java:3927
static Color setAlpha(Color color, int alpha)
Definition Misc.java:1309
SpriteAPI getSprite(String filename)