From dbcbe119a74f923ab129b950a364c3f27615cce3 Mon Sep 17 00:00:00 2001
From: Richard Pajersky <xpajersk@fi.muni.cz>
Date: Mon, 3 May 2021 11:10:37 +0200
Subject: [PATCH] Enabled color in GL and added color to DrawableMesh

---
 .../cz/fidentis/analyst/gui/scene/DrawableMesh.java   |  6 ++++++
 .../cz/fidentis/analyst/gui/scene/SceneRenderer.java  | 11 ++++++++++-
 .../fidentis/analyst/newgui/PostRegistrationCP.form   |  2 +-
 .../fidentis/analyst/newgui/PostRegistrationCP.java   |  2 +-
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/GUI/src/main/java/cz/fidentis/analyst/gui/scene/DrawableMesh.java b/GUI/src/main/java/cz/fidentis/analyst/gui/scene/DrawableMesh.java
index 82ee9db2..dc7177be 100644
--- a/GUI/src/main/java/cz/fidentis/analyst/gui/scene/DrawableMesh.java
+++ b/GUI/src/main/java/cz/fidentis/analyst/gui/scene/DrawableMesh.java
@@ -2,6 +2,7 @@ package cz.fidentis.analyst.gui.scene;
 
 import cz.fidentis.analyst.mesh.core.MeshFacet;
 import cz.fidentis.analyst.mesh.core.MeshModel;
+import java.awt.Color;
 import java.util.List;
 
 /**
@@ -18,6 +19,11 @@ public class DrawableMesh {
     private boolean display = true;
     
     // TO DO - R. Pajersky: add transformation attributes and methods
+    private Color color;
+
+    public Color getColor() {
+        return color;
+    }
     
     /**
      * Constructor. 
diff --git a/GUI/src/main/java/cz/fidentis/analyst/gui/scene/SceneRenderer.java b/GUI/src/main/java/cz/fidentis/analyst/gui/scene/SceneRenderer.java
index cda99920..364fa6d8 100644
--- a/GUI/src/main/java/cz/fidentis/analyst/gui/scene/SceneRenderer.java
+++ b/GUI/src/main/java/cz/fidentis/analyst/gui/scene/SceneRenderer.java
@@ -59,6 +59,11 @@ public class SceneRenderer {
 
         gl.glEnable(GL2.GL_NORMALIZE);
         gl.glDisable(GL2.GL_CULL_FACE);
+        
+        //color enabled
+        gl.glEnable(GL2.GL_COLOR_MATERIAL);
+        gl.glEnable(GL2.GL_BLEND);
+        gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
     }
     
     /**
@@ -128,6 +133,9 @@ public class SceneRenderer {
         }
         
         for (DrawableMesh obj: drawables) {
+            // render color
+            if (obj.getColor() != null)
+                gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, obj.getColor().getComponents(null), 0);
             for (MeshFacet facet: obj.getFacets()) {
                 // TO DO - R. Pajersky: add transformation (glPushMatrix, glRotate, ...)
                 renderFacet(facet);
@@ -181,7 +189,8 @@ public class SceneRenderer {
                 gl.glNormal3d(norm.x, norm.y, norm.z);
             }
             // render the vertices
-            Point3d vert = facet.getVertices().get(facet.getCornerTable().getRow(v).getVertexIndex()).getPosition(); 
+            gl.glColor4f( 0.0f,1.0f,0.0f, 0.5f );  
+            Point3d vert = facet.getVertices().get(facet.getCornerTable().getRow(v).getVertexIndex()).getPosition();
             gl.glVertex3d(vert.x, vert.y, vert.z);
         }
         
diff --git a/GUI/src/main/java/cz/fidentis/analyst/newgui/PostRegistrationCP.form b/GUI/src/main/java/cz/fidentis/analyst/newgui/PostRegistrationCP.form
index d493394b..9728e929 100644
--- a/GUI/src/main/java/cz/fidentis/analyst/newgui/PostRegistrationCP.form
+++ b/GUI/src/main/java/cz/fidentis/analyst/newgui/PostRegistrationCP.form
@@ -300,7 +300,7 @@
               <Component id="jSeparator7" min="-2" pref="10" max="-2" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
               <Component id="featurePointsButton" min="-2" max="-2" attributes="0"/>
-              <EmptySpace min="-2" pref="306" max="-2" attributes="0"/>
+              <EmptySpace min="-2" max="-2" attributes="0"/>
           </Group>
       </Group>
     </DimensionLayout>
diff --git a/GUI/src/main/java/cz/fidentis/analyst/newgui/PostRegistrationCP.java b/GUI/src/main/java/cz/fidentis/analyst/newgui/PostRegistrationCP.java
index c1d0920e..8be0b8e7 100644
--- a/GUI/src/main/java/cz/fidentis/analyst/newgui/PostRegistrationCP.java
+++ b/GUI/src/main/java/cz/fidentis/analyst/newgui/PostRegistrationCP.java
@@ -600,7 +600,7 @@ public class PostRegistrationCP extends javax.swing.JPanel {
                 .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(featurePointsButton)
-                .addGap(306, 306, 306))
+                .addContainerGap())
         );
     }// </editor-fold>//GEN-END:initComponents
 
-- 
GitLab