Permalink
Browse files

adding new lesson

  • Loading branch information...
1 parent 1f717bf commit cdf5c33c5365848e7e052036e1ff549dfc6c109f @mattdesl committed Jan 28, 2013
@@ -418,5 +418,4 @@ private void render() {
data.unbind();
renderCalls++;
}
-
}
@@ -206,7 +206,7 @@ public ShaderProgram(String vertexShaderSource, String fragShaderSource,
try {
linkProgram(attribLocations);
} catch (LWJGLException e) {
- release();
+ dispose();
throw e;
}
//TODO: for convenience it might be nice to warn non-critical errors in a log
@@ -363,7 +363,7 @@ public void use() {
* however, since it is not a commonly used feature and thus not well tested
* on all drivers, it should be used with caution. Shaders shouldn't be used
* after being released. */
- public void releaseShaders() {
+ public void disposeShaders() {
if (vert != 0) {
glDetachShader(getID(), vert);
glDeleteShader(vert);
@@ -378,11 +378,11 @@ public void releaseShaders() {
/** If this program has not yet been released, this will releases
* this program and its shaders. To only release the
- * shaders (not the program itself), call releaseShaders(). Programs will be
+ * shaders (not the program itself), call disposeShaders(). Programs will be
* considered "invalid" after being released, and should no longer be used. */
- public void release() {
+ public void dispose() {
if (program != 0) {
- releaseShaders();
+ disposeShaders();
glDeleteProgram(program);
program = 0;
}
@@ -1048,11 +1048,11 @@ public void setUniformf(int loc, Vector2f v) {
public void setUniformf(int loc, Vector3f v) {
if (loc==-1) return;
- setUniformf(loc, v.x, v.y, v.y);
+ setUniformf(loc, v.x, v.y, v.z);
}
public void setUniformf(int loc, Vector4f v) {
if (loc==-1) return;
- setUniformf(loc, v.x, v.y, v.y, v.z);
+ setUniformf(loc, v.x, v.y, v.z, v.w);
}
}
@@ -42,14 +42,19 @@
public class VertexArray implements VertexData {
- protected List<VertexAttrib> attributes;
+ protected VertexAttrib[] attributes;
private int totalNumComponents;
private int stride;
private FloatBuffer buffer;
private int vertCount;
- public VertexArray(int vertCount, List<VertexAttrib> attributes) {
+ /**
+ *
+ * @param vertCount the number of VERTICES; e.g. 3 verts to make a triangle, regardless of number of attributes
+ * @param attributes a list of attributes per vertex
+ */
+ public VertexArray(int vertCount, VertexAttrib ... attributes) {
this.attributes = attributes;
for (VertexAttrib a : attributes)
totalNumComponents += a.numComponents;
@@ -59,6 +64,10 @@ public VertexArray(int vertCount, List<VertexAttrib> attributes) {
this.buffer = BufferUtils.createFloatBuffer(vertCount * totalNumComponents);
}
+ public VertexArray(int vertCount, List<VertexAttrib> attributes) {
+ this(vertCount, attributes.toArray(new VertexAttrib[attributes.size()]));
+ }
+
public VertexArray flip() {
buffer.flip();
return this;
@@ -96,8 +105,8 @@ public void bind() {
//4 bytes per float
int stride = totalNumComponents * 4;
- for (int i=0; i<attributes.size(); i++) {
- VertexAttrib a = attributes.get(i);
+ for (int i=0; i<attributes.length; i++) {
+ VertexAttrib a = attributes[i];
buffer.position(offset);
glEnableVertexAttribArray(a.location);
glVertexAttribPointer(a.location, a.numComponents, false, stride, buffer);
@@ -110,8 +119,8 @@ public void draw(int geom, int first, int count) {
}
public void unbind() {
- for (int i=0; i<attributes.size(); i++) {
- VertexAttrib a = attributes.get(i);
+ for (int i=0; i<attributes.length; i++) {
+ VertexAttrib a = attributes[i];
glDisableVertexAttribArray(a.location);
}
}
@@ -213,7 +213,7 @@ protected void parseFont(InputStream fontFile, Charset charset) throws IOExcepti
line = br.readLine();
if (line == null) break;
if (line.startsWith("chars")) {
- System.out.println(line);
+// System.out.println(line);
int count = parseInt(line, "count");
glyphsList = new ArrayList<Glyph>(count);
continue;
@@ -299,4 +299,12 @@ protected void parseFont(InputStream fontFile, Charset charset) throws IOExcepti
//silent
}
}
+
+ /**
+ * Disposes all texture pages associated with this font.
+ */
+ public void dispose() {
+ for (TextureRegion t : getTexturePages())
+ t.getTexture().dispose();
+ }
}
@@ -109,4 +109,38 @@ public static Matrix4f toOrtho(Matrix4f m, float left, float right, float bottom
m.m33 = 1;
return m;
}
+
+
+ /** Sets the matrix to a projection matrix with a near- and far plane, a field of view in degrees and an aspect ratio.
+ *
+ * @param near The near plane
+ * @param far The far plane
+ * @param fov The field of view in degrees
+ * @param aspectRatio The aspect ratio
+ * @return This matrix for the purpose of chaining methods together. */
+ public static Matrix4f setToProjection (Matrix4f m, float near, float far, float fov, float aspectRatio) {
+ if (m==null)
+ m = new Matrix4f();
+ m.setIdentity();
+ float l_fd = (float)(1.0 / Math.tan((fov * (Math.PI / 180)) / 2.0));
+ float l_a1 = (far + near) / (near - far);
+ float l_a2 = (2 * far * near) / (near - far);
+ m.m00 = l_fd / aspectRatio;
+ m.m10 = 0;
+ m.m20 = 0;
+ m.m30 = 0;
+ m.m01 = 0;
+ m.m11 = l_fd;
+ m.m21 = 0;
+ m.m31 = 0;
+ m.m02 = 0;
+ m.m12 = 0;
+ m.m22 = l_a1;
+ m.m32 = -1;
+ m.m03 = 0;
+ m.m13 = 0;
+ m.m23 = l_a2;
+ m.m33 = 0;
+ return m;
+ }
}
Oops, something went wrong.

0 comments on commit cdf5c33

Please sign in to comment.