1 package de.lathanda.eos.robot.gui;
4 import java.util.HashMap;
5 import com.jogamp.opengl.GL;
6 import com.jogamp.opengl.GL2;
7 import com.jogamp.opengl.GLException;
8 import com.jogamp.opengl.GLProfile;
9 import com.jogamp.opengl.util.texture.Texture;
10 import com.jogamp.opengl.util.texture.awt.AWTTextureData;
12 import de.lathanda.eos.robot.geom3d.Material;
16 private static HashMap<Material, GLTextureBuffer> texturebuffer =
new HashMap<>();
20 if (texture ==
null) {
22 texturebuffer.put(m, texture);
26 public static synchronized void clear(GL gl) {
34 private HashMap<GL, Texture> tbuffer =
new HashMap<>();
39 Texture t = tbuffer.get(gl);
47 gl.glColor4ub((
byte) base.getRed(), (
byte) base.getGreen(), (
byte) base.getBlue(), (
byte) base.getAlpha());
50 gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT, m.ka, 0);
52 gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT, base.getComponents(
null), 0);
55 gl.glMaterialfv(GL.GL_FRONT, GL2.GL_DIFFUSE, m.kd, 0);
57 gl.glMaterialfv(GL.GL_FRONT, GL2.GL_DIFFUSE, base.getComponents(
null), 0);
60 gl.glMaterialfv(GL.GL_FRONT, GL2.GL_SPECULAR, m.ks, 0);
62 gl.glMaterialfv(GL.GL_FRONT, GL2.GL_SPECULAR, base.getComponents(
null), 0);
64 if (m.image !=
null) {
66 Texture t = getTexture(gl);
69 gl.glEnable(GL.GL_TEXTURE);
70 gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
71 }
catch (GLException gle) {
72 System.err.println(gle.getMessage());
77 private Texture getTexture(GL2 gl) {
78 Texture t = tbuffer.get(gl);
80 AWTTextureData atd =
new AWTTextureData(GLProfile.get(GLProfile.GL2), GL.GL_RGBA, GL.GL_RGBA,
false,
82 t =
new Texture(gl, atd);
83 t.setTexParameterf(gl, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
84 t.setTexParameterf(gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
91 if (m.image !=
null) {
92 Texture t = getTexture(gl);
94 gl.glDisable(GL.GL_TEXTURE);
void closeMaterial(GL2 gl)
static synchronized GLTextureBuffer get(Material m, GL gl)
static synchronized void clear(GL gl)
void openMaterial(Color base, GL2 gl)
GLTextureBuffer(Material m)