Skip to content

Commit

Permalink
fix broken textures
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Jul 1, 2024
1 parent 228b73c commit 499b9d0
Show file tree
Hide file tree
Showing 29 changed files with 300 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.marginallyclever.makelangelo.select.SelectReadOnlyText;

import java.awt.Component;
import javax.swing.JOptionPane;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.*;

@Deprecated
public class DialogBadFirmwareVersion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,6 @@ public Plotter getPlotter() {
return myPlotter;
}

public PlotterSettingsManager getPlotterSettingsManager() {
return plotterSettingsManager;
}

public MainFrame getFrame() {
return mainFrame;
}
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/com/marginallyclever/makelangelo/MeshFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.marginallyclever.makelangelo;

import com.jogamp.opengl.GL3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
* A factory for creating and maintaining Mesh objects.
*/
public class MeshFactory {
private static final Logger logger = LoggerFactory.getLogger(MeshFactory.class);

// the pool of all mesh loaded
private static final List<Mesh> meshPool = new ArrayList<>();

/**
* Create a new mesh and add it to the pool. This should be the only way to create a mesh.
* @return a new mesh
*/
public static Mesh createMesh() {
Mesh m = new Mesh();
addMesh(m);
return m;
}

public static void addMesh(Mesh mesh) {
if(meshPool.contains(mesh)) return;
meshPool.add(mesh);
}

public static void removeMesh(Mesh mesh) {
meshPool.remove(mesh);
}

public static void unloadAll(GL3 gl) {
for(Mesh m : meshPool) {
m.unload(gl);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.marginallyclever.makelangelo.apps.previewpanel;

import com.jogamp.opengl.GL3;

import java.util.EventListener;

/**
Expand All @@ -15,5 +13,5 @@ public interface PreviewListener extends EventListener {
* Callback from {@link PreviewPanel} that it is time to render to the WYSIWYG display.
* @param gl the render context
*/
void render(GL3 gl3);
void render(RenderContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.marginallyclever.convenience.helpers.OpenGLHelper;
import com.marginallyclever.convenience.helpers.ResourceHelper;
import com.marginallyclever.makelangelo.Camera;
import com.marginallyclever.makelangelo.MeshFactory;
import com.marginallyclever.makelangelo.Translator;
import com.marginallyclever.makelangelo.applicationsettings.GFXPreferences;
import com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer.PlotterRenderer;
Expand Down Expand Up @@ -95,9 +96,9 @@ public PreviewPanel(Paper paper, Plotter plotter) {

addListener(paper);
addListener(myTurtleRenderer);
addListener((gl) -> {
addListener(context -> {
if(myPlotterRenderer!=null) {
myPlotterRenderer.render(gl, myPlotter);
myPlotterRenderer.render(context, myPlotter);
}
});

Expand Down Expand Up @@ -321,6 +322,7 @@ public void dispose(GLAutoDrawable glAutoDrawable) {
logger.debug("dispose");
GL3 gl = glAutoDrawable.getGL().getGL3();
TextureFactory.unloadAll(gl);
MeshFactory.unloadAll(gl);
shaderDefault.delete(gl);
}

Expand Down Expand Up @@ -392,7 +394,7 @@ public void display(GLAutoDrawable glautodrawable) {
shaderDefault.use(gl3);
paintCamera(gl3, shaderDefault);
}
p.render(gl3);
p.render(new RenderContext(gl3, shaderDefault));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.marginallyclever.makelangelo.apps.previewpanel;

import com.jogamp.opengl.GL3;

public class RenderContext {
public GL3 gl;
public ShaderProgram shader;

public RenderContext(GL3 gl, ShaderProgram shader) {
this.gl = gl;
this.shader = shader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,43 @@

import com.jogamp.opengl.GL3;
import com.marginallyclever.makelangelo.Mesh;
import com.marginallyclever.makelangelo.MeshFactory;
import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext;
import com.marginallyclever.makelangelo.plotter.Plotter;
import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings;

import javax.vecmath.Point2d;

public class Cartesian implements PlotterRenderer {
public final double CARTESIAN_MOTOR_MOUNT_SIZE =45; //cm
public final double CARTESIAN_PLOTTER_SIZE=60; //cm
public final double CARTESIAN_PLOTTER_OUTER_SIZE=70; //cm
public final double CARTESIAN_PLOTTER_HOLE_SIZE=20; //cm
public final double CARTESIAN_MOTOR_BODY_SIZE =42; //cm
public static final int CARTESIAN_MOTOR_MOUNT_SIZE =45; //cm
public static final int CARTESIAN_PLOTTER_SIZE=60; //cm
public static final int CARTESIAN_PLOTTER_OUTER_SIZE=70; //cm
public static final int CARTESIAN_PLOTTER_HOLE_SIZE=20; //cm
public static final int NEMA17_SIZE = 42; //cm

public final Mesh meshMotor = new Mesh();
public final Mesh meshGantry = new Mesh();
public final Mesh meshControlBox = new Mesh();
public final Mesh meshQuad = MeshFactory.createMesh();

public Cartesian() {
setupMesh();
}

private void setupMesh() {
meshQuad.setRenderStyle(GL3.GL_QUADS);
meshQuad.addColor(1,1,1, 1);
meshQuad.addColor(1,1,1, 1);
meshQuad.addColor(1,1,1, 1);
meshQuad.addColor(1,1,1, 1);
meshQuad.addVertex(0, 0,0);
meshQuad.addVertex(0, 1,0);
meshQuad.addVertex(1, 1,0);
meshQuad.addVertex(1, 0,0);
}

@Override
public void render(GL3 gl,Plotter robot) {
paintGantryAndHead(gl,robot);
paintMotors(gl,robot);
paintControlBox(gl,robot);
public void render(RenderContext context, Plotter robot) {
paintGantryAndHead(context.gl,robot);
paintMotors(context.gl,robot);
paintControlBox(context.gl,robot);
}

@Override
Expand Down Expand Up @@ -98,19 +113,10 @@ protected void paintMotors(GL3 gl,Plotter plotter) {
}

private void paintOneMotor(GL3 gl) {
// TODO implement me
/*
// motor
gl.glColor3f(0, 0, 0);
gl.glBegin(GL3.GL_QUADS);
gl.glVertex2d(0 , 0 );
gl.glVertex2d(0 , CARTESIAN_MOTOR_BODY_SIZE);
gl.glVertex2d(CARTESIAN_MOTOR_BODY_SIZE, CARTESIAN_MOTOR_BODY_SIZE);
gl.glVertex2d(CARTESIAN_MOTOR_BODY_SIZE, 0 );
gl.glVertex2d(0 , 0 );
gl.glEnd();*/
// TODO set color to black? load NEMA17 motor picture?
meshQuad.render(gl);
}

/**
* paint the controller and the LCD panel
* @param gl the render context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer;

import com.jogamp.opengl.GL3;
import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram;
import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext;
import com.marginallyclever.makelangelo.plotter.Plotter;
import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings;

Expand All @@ -13,11 +13,11 @@
public class Makelangelo3 implements PlotterRenderer {

@Override
public void render(GL3 gl,Plotter robot) {
paintControlBox(gl,robot);
Polargraph.paintMotors(gl,robot);
public void render(RenderContext context, Plotter robot) {
paintControlBox(context.gl,robot);
Polargraph.paintMotors(context,robot);
if(robot.getDidFindHome())
Polargraph.paintPenHolderToCounterweights(gl,robot);
Polargraph.paintPenHolderToCounterweights(context,robot);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer;

import com.jogamp.opengl.GL3;
import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram;
import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext;
import com.marginallyclever.makelangelo.plotter.Plotter;
import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings;

public class Makelangelo3_3 implements PlotterRenderer {

@Override
public void render(GL3 gl,Plotter robot) {
paintControlBox(gl,robot);
Polargraph.paintMotors(gl,robot);
public void render(RenderContext context, Plotter robot) {
paintControlBox(context.gl,robot);
Polargraph.paintMotors(context,robot);
if(robot.getDidFindHome())
Polargraph.paintPenHolderToCounterweights(gl,robot);
Polargraph.paintPenHolderToCounterweights(context,robot);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.jogamp.opengl.GL3;
import com.marginallyclever.convenience.helpers.DrawingHelper;
import com.marginallyclever.makelangelo.Mesh;
import com.marginallyclever.makelangelo.MeshFactory;
import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext;
import com.marginallyclever.makelangelo.plotter.Plotter;
import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings;
import com.marginallyclever.makelangelo.texture.TextureFactory;
Expand All @@ -18,7 +20,7 @@ public class Makelangelo5 implements PlotterRenderer {
private final TextureWithMetadata textureGondola = TextureFactory.loadTexture("/textures/phBody.png");
private final TextureWithMetadata textureArm = TextureFactory.loadTexture("/textures/phArm2.png");

private final Mesh controlBox = new Mesh();
private final Mesh controlBox = MeshFactory.createMesh();

private void setupControlBoxMesh(PlotterSettings settings) {
float left = (float)settings.getDouble(PlotterSettings.LIMIT_LEFT);
Expand All @@ -43,22 +45,22 @@ private void setupControlBoxMesh(PlotterSettings settings) {
}

@Override
public void render(GL3 gl, Plotter robot) {
public void render(RenderContext context, Plotter robot) {
if (textureMainBody != null) {
paintControlBoxFancy(gl, textureMainBody);
paintControlBoxFancy(context, textureMainBody);
}

Polargraph.paintSafeArea(gl, robot);
Polargraph.paintSafeArea(context, robot);

if (robot.getDidFindHome())
paintPenHolderToCounterweights(gl, robot);
paintPenHolderToCounterweights(context, robot);

if (textureMotors != null) {
paintControlBoxFancy(gl, textureMotors);
paintControlBoxFancy(context, textureMotors);
}

if (textureLogo != null) {
paintLogoFancy(gl, robot.getSettings());
paintLogoFancy(context, robot.getSettings());
}
}

Expand All @@ -67,7 +69,7 @@ public void updatePlotterSettings(PlotterSettings settings) {
setupControlBoxMesh(settings);
}

public void paintPenHolderToCounterweights(GL3 gl, Plotter robot) {
public void paintPenHolderToCounterweights(RenderContext context, Plotter robot) {
Point2d pos = robot.getPos();
double gx = pos.x;
double gy = pos.y;
Expand All @@ -94,21 +96,21 @@ public void paintPenHolderToCounterweights(GL3 gl, Plotter robot) {
double right_b = (beltLength - right_a) / 2 - 55;

// belt from motor to pen holder left
drawBeltMinus10(gl,left,top,gx,gy);
drawBeltMinus10(context.gl,left,top,gx,gy);
// belt from motor to pen holder right
drawBeltMinus10(gl,right,top,gx,gy);
drawBeltMinus10(context.gl,right,top,gx,gy);

// belt from motor to counterweight left
paintBeltSide(gl,left,top,left_b);
paintBeltSide(context.gl,left,top,left_b);
// belt from motor to counterweight right
paintBeltSide(gl,right,top,right_b);
paintBeltSide(context.gl,right,top,right_b);

paintGondola(gl,gx,gy,robot);
paintGondola(context.gl,gx,gy,robot);

// left
paintCounterweight(gl,left,top-left_b);
paintCounterweight(context.gl,left,top-left_b);
// right
paintCounterweight(gl,right,top-right_b);
paintCounterweight(context.gl,right,top-right_b);
}

private void drawBeltMinus10(GL3 gl, double cornerX, double cornerY, double penX, double penY) {
Expand Down Expand Up @@ -175,20 +177,20 @@ private void paintCounterweight(GL3 gl,double x,double y) {
DrawingHelper.paintTexture(gl, textureWeight, x-20, y-74, 40,80);
}

private void paintControlBoxFancy(GL3 gl,TextureWithMetadata texture) {
//shaderProgram.set1i(gl,"useTexture",1);
texture.use(gl);
//controlBox.render(gl);
private void paintControlBoxFancy(RenderContext context,TextureWithMetadata texture) {
context.shader.set1i(context.gl,"useTexture",1);
texture.use(context.gl);
controlBox.render(context.gl);
//shaderProgram.set1i(gl,"useTexture",0);
}

/**
* Paint the Marginally Clever Logo
*
* @param gl the render context
* @param context the render context
* @param settings the machine settings
*/
private void paintLogoFancy(GL3 gl, PlotterSettings settings) {
private void paintLogoFancy(RenderContext context, PlotterSettings settings) {
// TODO implement me
/*
// bottom left corner of safe area
Expand Down
Loading

0 comments on commit 499b9d0

Please sign in to comment.