use of maspack.render.ColorMapProps in project artisynth_core by artisynth.
the class GL2Viewer method init.
@Override
public void init(GLAutoDrawable drawable) {
super.init(drawable);
this.drawable = drawable;
this.gl = drawable.getGL().getGL2();
if (DEBUG) {
Logger.getSystemLogger().debug("GL: " + gl);
Logger.getSystemLogger().debug("Dev id : ");
GLContext context = drawable.getContext();
String contextHC = Integer.toHexString(System.identityHashCode(context));
Logger.getSystemLogger().debug("Context: " + context.getClass().getName() + "@" + contextHC + " (shared=" + context.isShared() + ")");
}
gl.setSwapInterval(1);
int[] buff = new int[1];
gl.glGetIntegerv(GL2.GL_MAX_CLIP_PLANES, buff, 0);
maxClipPlanes = buff[0];
setFaceStyle(FaceStyle.FRONT);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glClearDepth(1.0);
gl.glLightModelfv(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local, 0);
gl.glLightModelfv(GL2.GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside, 0);
gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient, 0);
gl.glLightModelf(GL2.GL_LIGHT_MODEL_TWO_SIDE, 1);
gl.glEnable(GL2.GL_LIGHTING);
// normalize normals
gl.glEnable(GL2.GL_NORMALIZE);
myTextRenderer = GLTextRenderer.generate(gl, GL2PipelineRenderer.generate(gl));
myTextTextureProps = new ColorMapProps();
myTextTextureProps.setColorMixing(ColorMixing.MODULATE);
myTextTextureProps.setEnabled(true);
setLightingEnabled(true);
setDepthEnabled(true);
setColorEnabled(true);
setVertexColoringEnabled(true);
setTextureMappingEnabled(true);
setFaceStyle(FaceStyle.FRONT);
setShading(Shading.SMOOTH);
setGammaCorrectionEnabled(false);
lightManager.setMaxLights(getMaxLights(gl));
setupLights(gl);
// gl.glFrontFace (GL2.GL_CW);
if (!isSelecting()) {
gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]);
}
// initialize viewport
resetViewVolume(gl);
invalidateModelMatrix();
invalidateProjectionMatrix();
invalidateViewMatrix();
// trigger rebuild of renderables
buildInternalRenderList();
if (DEBUG) {
Logger.getSystemLogger().debug("GL2 initialized");
}
}
use of maspack.render.ColorMapProps in project artisynth_core by artisynth.
the class TextureEgyptianTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
JFrame frame = new JFrame();
JPanel controls = new JPanel();
frame.add(controls);
PolygonalMesh plane = MeshFactory.createRectangle(4000, 400, 32, 8, /*texture=*/
true);
RenderProps rprops = plane.getRenderProps();
if (rprops == null) {
rprops = new RenderProps();
}
rprops.setShading(Shading.SMOOTH);
rprops.setShininess(20);
rprops.setFaceColor(new Color(155, 196, 30));
rprops.setSpecular(new Color(255, 113, 0));
rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
plane.transform(new RigidTransform3d(Vector3d.ZERO, AxisAngle.ROT_X_90));
String srcDir = PathFinder.findSourceDir(this);
ColorMapProps dprops = new ColorMapProps();
dprops.setFileName(srcDir + "/data/specular_map.jpg");
dprops.setColorMixing(ColorMixing.MODULATE);
dprops.setEnabled(true);
NormalMapProps normalProps = new NormalMapProps();
normalProps.setFileName(srcDir + "/data/foil_normal_map2.png");
normalProps.setScaling(0.3f);
normalProps.setEnabled(true);
BumpMapProps bumpProps = new BumpMapProps();
bumpProps.setFileName(srcDir + "/data/egyptian_friz_2.png");
bumpProps.setScaling(2.5f);
bumpProps.setEnabled(true);
rprops.setColorMap(dprops);
rprops.setNormalMap(normalProps);
rprops.setBumpMap(bumpProps);
// FixedMeshBody fm = new FixedMeshBody(plane);
// fm.setRenderProps(rprops);
mv.addRenderable(plane);
if (false) {
mv.addRenderable(new IsRenderable() {
@Override
public void updateBounds(Vector3d pmin, Vector3d pmax) {
Point3d.X_UNIT.updateBounds(pmin, pmax);
Point3d.Y_UNIT.updateBounds(pmin, pmax);
Point3d.Z_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_X_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_Y_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_Z_UNIT.updateBounds(pmin, pmax);
}
@Override
public void render(Renderer renderer, int flags) {
renderer.setColor(Color.CYAN);
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
renderer.drawSphere(Point3d.ZERO, 1);
}
@Override
public void prerender(RenderList list) {
// TODO Auto-generated method stub
}
@Override
public int getRenderHints() {
// TODO Auto-generated method stub
return 0;
}
});
}
mv.autoFitViewers();
LabeledComponentBase base = PropertyWidget.create("Color texture", rprops.getColorMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Normal map", rprops.getNormalMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Specular", rprops.getColorMap(), "specularColoring");
controls.add(base);
base = PropertyWidget.create("Bump map scale", rprops.getBumpMap(), "scaling");
controls.add(base);
base = PropertyWidget.create("Normal map scale", rprops.getNormalMap(), "scaling");
controls.add(base);
frame.pack();
frame.setVisible(true);
}
use of maspack.render.ColorMapProps in project artisynth_core by artisynth.
the class ImagePlaneProbe method setImage.
public void setImage(double t) {
if (imageBasename == null || imageDirectory == null)
return;
int frameNum = (int) (t * frameRate) + 1;
String filename = String.format(fileNameFormat, imageBasename, frameNum, imageFileExt);
ColorMapProps tprops = myRenderProps.getColorMap();
tprops.setFileName(imageDirectory.getAbsolutePath() + "/" + filename);
myRenderProps.setColorMap(tprops);
}
use of maspack.render.ColorMapProps in project artisynth_core by artisynth.
the class GL3Viewer method drawText.
@Override
public double drawText(Font font, String str, float[] pos, double emSize) {
GL3 gl = getGL().getGL3();
if (font == null) {
font = getDefaultFont();
}
boolean savedBlending = isBlendingEnabled();
boolean savedTexture = isTextureMappingEnabled();
boolean savedDepth = isDepthWriteEnabled();
BlendFactor dfactor = getBlendDestFactor();
BlendFactor sfactor = getBlendSourceFactor();
setDepthWriteEnabled(false);
setBlendingEnabled(true);
setDepthWriteEnabled(false);
setBlendingEnabled(true);
setBlendSourceFactor(BlendFactor.GL_SRC_ALPHA);
setBlendDestFactor(BlendFactor.GL_ONE_MINUS_SRC_ALPHA);
setTextureMappingEnabled(true);
ColorMapProps savedTextureProps = setColorMap(myTextTextureProps);
maybeUpdateState(gl);
updateProgram(gl, RenderingMode.DEFAULT, true, false, true);
myProgManager.activateTexture(gl, "color_map");
myTextRenderer.begin(gl);
double d = myTextRenderer.drawText(font, str, pos, (float) emSize);
myTextRenderer.end(gl);
setDepthWriteEnabled(savedDepth);
setBlendSourceFactor(sfactor);
setBlendDestFactor(dfactor);
setBlendingEnabled(savedBlending);
setTextureMappingEnabled(savedTexture);
setColorMap(savedTextureProps);
return d;
}
use of maspack.render.ColorMapProps in project artisynth_core by artisynth.
the class PolygonalMeshRenderer method drawFaces.
private void drawFaces(Renderer renderer, RenderProps props, boolean highlight, RenderObject robj, FeatureIndexArray features, boolean featureSelection) {
boolean useTextures = robj.hasTextureCoords();
Renderer.FaceStyle savedFaceStyle = renderer.getFaceStyle();
Shading savedShadeModel = renderer.getShading();
Shading shading = props.getShading();
if (!robj.hasNormals() && shading != Shading.FLAT) {
shading = Shading.NONE;
}
renderer.setShading(shading);
renderer.setFaceColoring(props, highlight);
// XXX always front and back when selecting?
if (renderer.isSelecting()) {
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
} else {
renderer.setFaceStyle(props.getFaceStyle());
}
// int i = 0; // i is index of face
ColorInterpolation savedColorInterp = null;
if (usingHSV(getMesh())) {
savedColorInterp = renderer.setColorInterpolation(ColorInterpolation.HSV);
}
if (props.getDrawEdges()) {
renderer.setDepthOffset(-1);
}
ColorMapProps oldtprops = null;
NormalMapProps oldnprops = null;
BumpMapProps oldbprops = null;
if (useTextures) {
ColorMapProps dtprops = props.getColorMap();
oldtprops = renderer.setColorMap(dtprops);
NormalMapProps ntprops = props.getNormalMap();
oldnprops = renderer.setNormalMap(ntprops);
BumpMapProps btprops = props.getBumpMap();
oldbprops = renderer.setBumpMap(btprops);
}
if (renderer.isSelecting() && featureSelection) {
for (int i = 0; i < features.numFeatures(); ++i) {
renderer.beginSelectionQuery(features.getFeature(i));
renderer.drawVertices(robj, features.getVertices(), features.getFeatureOffset(i), features.getFeatureLength(i), DrawMode.TRIANGLES);
renderer.endSelectionQuery();
}
} else {
renderer.drawVertices(robj, features.getVertices(), DrawMode.TRIANGLES);
}
if (useTextures) {
// restore diffuse texture properties
renderer.setColorMap(oldtprops);
renderer.setNormalMap(oldnprops);
renderer.setBumpMap(oldbprops);
}
if (props.getDrawEdges()) {
renderer.setDepthOffset(0);
}
if (savedColorInterp != null) {
renderer.setColorInterpolation(savedColorInterp);
}
renderer.setFaceStyle(savedFaceStyle);
renderer.setShading(savedShadeModel);
}
Aggregations