Trying to get material and lighting right
This commit is contained in:
parent
09b81a3529
commit
5dd804bed0
@ -115,4 +115,15 @@ public class FigureRenderStrategy extends RenderStrategy {
|
|||||||
return 20;
|
return 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void convertColor(Color color, float[] out) {
|
||||||
|
if ( color == null ){
|
||||||
|
out[0] = 1;
|
||||||
|
out[1] = 1;
|
||||||
|
out[2] = 0;
|
||||||
|
} else {
|
||||||
|
out[0] = Math.max(0.2f, (float) color.getRed() / 255f);
|
||||||
|
out[1] = Math.max(0.2f, (float) color.getGreen() / 255f);
|
||||||
|
out[2] = Math.max(0.2f, (float) color.getBlue() / 255f);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,11 @@ import net.sf.openrocket.appearance.Decal;
|
|||||||
import net.sf.openrocket.logging.LogHelper;
|
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.startup.Application;
|
||||||
|
import net.sf.openrocket.util.Color;
|
||||||
|
|
||||||
public class RealisticRenderStrategy extends RenderStrategy {
|
public class RealisticRenderStrategy extends RenderStrategy {
|
||||||
|
|
||||||
|
private final float[] colorBlack = { 0, 0, 0, 1 };
|
||||||
private final float[] color = new float[4];
|
private final float[] color = new float[4];
|
||||||
private static final LogHelper log = Application.getLogger();
|
private static final LogHelper log = Application.getLogger();
|
||||||
|
|
||||||
@ -60,20 +62,20 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
convertColor(a.getDiffuse(), color);
|
convertColor(a.getDiffuse(), color);
|
||||||
color[3] = alpha;
|
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);
|
||||||
|
|
||||||
convertColor(a.getAmbient(), color);
|
convertColor(a.getAmbient(), color);
|
||||||
color[3] = alpha;
|
color[3] = alpha;
|
||||||
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0);
|
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0);
|
||||||
|
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0);
|
||||||
|
|
||||||
convertColor(a.getSpecular(), color);
|
convertColor(a.getSpecular(), color);
|
||||||
color[3] = alpha;
|
color[3] = alpha;
|
||||||
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, color, 0);
|
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, color, 0);
|
||||||
gl.glMateriali(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, a.getShininess());
|
gl.glMateriali(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, a.getShininess());
|
||||||
|
|
||||||
convertColor(a.getDiffuse(), color);
|
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
|
||||||
color[3] = alpha;
|
gl.glMateriali(GL.GL_BACK, GLLightingFunc.GL_SHININESS, 0);
|
||||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
|
|
||||||
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0);
|
|
||||||
|
|
||||||
Decal t = a.getTexture();
|
Decal t = a.getTexture();
|
||||||
Texture tex = null;
|
Texture tex = null;
|
||||||
@ -183,4 +185,15 @@ public class RealisticRenderStrategy extends RenderStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void convertColor(Color color, float[] out) {
|
||||||
|
if (color == null) {
|
||||||
|
out[0] = 1;
|
||||||
|
out[1] = 1;
|
||||||
|
out[2] = 0;
|
||||||
|
} else {
|
||||||
|
out[0] = (float) color.getRed() / 255f;
|
||||||
|
out[1] = (float) color.getGreen() / 255f;
|
||||||
|
out[2] = (float) color.getBlue() / 255f;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ package net.sf.openrocket.gui.figure3d;
|
|||||||
import javax.media.opengl.GL2;
|
import javax.media.opengl.GL2;
|
||||||
|
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.util.Color;
|
|
||||||
|
|
||||||
public abstract class RenderStrategy {
|
public abstract class RenderStrategy {
|
||||||
public abstract boolean isDrawn(RocketComponent c);
|
public abstract boolean isDrawn(RocketComponent c);
|
||||||
|
|
||||||
public abstract boolean isDrawnTransparent(RocketComponent c);
|
public abstract boolean isDrawnTransparent(RocketComponent c);
|
||||||
|
|
||||||
public abstract void preGeometry(GL2 gl, RocketComponent c, float alpha);
|
public abstract void preGeometry(GL2 gl, RocketComponent c, float alpha);
|
||||||
@ -17,15 +17,4 @@ public abstract class RenderStrategy {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void convertColor(Color color, float[] out) {
|
|
||||||
if ( color == null ){
|
|
||||||
out[0] = 1;
|
|
||||||
out[1] = 1;
|
|
||||||
out[2] = 0;
|
|
||||||
} else {
|
|
||||||
out[0] = Math.max(0.2f, (float) color.getRed() / 255f);
|
|
||||||
out[1] = Math.max(0.2f, (float) color.getGreen() / 255f);
|
|
||||||
out[2] = Math.max(0.2f, (float) color.getBlue() / 255f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user