Merge pull request #36 from bkuker/kruland-integration-stickers
Sticker decal mode & decal improvements
This commit is contained in:
commit
fa58cb6338
BIN
core/resources/datafiles/examples/Sticker Decals.ork
Normal file
BIN
core/resources/datafiles/examples/Sticker Decals.ork
Normal file
Binary file not shown.
@ -741,6 +741,7 @@ AppearanceCfg.lbl.texture.repeat = Repeat:
|
|||||||
TextureWrap.Repeat = Repeat
|
TextureWrap.Repeat = Repeat
|
||||||
TextureWrap.Mirror = Repeat & Mirror
|
TextureWrap.Mirror = Repeat & Mirror
|
||||||
TextureWrap.Clamp = Clamp Edge Pixels
|
TextureWrap.Clamp = Clamp Edge Pixels
|
||||||
|
TextureWrap.Sticker = Sticker
|
||||||
|
|
||||||
! RocketConfig
|
! RocketConfig
|
||||||
RocketCfg.lbl.Designname = Design name:
|
RocketCfg.lbl.Designname = Design name:
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import net.sf.openrocket.util.Coordinate;
|
|||||||
public class Decal {
|
public class Decal {
|
||||||
|
|
||||||
public static enum EdgeMode {
|
public static enum EdgeMode {
|
||||||
REPEAT("TextureWrap.Repeat"), MIRROR("TextureWrap.Mirror"), CLAMP("TextureWrap.Clamp");
|
REPEAT("TextureWrap.Repeat"), MIRROR("TextureWrap.Mirror"), CLAMP("TextureWrap.Clamp"), STICKER("TextureWrap.Sticker");
|
||||||
private final String transName;
|
private final String transName;
|
||||||
EdgeMode(final String name){
|
EdgeMode(final String name){
|
||||||
this.transName = name;
|
this.transName = name;
|
||||||
|
|||||||
@ -249,14 +249,7 @@ public class AppearancePanel extends JPanel {
|
|||||||
{ // Color
|
{ // Color
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.color.Color")));
|
add(new JLabel(trans.get("AppearanceCfg.lbl.color.Color")));
|
||||||
//mDefault.addEnableComponent(colorButton, false);
|
//mDefault.addEnableComponent(colorButton, false);
|
||||||
colorButton.setEnabled(ab.getImage() == null);
|
|
||||||
add(colorButton);
|
add(colorButton);
|
||||||
ab.addChangeListener(new StateChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void stateChanged(EventObject e) {
|
|
||||||
colorButton.setEnabled(ab.getImage() == null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Scale
|
{ // Scale
|
||||||
|
|||||||
@ -17,12 +17,39 @@ import net.sf.openrocket.rocketcomponent.Transition;
|
|||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.Color;
|
import net.sf.openrocket.util.Color;
|
||||||
|
|
||||||
public class FigureRenderStrategy extends RenderStrategy {
|
public class FigureRenderer extends RocketRenderer {
|
||||||
private final float[] color = new float[4];
|
private final float[] color = new float[4];
|
||||||
|
|
||||||
public FigureRenderStrategy() {
|
public FigureRenderer() {
|
||||||
super(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(GLAutoDrawable drawable) {
|
||||||
|
super.init(drawable);
|
||||||
|
|
||||||
|
GL2 gl = drawable.getGL().getGL2();
|
||||||
|
|
||||||
|
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,
|
||||||
|
new float[] { 0,0,0 }, 0);
|
||||||
|
|
||||||
|
float amb = 0.3f;
|
||||||
|
float dif = 1.0f - amb;
|
||||||
|
float spc = 1.0f;
|
||||||
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT,
|
||||||
|
new float[] { amb, amb, amb, 1 }, 0);
|
||||||
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE,
|
||||||
|
new float[] { dif, dif, dif, 1 }, 0);
|
||||||
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR,
|
||||||
|
new float[] { spc, spc, spc, 1 }, 0);
|
||||||
|
|
||||||
|
gl.glEnable(GLLightingFunc.GL_LIGHT1);
|
||||||
|
gl.glEnable(GLLightingFunc.GL_LIGHTING);
|
||||||
|
gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
|
||||||
|
|
||||||
|
gl.glEnable(GLLightingFunc.GL_NORMALIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDrawn(RocketComponent c) {
|
public boolean isDrawn(RocketComponent c) {
|
||||||
@ -45,11 +72,12 @@ public class FigureRenderStrategy extends RenderStrategy {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HashMap<Class<?>, Color> defaultColorCache = new HashMap<Class<?>, Color>();
|
private static final HashMap<Class<?>, Color> defaultColorCache = new HashMap<Class<?>, Color>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
|
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
||||||
|
|
||||||
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
|
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
|
||||||
Color figureColor = c.getColor();
|
Color figureColor = c.getColor();
|
||||||
if (figureColor == null) {
|
if (figureColor == null) {
|
||||||
@ -90,36 +118,7 @@ public class FigureRenderStrategy extends RenderStrategy {
|
|||||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
|
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
|
||||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0);
|
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0);
|
||||||
|
|
||||||
}
|
cr.renderGeometry(gl, c);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postGeometry(GL2 gl, RocketComponent c, float alpha) {
|
|
||||||
//Nothing to do here
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(GLAutoDrawable drawable) {
|
|
||||||
GL2 gl = drawable.getGL().getGL2();
|
|
||||||
|
|
||||||
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,
|
|
||||||
new float[] { 0,0,0 }, 0);
|
|
||||||
|
|
||||||
float amb = 0.3f;
|
|
||||||
float dif = 1.0f - amb;
|
|
||||||
float spc = 1.0f;
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT,
|
|
||||||
new float[] { amb, amb, amb, 1 }, 0);
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE,
|
|
||||||
new float[] { dif, dif, dif, 1 }, 0);
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR,
|
|
||||||
new float[] { spc, spc, spc, 1 }, 0);
|
|
||||||
|
|
||||||
gl.glEnable(GLLightingFunc.GL_LIGHT1);
|
|
||||||
gl.glEnable(GLLightingFunc.GL_LIGHTING);
|
|
||||||
gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
|
|
||||||
|
|
||||||
gl.glEnable(GLLightingFunc.GL_NORMALIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getShine(RocketComponent c) {
|
private static int getShine(RocketComponent c) {
|
||||||
@ -15,54 +15,45 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc;
|
|||||||
import net.sf.openrocket.appearance.Appearance;
|
import net.sf.openrocket.appearance.Appearance;
|
||||||
import net.sf.openrocket.appearance.Decal;
|
import net.sf.openrocket.appearance.Decal;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.startup.Application;
|
|
||||||
import net.sf.openrocket.util.Color;
|
import net.sf.openrocket.util.Color;
|
||||||
|
|
||||||
import com.jogamp.opengl.util.texture.Texture;
|
import com.jogamp.opengl.util.texture.Texture;
|
||||||
import com.jogamp.opengl.util.texture.TextureData;
|
import com.jogamp.opengl.util.texture.TextureData;
|
||||||
import com.jogamp.opengl.util.texture.TextureIO;
|
import com.jogamp.opengl.util.texture.TextureIO;
|
||||||
|
|
||||||
public class RealisticRenderStrategy extends RenderStrategy {
|
public class RealisticRenderer extends RocketRenderer {
|
||||||
|
|
||||||
private final float[] colorBlack = { 0, 0, 0, 1 };
|
private final float[] colorBlack = { 0, 0, 0, 1 };
|
||||||
|
private final float[] colorClear = { 0, 0, 0, 0 };
|
||||||
|
private final float[] colorWhite = { 1, 1, 1, 1 };
|
||||||
private final float[] color = new float[4];
|
private final float[] color = new float[4];
|
||||||
private static final LogHelper log = Application.getLogger();
|
|
||||||
|
|
||||||
private boolean needClearCache = false;
|
private boolean needClearCache = false;
|
||||||
private Map<String, Texture> oldTexCache = new HashMap<String, Texture>();
|
private Map<String, Texture> oldTexCache = new HashMap<String, Texture>();
|
||||||
private Map<String, Texture> texCache = new HashMap<String, Texture>();
|
private Map<String, Texture> texCache = new HashMap<String, Texture>();
|
||||||
private float anisotrophy = 0;
|
private float anisotrophy = 0;
|
||||||
|
|
||||||
public RealisticRenderStrategy(OpenRocketDocument document) {
|
public RealisticRenderer(OpenRocketDocument document) {
|
||||||
super(document);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateFigure() {
|
|
||||||
needClearCache = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(GLAutoDrawable drawable) {
|
public void init(GLAutoDrawable drawable) {
|
||||||
|
super.init(drawable);
|
||||||
|
|
||||||
oldTexCache = new HashMap<String, Texture>();
|
oldTexCache = new HashMap<String, Texture>();
|
||||||
texCache = new HashMap<String, Texture>();
|
texCache = new HashMap<String, Texture>();
|
||||||
|
|
||||||
GL2 gl = drawable.getGL().getGL2();
|
GL2 gl = drawable.getGL().getGL2();
|
||||||
|
|
||||||
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,
|
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT, new float[] { 0, 0, 0 }, 0);
|
||||||
new float[] { 0, 0, 0 }, 0);
|
|
||||||
|
|
||||||
float amb = 0.3f;
|
float amb = 0.3f;
|
||||||
float dif = 1.0f - amb;
|
float dif = 1.0f - amb;
|
||||||
float spc = 1.0f;
|
float spc = 1.0f;
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT,
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT, new float[] { amb, amb, amb, 1 }, 0);
|
||||||
new float[] { amb, amb, amb, 1 }, 0);
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE, new float[] { dif, dif, dif, 1 }, 0);
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_DIFFUSE,
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR, new float[] { spc, spc, spc, 1 }, 0);
|
||||||
new float[] { dif, dif, dif, 1 }, 0);
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR,
|
|
||||||
new float[] { spc, spc, spc, 1 }, 0);
|
|
||||||
|
|
||||||
gl.glEnable(GLLightingFunc.GL_LIGHT1);
|
gl.glEnable(GLLightingFunc.GL_LIGHT1);
|
||||||
gl.glEnable(GLLightingFunc.GL_LIGHTING);
|
gl.glEnable(GLLightingFunc.GL_LIGHTING);
|
||||||
@ -77,8 +68,17 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateFigure() {
|
||||||
|
super.updateFigure();
|
||||||
|
|
||||||
|
needClearCache = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose(GLAutoDrawable drawable) {
|
public void dispose(GLAutoDrawable drawable) {
|
||||||
|
super.dispose(drawable);
|
||||||
|
|
||||||
oldTexCache = null;
|
oldTexCache = null;
|
||||||
texCache = null;
|
texCache = null;
|
||||||
}
|
}
|
||||||
@ -94,23 +94,23 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
|
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
||||||
|
|
||||||
if (needClearCache) {
|
if (needClearCache) {
|
||||||
clearCaches(gl);
|
clearCaches(gl);
|
||||||
needClearCache = false;
|
needClearCache = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Appearance a = getAppearance(c);
|
final Appearance a = getAppearance(c);
|
||||||
|
final Decal t = a.getTexture();
|
||||||
|
final Texture tex = getTexture(t);
|
||||||
|
|
||||||
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
|
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
|
||||||
gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR);
|
gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR);
|
||||||
|
|
||||||
|
|
||||||
if (a.getTexture() != null) {
|
convertColor(a.getPaint(), color);
|
||||||
color[0] = color[1] = color[2] = 1;
|
color[3] = alpha;
|
||||||
} else {
|
|
||||||
convertColor(a.getPaint(), color);
|
|
||||||
color[3] = alpha;
|
|
||||||
}
|
|
||||||
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, color, 0);
|
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, color, 0);
|
||||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
|
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
|
||||||
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0);
|
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0);
|
||||||
@ -124,17 +124,15 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
|
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
|
||||||
gl.glMateriali(GL.GL_BACK, GLLightingFunc.GL_SHININESS, 0);
|
gl.glMateriali(GL.GL_BACK, GLLightingFunc.GL_SHININESS, 0);
|
||||||
|
|
||||||
Decal t = a.getTexture();
|
cr.renderGeometry(gl, c);
|
||||||
Texture tex = null;
|
|
||||||
if (t != null) {
|
|
||||||
tex = getTexture(t);
|
|
||||||
}
|
|
||||||
if (t != null && tex != null) {
|
if (t != null && tex != null) {
|
||||||
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
|
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
|
||||||
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
|
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
|
||||||
|
|
||||||
tex.enable(gl);
|
tex.enable(gl);
|
||||||
tex.bind(gl);
|
tex.bind(gl);
|
||||||
|
|
||||||
gl.glMatrixMode(GL.GL_TEXTURE);
|
gl.glMatrixMode(GL.GL_TEXTURE);
|
||||||
gl.glPushMatrix();
|
gl.glPushMatrix();
|
||||||
|
|
||||||
@ -148,28 +146,35 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, toEdgeMode(t.getEdgeMode()));
|
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, toEdgeMode(t.getEdgeMode()));
|
||||||
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, toEdgeMode(t.getEdgeMode()));
|
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, toEdgeMode(t.getEdgeMode()));
|
||||||
|
|
||||||
|
|
||||||
|
gl.glTexParameterfv(GL.GL_TEXTURE_2D, GL2.GL_TEXTURE_BORDER_COLOR, colorClear, 0);
|
||||||
|
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, colorWhite, 0);
|
||||||
|
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, colorWhite, 0);
|
||||||
|
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, colorWhite, 0);
|
||||||
|
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, colorWhite, 0);
|
||||||
|
|
||||||
|
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
gl.glEnable(GL.GL_BLEND);
|
||||||
|
gl.glDepthFunc(GL.GL_LEQUAL);
|
||||||
|
|
||||||
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
||||||
|
|
||||||
if (anisotrophy > 0) {
|
if (anisotrophy > 0) {
|
||||||
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotrophy);
|
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotrophy);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
cr.renderGeometry(gl, c);
|
||||||
|
|
||||||
@Override
|
if (t.getEdgeMode() == Decal.EdgeMode.STICKER) {
|
||||||
public void postGeometry(GL2 gl, RocketComponent c, float alpha) {
|
gl.glDepthFunc(GL.GL_LESS);
|
||||||
Appearance a = getAppearance(c);
|
}
|
||||||
Decal t = a.getTexture();
|
|
||||||
Texture tex = null;
|
|
||||||
if (t != null) {
|
|
||||||
tex = getTexture(t);
|
|
||||||
}
|
|
||||||
if (tex != null) {
|
|
||||||
gl.glMatrixMode(GL.GL_TEXTURE);
|
gl.glMatrixMode(GL.GL_TEXTURE);
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
||||||
tex.disable(gl);
|
tex.disable(gl);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCaches(GL2 gl) {
|
private void clearCaches(GL2 gl) {
|
||||||
@ -184,6 +189,9 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Texture getTexture(Decal t) {
|
private Texture getTexture(Decal t) {
|
||||||
|
if (t == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
String imageName = t.getImage().getName();
|
String imageName = t.getImage().getName();
|
||||||
|
|
||||||
// Return the Cached value if available
|
// Return the Cached value if available
|
||||||
@ -202,7 +210,7 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
try {
|
try {
|
||||||
log.debug("Loading texture " + t);
|
log.debug("Loading texture " + t);
|
||||||
InputStream is = t.getImage().getBytes();
|
InputStream is = t.getImage().getBytes();
|
||||||
TextureData data = TextureIO.newTextureData(GLProfile.getDefault(), is, true, null);
|
TextureData data = TextureIO.newTextureData(GLProfile.getDefault(), is, GL.GL_RGBA, GL.GL_RGBA, true, null);
|
||||||
tex = TextureIO.newTexture(data);
|
tex = TextureIO.newTexture(data);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("Error loading Texture", e);
|
log.error("Error loading Texture", e);
|
||||||
@ -229,6 +237,8 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
return GL.GL_MIRRORED_REPEAT;
|
return GL.GL_MIRRORED_REPEAT;
|
||||||
case CLAMP:
|
case CLAMP:
|
||||||
return GL.GL_CLAMP_TO_EDGE;
|
return GL.GL_CLAMP_TO_EDGE;
|
||||||
|
case STICKER:
|
||||||
|
return GL2.GL_CLAMP_TO_BORDER;
|
||||||
default:
|
default:
|
||||||
return GL.GL_CLAMP_TO_EDGE;
|
return GL.GL_CLAMP_TO_EDGE;
|
||||||
}
|
}
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package net.sf.openrocket.gui.figure3d;
|
|
||||||
|
|
||||||
import javax.media.opengl.GL2;
|
|
||||||
import javax.media.opengl.GLAutoDrawable;
|
|
||||||
|
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
|
||||||
|
|
||||||
public abstract class RenderStrategy {
|
|
||||||
|
|
||||||
protected final OpenRocketDocument document;
|
|
||||||
|
|
||||||
public RenderStrategy( OpenRocketDocument document ) {
|
|
||||||
this.document = document;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean isDrawn(RocketComponent c);
|
|
||||||
|
|
||||||
public abstract boolean isDrawnTransparent(RocketComponent c);
|
|
||||||
|
|
||||||
public abstract void preGeometry(GL2 gl, RocketComponent c, float alpha);
|
|
||||||
|
|
||||||
public abstract void postGeometry(GL2 gl, RocketComponent c, float alpha);
|
|
||||||
|
|
||||||
public void updateFigure() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(GLAutoDrawable drawable) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dispose(GLAutoDrawable drawable) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -21,6 +21,7 @@ import javax.media.opengl.GLAutoDrawable;
|
|||||||
import javax.media.opengl.GLCapabilities;
|
import javax.media.opengl.GLCapabilities;
|
||||||
import javax.media.opengl.GLEventListener;
|
import javax.media.opengl.GLEventListener;
|
||||||
import javax.media.opengl.GLProfile;
|
import javax.media.opengl.GLProfile;
|
||||||
|
import javax.media.opengl.GLRunnable;
|
||||||
import javax.media.opengl.awt.GLCanvas;
|
import javax.media.opengl.awt.GLCanvas;
|
||||||
import javax.media.opengl.fixedfunc.GLLightingFunc;
|
import javax.media.opengl.fixedfunc.GLLightingFunc;
|
||||||
import javax.media.opengl.fixedfunc.GLMatrixFunc;
|
import javax.media.opengl.fixedfunc.GLMatrixFunc;
|
||||||
@ -87,7 +88,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
float[] lightPosition = new float[] { 1, 4, 1, 0 };
|
float[] lightPosition = new float[] { 1, 4, 1, 0 };
|
||||||
|
|
||||||
RocketRenderer rr = new RocketRenderer();
|
RocketRenderer rr = new FigureRenderer();
|
||||||
|
|
||||||
public RocketFigure3d(OpenRocketDocument document, Configuration config) {
|
public RocketFigure3d(OpenRocketDocument document, Configuration config) {
|
||||||
this.document = document;
|
this.document = document;
|
||||||
@ -393,7 +394,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
GL2 gl = drawable.getGL().getGL2();
|
GL2 gl = drawable.getGL().getGL2();
|
||||||
gl.glClearDepth(1.0f); // clear z-buffer to the farthest
|
gl.glClearDepth(1.0f); // clear z-buffer to the farthest
|
||||||
|
|
||||||
gl.glDepthFunc(GL.GL_LEQUAL); // the type of depth test to do
|
gl.glDepthFunc(GL.GL_LESS); // the type of depth test to do
|
||||||
|
|
||||||
float amb = 0.5f;
|
float amb = 0.5f;
|
||||||
float dif = 1.0f;
|
float dif = 1.0f;
|
||||||
@ -425,7 +426,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
|
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
|
||||||
gl.glLoadIdentity();
|
gl.glLoadIdentity();
|
||||||
glu.gluPerspective(fovY, ratio, 0.05f, 100f);
|
glu.gluPerspective(fovY, ratio, 0.1f, 50f);
|
||||||
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
||||||
|
|
||||||
redrawExtras = true;
|
redrawExtras = true;
|
||||||
@ -631,13 +632,20 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
this.csl = newListener;
|
this.csl = newListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(int t) {
|
public void setType(final int t) {
|
||||||
if (t == TYPE_FIGURE) {
|
canvas.invoke(true, new GLRunnable() {
|
||||||
rr.setRenderStrategy(new FigureRenderStrategy());
|
@Override
|
||||||
} else {
|
public boolean run(GLAutoDrawable drawable) {
|
||||||
rr.setRenderStrategy(new RealisticRenderStrategy(document));
|
rr.dispose(drawable);
|
||||||
}
|
if (t == TYPE_FIGURE) {
|
||||||
repaint();
|
rr = new FigureRenderer();
|
||||||
|
} else {
|
||||||
|
rr = new RealisticRenderer(document);
|
||||||
|
}
|
||||||
|
rr.init(drawable);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,50 +23,33 @@ import net.sf.openrocket.util.Coordinate;
|
|||||||
/*
|
/*
|
||||||
* @author Bill Kuker <bkuker@billkuker.com>
|
* @author Bill Kuker <bkuker@billkuker.com>
|
||||||
*/
|
*/
|
||||||
public class RocketRenderer {
|
public abstract class RocketRenderer {
|
||||||
@SuppressWarnings("unused")
|
protected static final LogHelper log = Application.getLogger();
|
||||||
private static final LogHelper log = Application.getLogger();
|
|
||||||
|
|
||||||
RenderStrategy currentStrategy = new FigureRenderStrategy();
|
final ComponentRenderer cr = new ComponentRenderer();
|
||||||
RenderStrategy nextStrategy;
|
|
||||||
|
|
||||||
ComponentRenderer cr;
|
|
||||||
|
|
||||||
private final float[] selectedEmissive = { 1, 0, 0, 1 };
|
private final float[] selectedEmissive = { 1, 0, 0, 1 };
|
||||||
private final float[] colorBlack = { 0, 0, 0, 1 };
|
private final float[] colorBlack = { 0, 0, 0, 1 };
|
||||||
|
|
||||||
|
|
||||||
public void setRenderStrategy(RenderStrategy r) {
|
|
||||||
nextStrategy = r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkRenderStrategy(GLAutoDrawable drawable) {
|
|
||||||
if (nextStrategy == null)
|
|
||||||
return;
|
|
||||||
currentStrategy.dispose(drawable);
|
|
||||||
nextStrategy.init(drawable);
|
|
||||||
currentStrategy = nextStrategy;
|
|
||||||
nextStrategy = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(GLAutoDrawable drawable) {
|
public void init(GLAutoDrawable drawable) {
|
||||||
cr = new ComponentRenderer();
|
|
||||||
cr.init(drawable);
|
cr.init(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose(GLAutoDrawable drawable) {
|
public void dispose(GLAutoDrawable drawable) {
|
||||||
currentStrategy.dispose(drawable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFigure() {
|
public void updateFigure() {
|
||||||
currentStrategy.updateFigure();
|
|
||||||
cr.updateFigure();
|
cr.updateFigure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void renderComponent(GL2 gl, RocketComponent c, float alpha);
|
||||||
|
|
||||||
public RocketComponent pick(GLAutoDrawable drawable,
|
public abstract boolean isDrawn(RocketComponent c);
|
||||||
Configuration configuration, Point p, Set<RocketComponent> ignore) {
|
|
||||||
checkRenderStrategy(drawable);
|
public abstract boolean isDrawnTransparent(RocketComponent c);
|
||||||
|
|
||||||
|
public RocketComponent pick(GLAutoDrawable drawable, Configuration configuration, Point p,
|
||||||
|
Set<RocketComponent> ignore) {
|
||||||
final GL2 gl = drawable.getGL().getGL2();
|
final GL2 gl = drawable.getGL().getGL2();
|
||||||
gl.glEnable(GL.GL_DEPTH_TEST);
|
gl.glEnable(GL.GL_DEPTH_TEST);
|
||||||
|
|
||||||
@ -81,12 +64,11 @@ public class RocketRenderer {
|
|||||||
// if index is 0x0ABC the color ends up as
|
// if index is 0x0ABC the color ends up as
|
||||||
// 0xA0B0C000 with each nibble in the coresponding
|
// 0xA0B0C000 with each nibble in the coresponding
|
||||||
// high bits of the RG and B channels.
|
// high bits of the RG and B channels.
|
||||||
gl.glColor4ub((byte) ((pickParts.size() >> 4) & 0xF0),
|
gl.glColor4ub((byte) ((pickParts.size() >> 4) & 0xF0), (byte) ((pickParts.size() << 0) & 0xF0),
|
||||||
(byte) ((pickParts.size() << 0) & 0xF0),
|
|
||||||
(byte) ((pickParts.size() << 4) & 0xF0), (byte) 1);
|
(byte) ((pickParts.size() << 4) & 0xF0), (byte) 1);
|
||||||
pickParts.add(c);
|
pickParts.add(c);
|
||||||
|
|
||||||
if (currentStrategy.isDrawnTransparent(c)) {
|
if (isDrawnTransparent(c)) {
|
||||||
gl.glEnable(GL.GL_CULL_FACE);
|
gl.glEnable(GL.GL_CULL_FACE);
|
||||||
gl.glCullFace(GL.GL_FRONT);
|
gl.glCullFace(GL.GL_FRONT);
|
||||||
cr.renderGeometry(gl, c);
|
cr.renderGeometry(gl, c);
|
||||||
@ -101,8 +83,7 @@ public class RocketRenderer {
|
|||||||
gl.glReadPixels(p.x, p.y, 1, 1, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, bb);
|
gl.glReadPixels(p.x, p.y, 1, 1, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, bb);
|
||||||
|
|
||||||
final int pickColor = bb.getInt();
|
final int pickColor = bb.getInt();
|
||||||
final int pickIndex = ((pickColor >> 20) & 0xF00)
|
final int pickIndex = ((pickColor >> 20) & 0xF00) | ((pickColor >> 16) & 0x0F0) | ((pickColor >> 12) & 0x00F);
|
||||||
| ((pickColor >> 16) & 0x0F0) | ((pickColor >> 12) & 0x00F);
|
|
||||||
|
|
||||||
if (pickIndex < 0 || pickIndex > pickParts.size() - 1)
|
if (pickIndex < 0 || pickIndex > pickParts.size() - 1)
|
||||||
return null;
|
return null;
|
||||||
@ -110,9 +91,7 @@ public class RocketRenderer {
|
|||||||
return pickParts.get(pickIndex);
|
return pickParts.get(pickIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(GLAutoDrawable drawable, Configuration configuration,
|
public void render(GLAutoDrawable drawable, Configuration configuration, Set<RocketComponent> selection) {
|
||||||
Set<RocketComponent> selection) {
|
|
||||||
checkRenderStrategy(drawable);
|
|
||||||
|
|
||||||
if (cr == null)
|
if (cr == null)
|
||||||
throw new IllegalStateException(this + " Not Initialized");
|
throw new IllegalStateException(this + " Not Initialized");
|
||||||
@ -122,24 +101,22 @@ public class RocketRenderer {
|
|||||||
gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing
|
gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing
|
||||||
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
|
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
{ // Draw selection outline at nearest Z
|
||||||
{ //Draw selection outline at nearest Z
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION, selectedEmissive, 0);
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION,
|
|
||||||
selectedEmissive, 0);
|
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE, colorBlack, 0);
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_DIFFUSE, colorBlack, 0);
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_AMBIENT, colorBlack, 0);
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_AMBIENT, colorBlack, 0);
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
|
||||||
gl.glLineWidth(5.0f);
|
gl.glLineWidth(5.0f);
|
||||||
|
|
||||||
for (RocketComponent c : configuration) {
|
for (RocketComponent c : configuration) {
|
||||||
if ( selection.contains(c) ){
|
if (selection.contains(c)) {
|
||||||
//Draw as lines, set Z to nearest
|
// Draw as lines, set Z to nearest
|
||||||
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
|
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
|
||||||
gl.glDepthRange(0, 0);
|
gl.glDepthRange(0, 0);
|
||||||
cr.renderGeometry(gl, c);
|
cr.renderGeometry(gl, c);
|
||||||
|
|
||||||
//Draw polygons, always passing depth test,
|
// Draw polygons, always passing depth test,
|
||||||
//setting Z to farthest
|
// setting Z to farthest
|
||||||
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
||||||
gl.glDepthRange(1, 1);
|
gl.glDepthRange(1, 1);
|
||||||
gl.glDepthFunc(GL.GL_ALWAYS);
|
gl.glDepthFunc(GL.GL_ALWAYS);
|
||||||
@ -149,14 +126,13 @@ public class RocketRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
|
||||||
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION,
|
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_EMISSION, colorBlack, 0);
|
||||||
colorBlack, 0);
|
} // done with selection outline
|
||||||
} //done with selection outline
|
|
||||||
|
|
||||||
// Draw all inner components
|
// Draw all inner components
|
||||||
for (RocketComponent c : configuration) {
|
for (RocketComponent c : configuration) {
|
||||||
if (currentStrategy.isDrawn(c)) {
|
if (isDrawn(c)) {
|
||||||
if (!currentStrategy.isDrawnTransparent(c)) {
|
if (!isDrawnTransparent(c)) {
|
||||||
renderComponent(gl, c, 1.0f);
|
renderComponent(gl, c, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,8 +145,8 @@ public class RocketRenderer {
|
|||||||
gl.glEnable(GL.GL_CULL_FACE);
|
gl.glEnable(GL.GL_CULL_FACE);
|
||||||
gl.glCullFace(GL.GL_FRONT);
|
gl.glCullFace(GL.GL_FRONT);
|
||||||
for (RocketComponent c : configuration) {
|
for (RocketComponent c : configuration) {
|
||||||
if (currentStrategy.isDrawn(c)) {
|
if (isDrawn(c)) {
|
||||||
if (currentStrategy.isDrawnTransparent(c)) {
|
if (isDrawnTransparent(c)) {
|
||||||
renderComponent(gl, c, 1.0f);
|
renderComponent(gl, c, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,8 +158,8 @@ public class RocketRenderer {
|
|||||||
gl.glEnable(GL.GL_CULL_FACE);
|
gl.glEnable(GL.GL_CULL_FACE);
|
||||||
gl.glCullFace(GL.GL_BACK);
|
gl.glCullFace(GL.GL_BACK);
|
||||||
for (RocketComponent c : configuration) {
|
for (RocketComponent c : configuration) {
|
||||||
if (currentStrategy.isDrawn(c)) {
|
if (isDrawn(c)) {
|
||||||
if (currentStrategy.isDrawnTransparent(c)) {
|
if (isDrawnTransparent(c)) {
|
||||||
renderComponent(gl, c, 0.2f);
|
renderComponent(gl, c, 0.2f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,9 +178,8 @@ public class RocketRenderer {
|
|||||||
double length = motor.getLength();
|
double length = motor.getLength();
|
||||||
double radius = motor.getDiameter() / 2;
|
double radius = motor.getDiameter() / 2;
|
||||||
|
|
||||||
Coordinate[] position = ((RocketComponent) mount)
|
Coordinate[] position = ((RocketComponent) mount).toAbsolute(new Coordinate(((RocketComponent) mount)
|
||||||
.toAbsolute(new Coordinate(((RocketComponent) mount)
|
.getLength() + mount.getMotorOverhang() - length));
|
||||||
.getLength() + mount.getMotorOverhang() - length));
|
|
||||||
|
|
||||||
for (int i = 0; i < position.length; i++) {
|
for (int i = 0; i < position.length; i++) {
|
||||||
cr.renderMotor(gl, position[i], length, radius);
|
cr.renderMotor(gl, position[i], length, radius);
|
||||||
@ -213,10 +188,4 @@ public class RocketRenderer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
|
||||||
currentStrategy.preGeometry(gl, c, alpha);
|
|
||||||
cr.renderGeometry(gl, c);
|
|
||||||
currentStrategy.postGeometry(gl, c, alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user