diff --git a/jsgl/src/main/java/jsgl/jogl/FrameBufferObject.java b/jsgl/src/main/java/jsgl/jogl/FrameBufferObject.java
index 73049d7a..531dcb69 100644
--- a/jsgl/src/main/java/jsgl/jogl/FrameBufferObject.java
+++ b/jsgl/src/main/java/jsgl/jogl/FrameBufferObject.java
@@ -30,8 +30,8 @@
* an FBO, it must be bound as the current Framebuffer.
*
* @author Justin Stoecker
- * @see http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt
- * @see http://www.songho.ca/opengl/gl_fbo.html
+ * @see ...
+ * @see ...
*/
public class FrameBufferObject implements GLDisposable
{
@@ -45,6 +45,10 @@ public class FrameBufferObject implements GLDisposable
private int texWidth;
private int texHeight;
+ public static FrameBufferObject create(GL2 gl, int w, int h, int glRgb) {
+ return null;
+ }
+
public int getID()
{
return id;
@@ -91,15 +95,10 @@ public static FrameBufferObject generate(GL gl)
* @param internalFormat -
* @return Returns a Framebuffer Objects if successful; null otherwise
*/
- public static FrameBufferObject create(GL gl, int w, int h, int internalFormat)
- {
+ public static FrameBufferObject create(GL gl, int w, int h, int internalFormat, Texture2D.Texture2DBuilder colorTexBuilder) {
Texture2D colorTex = Texture2D.generate(gl);
colorTex.bind(gl);
- Texture2D.setParameter(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
- Texture2D.setParameter(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
- Texture2D.setParameter(gl, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
- Texture2D.setParameter(gl, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
- colorTex.texImage(gl, 0, internalFormat, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
+ colorTexBuilder.build(gl, colorTex);
Texture2D.unbind(gl);
RenderBuffer depthBuffer = RenderBuffer.createDepthBuffer(gl, w, h);
@@ -120,16 +119,12 @@ public static FrameBufferObject create(GL gl, int w, int h, int internalFormat)
return fbo;
}
+
/** Creates an FBO with a color texture attachment and no depth attachment */
- public static FrameBufferObject createNoDepth(GL gl, int w, int h, int internalFormat)
- {
+ public static FrameBufferObject createNoDepth(GL gl, int w, int h, int internalFormat, Texture2D.Texture2DBuilder colorTexBuilder) {
Texture2D colorTex = Texture2D.generate(gl);
colorTex.bind(gl);
- Texture2D.setParameter(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
- Texture2D.setParameter(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
- Texture2D.setParameter(gl, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
- Texture2D.setParameter(gl, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
- colorTex.texImage(gl, 0, internalFormat, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
+ colorTexBuilder.build(gl, colorTex);
Texture2D.unbind(gl);
FrameBufferObject fbo = FrameBufferObject.generate(gl);
@@ -148,6 +143,7 @@ public static FrameBufferObject createNoDepth(GL gl, int w, int h, int internalF
return fbo;
}
+
/**
* Creates a Framebuffer Object that can be used for offscreen rendering to
* a texture of a specified with and height. This FBO is setup for
diff --git a/jsgl/src/main/java/jsgl/jogl/Texture2D.java b/jsgl/src/main/java/jsgl/jogl/Texture2D.java
index 4f59b655..39d2fb9d 100644
--- a/jsgl/src/main/java/jsgl/jogl/Texture2D.java
+++ b/jsgl/src/main/java/jsgl/jogl/Texture2D.java
@@ -117,7 +117,7 @@ public Texture2DBuilder data(Buffer data) {
}
public void build(GL gl, Texture2D texture) {
- texture.texImage(gl, level, internalFormat, width, height, border, format, type, data);
+ texture.texImage(gl, this);
}
}
diff --git a/jsgl/src/main/java/jsgl/jogl/model/ObjMaterialLibrary.java b/jsgl/src/main/java/jsgl/jogl/model/ObjMaterialLibrary.java
index 1b7c9f72..732c099b 100644
--- a/jsgl/src/main/java/jsgl/jogl/model/ObjMaterialLibrary.java
+++ b/jsgl/src/main/java/jsgl/jogl/model/ObjMaterialLibrary.java
@@ -16,11 +16,7 @@
package jsgl.jogl.model;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.util.ArrayList;
/**
@@ -65,7 +61,7 @@ private LineType getLineType(String line) {
return LineType.UNKNOWN;
}
- private void processLine(LineType lineType, String line, String texturePath, ClassLoader cl, ObjMaterial currentMaterial) {
+ private void processLine(LineType lineType, String line, String texturePath, ClassLoader cl, ObjMaterial currentMaterial) throws IOException {
switch (lineType) {
case NEW_MATERIAL:
// new material definition, so current material is finished
@@ -95,12 +91,11 @@ private void processLine(LineType lineType, String line, String texturePath, Cla
processTextureMap(line, texturePath, cl, currentMaterial);
break;
case UNKNOWN:
- // Handle unknown line type if needed
break;
}
}
- private void processTextureMap(String line, String texturePath, ClassLoader cl, ObjMaterial currentMaterial) {
+ private void processTextureMap(String line, String texturePath, ClassLoader cl, ObjMaterial currentMaterial) throws IOException {
String textureName = line.split("\\s+")[1];
InputStream is = null;
if (cl != null) {
diff --git a/jsgl/src/main/java/jsgl/jogl/model/ObjModel.java b/jsgl/src/main/java/jsgl/jogl/model/ObjModel.java
index ce758bea..bbb19208 100644
--- a/jsgl/src/main/java/jsgl/jogl/model/ObjModel.java
+++ b/jsgl/src/main/java/jsgl/jogl/model/ObjModel.java
@@ -18,10 +18,8 @@
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
+
+import java.io.*;
import java.util.ArrayList;
import jsgl.jogl.GLDisposable;
import jsgl.math.BoundingBox;
@@ -200,6 +198,49 @@ public static ObjModel load(File file) throws IOException
return model;
}
+ private static ObjGroup processGroup(String line, ObjModel model, ObjGroup currentGroup) {
+ if (currentGroup != null) model.groups.add(currentGroup);
+ return new ObjGroup(line.split("\\s+")[1]);
+ }
+
+
+ private static void processUseMaterial(String line, ObjModel model) {
+ String requestedMaterial = line.split("\\s+")[1];
+ ObjMaterial currentMaterial;
+ for (ObjMaterial mat : model.mtllib.materials)
+ if (mat.name.equals(requestedMaterial))
+ currentMaterial = mat;
+ }
+
+ private static void processMaterialLibrary(String line, File file, ObjModel model) throws IOException {
+ File f = new File(file.getParent(), line.split("\\s+")[1]);
+ if (model.mtllib == null) model.mtllib = new ObjMaterialLibrary();
+ BufferedReader br2 = new BufferedReader(new FileReader(f));
+ file.getParentFile();
+ model.mtllib.load(br2, file.getParent(), null);
+ // TODO: can files have multiple material libraries?
+ }
+
+
+ private static void processFaceLine(String line, ObjGroup currentGroup, ObjMaterial currentMaterial, ObjModel model) {
+ if (currentGroup == null) currentGroup = new ObjGroup("Unnamed Default Group");
+ currentGroup.faces.add(new Face(line, currentMaterial));
+ }
+
+
+ private static void processVertexLine(String line, ObjModel model, Vec3f min, Vec3f max) {
+ float[] vert = readFloatValues(line);
+ if (vert.length > 2) {
+ if (vert[0] > max.x) max.x = vert[0];
+ if (vert[1] > max.y) max.y = vert[1];
+ if (vert[2] > max.z) max.z = vert[2];
+ if (vert[0] < min.x) min.x = vert[0];
+ if (vert[1] < min.y) min.y = vert[1];
+ if (vert[2] < min.z) min.z = vert[2];
+ }
+ model.verts.add(vert);
+ }
+
private static LineType getLineType(String line) {
if (line.startsWith("v ")) return LineType.VERTEX;
if (line.startsWith("vn ")) return LineType.NORMAL;
diff --git a/jsgl/src/main/java/jsgl/math/vector/Vec3f.java b/jsgl/src/main/java/jsgl/math/vector/Vec3f.java
index a1dace76..3977b37d 100644
--- a/jsgl/src/main/java/jsgl/math/vector/Vec3f.java
+++ b/jsgl/src/main/java/jsgl/math/vector/Vec3f.java
@@ -17,6 +17,8 @@
package jsgl.math.vector;
import java.nio.FloatBuffer;
+
+import jsgl.math.Plane;
import jsgl.math.Tuplef;
/**
@@ -72,6 +74,37 @@ public Vec3f(float v)
this.z = v;
}
+ public static Vec3f intersectInfiniteLineWithPlane(Vec3f a, Vec3f b, Plane p) {
+ Vec3f n = p.getNormal();
+ Vec3f d = b.minus(a);
+
+ // ray's direction is parallel to surface of the plane
+ float nDotD = n.dot(d);
+ if (nDotD == 0)
+ return null;
+
+ float t = (n.dot(p.getPoint()) - n.dot(a)) / nDotD;
+
+ return a.plus(d.times(t));
+ }
+
+ public static Vec3f intersectLineSegmentWithPlane(Vec3f a, Vec3f b, Plane p) {
+ Vec3f n = p.getNormal();
+ Vec3f d = b.minus(a);
+
+ // ray's direction is parallel to surface of the plane
+ float nDotD = n.dot(d);
+ if (nDotD == 0)
+ return null;
+
+ float t = (n.dot(p.getPoint()) - n.dot(a)) / nDotD;
+
+ if (t >= 0 && t <= 1)
+ return a.plus(d.times(t));
+
+ return null;
+ }
+
/**
* Returns the result of the 3D dot product of this Vec3f and that Vec3f
*/
diff --git a/src/main/java/rv/world/rendering/ShadowMapRenderer.java b/src/main/java/rv/world/rendering/ShadowMapRenderer.java
index 80ec3f0d..d81f7957 100644
--- a/src/main/java/rv/world/rendering/ShadowMapRenderer.java
+++ b/src/main/java/rv/world/rendering/ShadowMapRenderer.java
@@ -133,7 +133,7 @@ private Texture2D createTexture(GL2 gl)
Texture2D.setParameter(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
Texture2D.setParameter(gl, GL.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP_TO_EDGE);
Texture2D.setParameter(gl, GL.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP_TO_EDGE);
- tex.texImage(gl, 0, TEX_FORMAT, texWidth, texHeight, 0, GL2.GL_RGBA, GL2.GL_FLOAT, null);
+ tex.texImage(gl, new Texture2D.Texture2DBuilder());
Texture2D.unbind(gl);
return tex;
diff --git a/src/main/kotlin/org/magmaoffenburg/roboviz/rendering/Renderer.kt b/src/main/kotlin/org/magmaoffenburg/roboviz/rendering/Renderer.kt
index 61258e36..4a9216f3 100644
--- a/src/main/kotlin/org/magmaoffenburg/roboviz/rendering/Renderer.kt
+++ b/src/main/kotlin/org/magmaoffenburg/roboviz/rendering/Renderer.kt
@@ -308,9 +308,9 @@ class Renderer : GLProgram(MainWindow.instance.width, MainWindow.instance.height
private fun genFBO(gl: GL2, vp: Viewport) {
if (numSamples > 0) {
msSceneFBO = FrameBufferObject.create(gl, vp.w, vp.h, GL.GL_RGBA, numSamples)
- sceneFBO = FrameBufferObject.createNoDepth(gl, vp.w, vp.h, GL.GL_RGB8)
+ sceneFBO = FrameBufferObject.createNoDepth(gl, vp.w, vp.h, GL.GL_RGB8, null);
} else {
- sceneFBO = FrameBufferObject.create(gl, vp.w, vp.h, GL.GL_RGB)
+ sceneFBO = FrameBufferObject.create(gl, vp.w, vp.h, GL.GL_RGB, null);
}
}