* the gdx jar file. This is here to get you up and running quickly.\r
*/\r
public BitmapFont() {\r
- \r
+\r
this(new FileHandle() {\r
@Override\r
public String getPath() {\r
import com.badlogic.gdx.graphics.BitmapFont.HAlignment;\r
\r
/**\r
- * A BitmapFontCache caches glyph geometry for a BitmapFont, providing a fast way to render static text. <br>\r
+ * A BitmapFontCache caches glyph geometry for a BitmapFont, providing a fast\r
+ * way to render static text. <br>\r
* <br>\r
- * The code is heavily based on Matthias Mann's TWL BitmapFont class. Thanks for sharing, Matthias! :)\r
+ * The code is heavily based on Matthias Mann's TWL BitmapFont class. Thanks for\r
+ * sharing, Matthias! :)\r
+ * \r
* @author Nathan Sweet <misc@n4te.com>\r
* @author Matthias Mann\r
*/\r
private float x, y;\r
private float color;\r
\r
- public BitmapFontCache (BitmapFont font) {\r
+ public BitmapFontCache(BitmapFont font) {\r
this.font = font;\r
}\r
\r
/**\r
- * Sets the position of the text, relative to the position when the cached text was created.\r
- * @param x The x coordinate\r
- * @param y The y coodinate\r
+ * Sets the position of the text, relative to the position when the cached\r
+ * text was created.\r
+ * \r
+ * @param x\r
+ * The x coordinate\r
+ * @param y\r
+ * The y coodinate\r
*/\r
- public void setPosition (float x, float y) {\r
+ public void setPosition(float x, float y) {\r
translate(x - this.x, y - this.y);\r
}\r
\r
/**\r
* Sets the position of the text, relative to its current position.\r
- * @param xAmount The amount in x to move the text\r
- * @param yAmount The amount in y to move the text\r
+ * \r
+ * @param xAmount\r
+ * The amount in x to move the text\r
+ * @param yAmount\r
+ * The amount in y to move the text\r
*/\r
- public void translate (float xAmount, float yAmount) {\r
- if (xAmount == 0 && yAmount == 0) return;\r
+ public void translate(float xAmount, float yAmount) {\r
+ if (xAmount == 0 && yAmount == 0)\r
+ return;\r
x += xAmount;\r
y += yAmount;\r
float[] vertices = this.vertices;\r
\r
/**\r
* Sets the tint color of the text.\r
- * @param tint The {@link Color}\r
+ * \r
+ * @param tint\r
+ * The {@link Color}\r
*/\r
- public void setColor (Color tint) {\r
+ public void setColor(Color tint) {\r
final float color = tint.toFloatBits();\r
- if (color == this.color) return;\r
+ if (color == this.color)\r
+ return;\r
this.color = color;\r
float[] vertices = this.vertices;\r
for (int i = 2, n = idx; i < n; i += 5)\r
/**\r
* Sets the tint color of the text.\r
*/\r
- public void setColor (float r, float g, float b, float a) {\r
- int intBits = ((int)(255 * a) << 24) | ((int)(255 * b) << 16) | ((int)(255 * g) << 8) | ((int)(255 * r));\r
+ public void setColor(float r, float g, float b, float a) {\r
+ int intBits = ((int) (255 * a) << 24) | ((int) (255 * b) << 16)\r
+ | ((int) (255 * g) << 8) | ((int) (255 * r));\r
float color = Float.intBitsToFloat(intBits);\r
- if (color == this.color) return;\r
+ if (color == this.color)\r
+ return;\r
this.color = color;\r
float[] vertices = this.vertices;\r
for (int i = 2, n = idx; i < n; i += 5)\r
}\r
\r
/**\r
- * Draws the contents of the cache via a {@link SpriteBatch}. Must be called between a {@link SpriteBatch#begin()}/\r
- * {@link SpriteBatch#end()} pair.\r
- * @param spriteBatch The SpriteBatch\r
+ * Draws the contents of the cache via a {@link SpriteBatch}. Must be called\r
+ * between a {@link SpriteBatch#begin()}/ {@link SpriteBatch#end()} pair.\r
+ * \r
+ * @param spriteBatch\r
+ * The SpriteBatch\r
*/\r
- public void draw (SpriteBatch spriteBatch) {\r
+ public void draw(SpriteBatch spriteBatch) {\r
spriteBatch.draw(font.texture, vertices, 0, idx);\r
}\r
\r
- void reset (int glyphCount) {\r
+ void reset(int glyphCount) {\r
x = 0;\r
y = 0;\r
idx = 0;\r
\r
int vertexCount = glyphCount * 20;\r
- if (vertices == null || vertices.length < vertexCount) vertices = new float[vertexCount];\r
+ if (vertices == null || vertices.length < vertexCount)\r
+ vertices = new float[vertexCount];\r
}\r
\r
- private int addToCache (CharSequence str, int x, int y, float color, int start, int end) {\r
+ private int addToCache(CharSequence str, int x, int y, float color,\r
+ int start, int end) {\r
BitmapFont font = this.font;\r
Glyph lastGlyph = null;\r
while (start < end) {\r
return x;\r
}\r
\r
- void addGlyph (Glyph glyph, float x, float y, float color) {\r
+ void addGlyph(Glyph glyph, float x, float y, float color) {\r
x += glyph.xoffset;\r
y += glyph.yoffset;\r
final float x2 = x + glyph.width;\r
}\r
\r
/**\r
- * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}.\r
- * @param str The string\r
- * @param x The x position of the left most character\r
- * @param y The y position of the left most character's top left corner\r
- * @param tint The color\r
+ * Caches the given string at the given position with the given color in the\r
+ * provided {@link BitmapFontCache}.\r
+ * \r
+ * @param str\r
+ * The string\r
+ * @param x\r
+ * The x position of the left most character\r
+ * @param y\r
+ * The y position of the left most character's top left corner\r
+ * @param tint\r
+ * The color\r
*/\r
- public void setText (CharSequence str, int x, int y, Color tint) {\r
+ public void setText(CharSequence str, int x, int y, Color tint) {\r
setText(str, x, y, tint, 0, str.length());\r
}\r
\r
/**\r
- * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}.\r
- * @param str The string\r
- * @param x The x position of the left most character\r
- * @param y The y position of the left most character's top left corner\r
- * @param tint The color\r
- * @param start The first character of the string to draw\r
- * @param end The last character of the string to draw\r
+ * Caches the given string at the given position with the given color in the\r
+ * provided {@link BitmapFontCache}.\r
+ * \r
+ * @param str\r
+ * The string\r
+ * @param x\r
+ * The x position of the left most character\r
+ * @param y\r
+ * The y position of the left most character's top left corner\r
+ * @param tint\r
+ * The color\r
+ * @param start\r
+ * The first character of the string to draw\r
+ * @param end\r
+ * The last character of the string to draw\r
*/\r
- public void setText (CharSequence str, int x, int y, Color tint, int start, int end) {\r
+ public void setText(CharSequence str, int x, int y, Color tint, int start,\r
+ int end) {\r
final float color = tint.toFloatBits();\r
reset(end - start);\r
y += font.yOffset;\r
}\r
\r
/**\r
- * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
- * coincides with the top left corner of the first line's glyph. The method interprets new lines.\r
- * @param str The string\r
- * @param x The x position of the left most character of the first line\r
- * @param y The y position of the left most character's top left corner of the first line\r
- * @param tint The color\r
+ * Caches the given string at the given position with the given color in the\r
+ * provided {@link BitmapFontCache}. The position coincides with the top\r
+ * left corner of the first line's glyph. The method interprets new lines.\r
+ * \r
+ * @param str\r
+ * The string\r
+ * @param x\r
+ * The x position of the left most character of the first line\r
+ * @param y\r
+ * The y position of the left most character's top left corner of\r
+ * the first line\r
+ * @param tint\r
+ * The color\r
*/\r
- public void setMultiLineText (CharSequence str, int x, int y, Color tint) {\r
+ public void setMultiLineText(CharSequence str, int x, int y, Color tint) {\r
setMultiLineText(str, x, y, tint, 0, HAlignment.LEFT);\r
}\r
\r
/**\r
- * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
- * coincides with the top left corner of the first line's glyph. The method interprets new lines. <br>\r
+ * Caches the given string at the given position with the given color in the\r
+ * provided {@link BitmapFontCache}. The position coincides with the top\r
+ * left corner of the first line's glyph. The method interprets new lines. <br>\r
* <br>\r
- * You can specify the horizontal alignment of the text with the <code>alignmentWidth</code> and <code>alignment</code>\r
- * parameters. The first parameter specifies the width of the rectangle the text should be aligned in (x to x +\r
- * alignmentWidth). The second parameter specifies the alignment itself.\r
- * @param str The string\r
- * @param x The x position of the left most character of the first line\r
- * @param y The y position of the left most character's top left corner of the first line\r
- * @param tint The color\r
- * @param alignmentWidth The alignment width\r
- * @param alignment The horizontal alignment\r
+ * You can specify the horizontal alignment of the text with the\r
+ * <code>alignmentWidth</code> and <code>alignment</code> parameters. The\r
+ * first parameter specifies the width of the rectangle the text should be\r
+ * aligned in (x to x + alignmentWidth). The second parameter specifies the\r
+ * alignment itself.\r
+ * \r
+ * @param str\r
+ * The string\r
+ * @param x\r
+ * The x position of the left most character of the first line\r
+ * @param y\r
+ * The y position of the left most character's top left corner of\r
+ * the first line\r
+ * @param tint\r
+ * The color\r
+ * @param alignmentWidth\r
+ * The alignment width\r
+ * @param alignment\r
+ * The horizontal alignment\r
*/\r
- public void setMultiLineText (CharSequence str, int x, int y, Color tint, int alignmentWidth, HAlignment alignment) {\r
+ public void setMultiLineText(CharSequence str, int x, int y, Color tint,\r
+ int alignmentWidth, HAlignment alignment) {\r
BitmapFont font = this.font;\r
\r
int length = str.length();\r
if (alignment != HAlignment.LEFT) {\r
int lineWidth = font.computeTextWidth(str, start, lineEnd);\r
xOffset = alignmentWidth - lineWidth;\r
- if (alignment == HAlignment.CENTER) xOffset /= 2;\r
+ if (alignment == HAlignment.CENTER)\r
+ xOffset /= 2;\r
}\r
addToCache(str, x + xOffset, y, color, start, lineEnd);\r
start = lineEnd + 1;\r
}\r
\r
/**\r
- * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
- * coincides with the top left corner of the first line's glyph. This method interprets new lines and causes the text to wrap\r
- * at spaces based on the given <code>wrapWidth</code>. The wrapped text is left aligned.\r
- * @param str The string\r
- * @param x The x position of the left most character of the first line\r
- * @param y The y position of the left most character's top left corner of the first line\r
- * @param tint The color\r
- * @param wrapWidth The wrap width\r
+ * Caches the given string at the given position with the given color in the\r
+ * provided {@link BitmapFontCache}. The position coincides with the top\r
+ * left corner of the first line's glyph. This method interprets new lines\r
+ * and causes the text to wrap at spaces based on the given\r
+ * <code>wrapWidth</code>. The wrapped text is left aligned.\r
+ * \r
+ * @param str\r
+ * The string\r
+ * @param x\r
+ * The x position of the left most character of the first line\r
+ * @param y\r
+ * The y position of the left most character's top left corner of\r
+ * the first line\r
+ * @param tint\r
+ * The color\r
+ * @param wrapWidth\r
+ * The wrap width\r
*/\r
- public void setWrappedText (CharSequence str, int x, int y, Color tint, int wrapWidth) {\r
+ public void setWrappedText(CharSequence str, int x, int y, Color tint,\r
+ int wrapWidth) {\r
setWrappedText(str, x, y, tint, wrapWidth, HAlignment.LEFT);\r
}\r
\r
/**\r
- * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
- * coincides with the top left corner of the first line's glyph. This method interprets new lines and causes the text to wrap\r
- * at spaces based on the given <code>wrapWidth</code>. <br>\r
+ * Caches the given string at the given position with the given color in the\r
+ * provided {@link BitmapFontCache}. The position coincides with the top\r
+ * left corner of the first line's glyph. This method interprets new lines\r
+ * and causes the text to wrap at spaces based on the given\r
+ * <code>wrapWidth</code>. <br>\r
* <br>\r
- * You can specify the horizontal alignment of the text within the <code>wrapWidth</code> by using the <code>alignment</code>\r
- * parameter.\r
- * @param str The string\r
- * @param x The x position of the left most character of the first line\r
- * @param y The y position of the left most character's top left corner of the first line\r
- * @param tint The color\r
- * @param wrapWidth The wrap width\r
+ * You can specify the horizontal alignment of the text within the\r
+ * <code>wrapWidth</code> by using the <code>alignment</code> parameter.\r
+ * \r
+ * @param str\r
+ * The string\r
+ * @param x\r
+ * The x position of the left most character of the first line\r
+ * @param y\r
+ * The y position of the left most character's top left corner of\r
+ * the first line\r
+ * @param tint\r
+ * The color\r
+ * @param wrapWidth\r
+ * The wrap width\r
*/\r
- public void setWrappedText (CharSequence str, int x, int y, Color tint, int wrapWidth, HAlignment alignment) {\r
+ public void setWrappedText(CharSequence str, int x, int y, Color tint,\r
+ int wrapWidth, HAlignment alignment) {\r
BitmapFont font = this.font;\r
\r
int length = str.length();\r
int start = 0;\r
int numLines = 0;\r
while (start < length) {\r
- int lineEnd = start + font.computeVisibleGlpyhs(str, start, BitmapFont.indexOf(str, '\n', start), wrapWidth);\r
+ int lineEnd = start\r
+ + font.computeVisibleGlpyhs(str, start,\r
+ BitmapFont.indexOf(str, '\n', start), wrapWidth);\r
if (lineEnd < length) {\r
while (lineEnd > start) {\r
char ch = str.charAt(lineEnd);\r
- if (ch == ' ' || ch == '\n') break;\r
+ if (ch == ' ' || ch == '\n')\r
+ break;\r
lineEnd--;\r
}\r
}\r
- if (lineEnd == start) lineEnd++;\r
+ if (lineEnd == start)\r
+ lineEnd++;\r
int xOffset = 0;\r
if (alignment != HAlignment.LEFT) {\r
int lineWidth = font.computeTextWidth(str, start, lineEnd);\r
xOffset = wrapWidth - lineWidth;\r
- if (alignment == HAlignment.CENTER) xOffset /= 2;\r
+ if (alignment == HAlignment.CENTER)\r
+ xOffset /= 2;\r
}\r
addToCache(str, x + xOffset, y, color, start, lineEnd);\r
start = lineEnd + 1;\r
/**\r
* @return The width of the contained text\r
*/\r
- public int getWidth () {\r
+ public int getWidth() {\r
return width;\r
}\r
\r
/**\r
* @return The height of the contained text\r
*/\r
- public int getHeight () {\r
+ public int getHeight() {\r
return height;\r
}\r
\r
/**\r
- * @return The x coordinate of the contained text, relative to the position when the cached text was created\r
+ * @return The x coordinate of the contained text, relative to the position\r
+ * when the cached text was created\r
*/\r
- public float getX () {\r
+ public float getX() {\r
return x;\r
}\r
\r
/**\r
- * @return The y coordinate of the contained text, relative to the position when the cached text was created\r
+ * @return The y coordinate of the contained text, relative to the position\r
+ * when the cached text was created\r
*/\r
- public float getY () {\r
+ public float getY() {\r
return y;\r
}\r
}\r
package com.badlogic.gdx.graphics;\r
\r
/**\r
- * A color class, holding the r, g, b and alpha component as floats in the range [0,1]. All methods perform clamping on the\r
- * internal values after execution.\r
+ * A color class, holding the r, g, b and alpha component as floats in the range\r
+ * [0,1]. All methods perform clamping on the internal values after execution.\r
* \r
* @author mzechner\r
* \r
\r
/**\r
* Constructor, sets the components of the color\r
- * @param r the red component\r
- * @param g the green component\r
- * @param b the blue component\r
- * @param a the alpha component\r
+ * \r
+ * @param r\r
+ * the red component\r
+ * @param g\r
+ * the green component\r
+ * @param b\r
+ * the blue component\r
+ * @param a\r
+ * the alpha component\r
*/\r
- public Color (float r, float g, float b, float a) {\r
+ public Color(float r, float g, float b, float a) {\r
this.r = r;\r
this.g = g;\r
this.b = b;\r
\r
/**\r
* Constructs a new color using the given color\r
- * @param color the color\r
+ * \r
+ * @param color\r
+ * the color\r
*/\r
- public Color (Color color) {\r
+ public Color(Color color) {\r
set(color);\r
}\r
\r
/**\r
* Sets this color to the given color.\r
- * @param color the Color\r
+ * \r
+ * @param color\r
+ * the Color\r
*/\r
- public Color set (Color color) {\r
+ public Color set(Color color) {\r
this.r = color.r;\r
this.g = color.g;\r
this.b = color.b;\r
\r
/**\r
* Multiplies the this color and the given color\r
- * @param color the color\r
+ * \r
+ * @param color\r
+ * the color\r
* @return this color.\r
*/\r
- public Color mul (Color color) {\r
+ public Color mul(Color color) {\r
this.r *= color.r;\r
this.g *= color.g;\r
this.b *= color.b;\r
/**\r
* Multiplies all components of this Color with the given value.\r
* \r
- * @param value the value\r
+ * @param value\r
+ * the value\r
* @return this color\r
*/\r
- public Color mul (float value) {\r
+ public Color mul(float value) {\r
this.r *= value;\r
this.g *= value;\r
this.b *= value;\r
\r
/**\r
* Adds the given color to this color.\r
- * @param color the color\r
+ * \r
+ * @param color\r
+ * the color\r
* @return this color\r
*/\r
- public Color add (Color color) {\r
+ public Color add(Color color) {\r
this.r += color.r;\r
this.g += color.g;\r
this.b += color.b;\r
\r
/**\r
* Subtracts the given color from this color\r
- * @param color the color\r
+ * \r
+ * @param color\r
+ * the color\r
* @return this color\r
*/\r
- public Color sub (Color color) {\r
+ public Color sub(Color color) {\r
this.r -= color.r;\r
this.g -= color.g;\r
this.b -= color.b;\r
return this;\r
}\r
\r
- public void clamp () {\r
- if (r < 0) r = 0;\r
- if (r > 1) r = 1;\r
+ public void clamp() {\r
+ if (r < 0)\r
+ r = 0;\r
+ if (r > 1)\r
+ r = 1;\r
\r
- if (g < 0) g = 0;\r
- if (g > 1) g = 1;\r
+ if (g < 0)\r
+ g = 0;\r
+ if (g > 1)\r
+ g = 1;\r
\r
- if (b < 0) b = 0;\r
- if (b > 1) b = 1;\r
+ if (b < 0)\r
+ b = 0;\r
+ if (b > 1)\r
+ b = 1;\r
\r
- if (a < 0) a = 0;\r
- if (a > 1) a = 1;\r
+ if (a < 0)\r
+ a = 0;\r
+ if (a > 1)\r
+ a = 1;\r
}\r
\r
- public void set (float r, float g, float b, float a) {\r
+ public void set(float r, float g, float b, float a) {\r
this.r = r;\r
this.g = g;\r
this.b = b;\r
this.a = a;\r
}\r
\r
- @Override public boolean equals (Object o) {\r
- if (this == o) return true;\r
- if (o == null || getClass() != o.getClass()) return false;\r
+ @Override\r
+ public boolean equals(Object o) {\r
+ if (this == o)\r
+ return true;\r
+ if (o == null || getClass() != o.getClass())\r
+ return false;\r
\r
- Color color = (Color)o;\r
+ Color color = (Color) o;\r
\r
- if (Float.compare(color.a, a) != 0) return false;\r
- if (Float.compare(color.b, b) != 0) return false;\r
- if (Float.compare(color.g, g) != 0) return false;\r
- if (Float.compare(color.r, r) != 0) return false;\r
+ if (Float.compare(color.a, a) != 0)\r
+ return false;\r
+ if (Float.compare(color.b, b) != 0)\r
+ return false;\r
+ if (Float.compare(color.g, g) != 0)\r
+ return false;\r
+ if (Float.compare(color.r, r) != 0)\r
+ return false;\r
\r
return true;\r
}\r
\r
- @Override public int hashCode () {\r
+ @Override\r
+ public int hashCode() {\r
int result = (r != +0.0f ? Float.floatToIntBits(r) : 0);\r
result = 31 * result + (g != +0.0f ? Float.floatToIntBits(g) : 0);\r
result = 31 * result + (b != +0.0f ? Float.floatToIntBits(b) : 0);\r
}\r
\r
/**\r
- * Packs the four color components which should be in the range 0-255 into a 32-bit integer and then converts it to a float.\r
- * Note that no range checking is performed for higher performance.\r
- * @param r the red component, 0 - 255\r
- * @param g the green component, 0 - 255\r
- * @param b the blue component, 0 - 255\r
- * @param a the alpha component, 0 - 255\r
+ * Packs the four color components which should be in the range 0-255 into a\r
+ * 32-bit integer and then converts it to a float. Note that no range\r
+ * checking is performed for higher performance.\r
+ * \r
+ * @param r\r
+ * the red component, 0 - 255\r
+ * @param g\r
+ * the green component, 0 - 255\r
+ * @param b\r
+ * the blue component, 0 - 255\r
+ * @param a\r
+ * the alpha component, 0 - 255\r
* @return the packed color as a float\r
*/\r
- public static float toFloatBits (int r, int g, int b, int a) {\r
+ public static float toFloatBits(int r, int g, int b, int a) {\r
int color = (a << 24) | (b << 16) | (g << 8) | r;\r
float floatColor = Float.intBitsToFloat(color);\r
return floatColor;\r
}\r
\r
/**\r
- * Packs the four color components which should be in the range 0-255 into a 32-bit. Note that no range checking is performed\r
- * for higher performance.\r
- * @param r the red component, 0 - 255\r
- * @param g the green component, 0 - 255\r
- * @param b the blue component, 0 - 255\r
- * @param a the alpha component, 0 - 255\r
+ * Packs the four color components which should be in the range 0-255 into a\r
+ * 32-bit. Note that no range checking is performed for higher performance.\r
+ * \r
+ * @param r\r
+ * the red component, 0 - 255\r
+ * @param g\r
+ * the green component, 0 - 255\r
+ * @param b\r
+ * the blue component, 0 - 255\r
+ * @param a\r
+ * the alpha component, 0 - 255\r
* @return the packed color as a 32-bit int\r
*/\r
- public static float toIntBits (int r, int g, int b, int a) {\r
+ public static float toIntBits(int r, int g, int b, int a) {\r
return (a << 24) | (b << 16) | (g << 8) | r;\r
\r
}\r
\r
/**\r
- * Packs the 4 components of this color into a 32-bit int and returns it as a float.\r
+ * Packs the 4 components of this color into a 32-bit int and returns it as\r
+ * a float.\r
* \r
* @return the packed color as a 32-bit float\r
*/\r
- public float toFloatBits () {\r
- int color = ((int)(255 * a) << 24) | ((int)(255 * b) << 16) | ((int)(255 * g) << 8) | ((int)(255 * r));\r
+ public float toFloatBits() {\r
+ int color = ((int) (255 * a) << 24) | ((int) (255 * b) << 16)\r
+ | ((int) (255 * g) << 8) | ((int) (255 * r));\r
return Float.intBitsToFloat(color);\r
}\r
\r
/**\r
* Packs the 4 components of this color into a 32-bit int.\r
+ * \r
* @return the packed color as a 32-bit int.\r
*/\r
- public int toIntBits () {\r
- int color = ((int)(255 * a) << 24) | ((int)(255 * b) << 16) | ((int)(255 * g) << 8) | ((int)(255 * r));\r
+ public int toIntBits() {\r
+ int color = ((int) (255 * a) << 24) | ((int) (255 * b) << 16)\r
+ | ((int) (255 * g) << 8) | ((int) (255 * r));\r
return color;\r
}\r
\r
/**\r
- * Packs the 4 components of this color into a 32-bit int and returns it as a float.\r
+ * Packs the 4 components of this color into a 32-bit int and returns it as\r
+ * a float.\r
* \r
* @return the packed color as a 32-bit float\r
*/\r
- public static float toFloatBits (float r, float g, float b, float a) {\r
- int color = ((int)(255 * a) << 24) | ((int)(255 * b) << 16) | ((int)(255 * g) << 8) | ((int)(255 * r));\r
+ public static float toFloatBits(float r, float g, float b, float a) {\r
+ int color = ((int) (255 * a) << 24) | ((int) (255 * b) << 16)\r
+ | ((int) (255 * g) << 8) | ((int) (255 * r));\r
return Float.intBitsToFloat(color);\r
}\r
}\r
\r
/**\r
* An ImmediateModeRenderer allows you to perform immediate mode rendering as you were accustomed to in your desktop OpenGL\r
- * environment. In order to draw something you first have to call {@link ImmediateModeRenderer.begin()} with the primitive type\r
+ * environment. In order to draw something you first have to call {@link ImmediateModeRenderer#begin(int)} with the primitive type\r
* you want to render. Next you specify as many vertices as you want by first defining the vertex color, normal and texture\r
* coordinates followed by the vertex position which finalizes the definition of a single vertex. When you are done specifying the\r
- * geometry you have to call {@link ImmediateModeRenderer.end()} to make the renderer render the geometry. Internally the renderer\r
+ * geometry you have to call {@link ImmediateModeRenderer#end()} to make the renderer render the geometry. Internally the renderer\r
* uses vertex arrays to render the provided geometry. This is not the best performing way to do this so use this class only for\r
* non performance critical low vertex count geometries while debugging.\r
* \r
\r
/**\r
* Constructs a new ImmediateModeRenderer\r
- * @param gl\r
*/\r
public ImmediateModeRenderer () {\r
if (Gdx.graphics.isGL20Available())\r
-\r
package com.badlogic.gdx.graphics;\r
\r
import java.nio.FloatBuffer;\r
\r
/**\r
* <p>\r
- * A Mesh holds vertices composed of attributes specified by a {@link VertexAttributes} instance. The vertices are held either in\r
- * VRAM in form of vertex buffer objects or in RAM in form of vertex arrays. The former variant is more performant and is prefered\r
- * over vertex arrays if hardware supports it.\r
+ * A Mesh holds vertices composed of attributes specified by a\r
+ * {@link VertexAttributes} instance. The vertices are held either in VRAM in\r
+ * form of vertex buffer objects or in RAM in form of vertex arrays. The former\r
+ * variant is more performant and is prefered over vertex arrays if hardware\r
+ * supports it.\r
* </p>\r
* \r
* <p>\r
- * Meshes are automatically managed. If the OpenGL context is lost all vertex buffer objects get invalidated and must be reloaded\r
- * when the context is recreated. This only happens on Android when a user switches to another application or receives an incoming\r
- * call. A managed Mesh will be reloaded automagically so you don't have to do this manually.\r
+ * Meshes are automatically managed. If the OpenGL context is lost all vertex\r
+ * buffer objects get invalidated and must be reloaded when the context is\r
+ * recreated. This only happens on Android when a user switches to another\r
+ * application or receives an incoming call. A managed Mesh will be reloaded\r
+ * automagically so you don't have to do this manually.\r
* </p>\r
* \r
* <p>\r
- * A Mesh consists of vertices and optionally indices which specify which vertices define a triangle. Each vertex is composed of\r
- * attributes such as position, normal, color or texture coordinate. Note that not all of this attributes must be given, except\r
- * for position which is non-optional. Each attribute has an alias which is used when rendering a Mesh in OpenGL ES 2.0. The alias\r
- * is used to bind a specific vertex attribute to a shader attribute. The shader source and the alias of the attribute must match\r
- * exactly for this to work. For OpenGL ES 1.x rendering this aliases are irrelevant.\r
+ * A Mesh consists of vertices and optionally indices which specify which\r
+ * vertices define a triangle. Each vertex is composed of attributes such as\r
+ * position, normal, color or texture coordinate. Note that not all of this\r
+ * attributes must be given, except for position which is non-optional. Each\r
+ * attribute has an alias which is used when rendering a Mesh in OpenGL ES 2.0.\r
+ * The alias is used to bind a specific vertex attribute to a shader attribute.\r
+ * The shader source and the alias of the attribute must match exactly for this\r
+ * to work. For OpenGL ES 1.x rendering this aliases are irrelevant.\r
* </p>\r
* \r
* <p>\r
*/\r
public class Mesh {\r
/** list of all meshes **/\r
- static final ArrayList<Mesh> meshes = new ArrayList<Mesh>(); \r
+ static final ArrayList<Mesh> meshes = new ArrayList<Mesh>();\r
\r
final VertexData vertices;\r
final IndexBufferObject indices;\r
boolean autoBind = true;\r
final boolean isVertexArray;\r
- \r
+\r
/**\r
* Creates a new Mesh with the given attributes.\r
* \r
- * @param isStatic whether this mesh is static or not. Allows for internal optimizations. \r
- * @param maxVertices the maximum number of vertices this mesh can hold\r
- * @param maxIndices the maximum number of indices this mesh can hold\r
- * @param attributes the {@link VertexAttribute}s. Each vertex attribute defines one property of a vertex such as position,\r
- * normal or texture coordinate\r
+ * @param isStatic\r
+ * whether this mesh is static or not. Allows for internal\r
+ * optimizations.\r
+ * @param maxVertices\r
+ * the maximum number of vertices this mesh can hold\r
+ * @param maxIndices\r
+ * the maximum number of indices this mesh can hold\r
+ * @param attributes\r
+ * the {@link VertexAttribute}s. Each vertex attribute defines\r
+ * one property of a vertex such as position, normal or texture\r
+ * coordinate\r
*/\r
- public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttribute... attributes) {\r
- if(Gdx.gl11 != null || Gdx.gl20 != null ) {\r
+ public Mesh(boolean isStatic, int maxVertices, int maxIndices,\r
+ VertexAttribute... attributes) {\r
+ if (Gdx.gl11 != null || Gdx.gl20 != null) {\r
vertices = new VertexBufferObject(isStatic, maxVertices, attributes);\r
indices = new IndexBufferObject(isStatic, maxIndices);\r
isVertexArray = false;\r
- }\r
- else {\r
+ } else {\r
vertices = new VertexArray(maxVertices, attributes);\r
indices = new IndexBufferObject(maxIndices);\r
isVertexArray = true;\r
- } \r
- \r
+ }\r
+\r
meshes.add(this);\r
}\r
\r
/**\r
- * Sets the vertices of this Mesh. The attributes are assumed to be given in float format. If this mesh is configured to use\r
- * fixed point an IllegalArgumentException will be thrown.\r
+ * Sets the vertices of this Mesh. The attributes are assumed to be given in\r
+ * float format. If this mesh is configured to use fixed point an\r
+ * IllegalArgumentException will be thrown.\r
* \r
- * @param vertices the vertices.\r
+ * @param vertices\r
+ * the vertices.\r
*/\r
- public void setVertices (float[] vertices) { \r
+ public void setVertices(float[] vertices) {\r
this.vertices.setVertices(vertices, 0, vertices.length);\r
}\r
\r
/**\r
- * Sets the vertices of this Mesh. The attributes are assumed to be given in float format. If this mesh is configured to use\r
- * fixed point an IllegalArgumentException will be thrown.\r
+ * Sets the vertices of this Mesh. The attributes are assumed to be given in\r
+ * float format. If this mesh is configured to use fixed point an\r
+ * IllegalArgumentException will be thrown.\r
* \r
- * @param vertices the vertices.\r
- * @param offset the offset into the vertices array\r
- * @param count the number of floats to use\r
+ * @param vertices\r
+ * the vertices.\r
+ * @param offset\r
+ * the offset into the vertices array\r
+ * @param count\r
+ * the number of floats to use\r
*/\r
- public void setVertices (float[] vertices, int offset, int count) {\r
+ public void setVertices(float[] vertices, int offset, int count) {\r
this.vertices.setVertices(vertices, offset, count);\r
}\r
\r
/**\r
* Sets the indices of this Mesh\r
* \r
- * @param indices the indices\r
+ * @param indices\r
+ * the indices\r
*/\r
- public void setIndices (short[] indices) {\r
+ public void setIndices(short[] indices) {\r
this.indices.setIndices(indices, 0, indices.length);\r
}\r
- \r
+\r
/**\r
* Sets the indices of this Mesh.\r
* \r
- * @param indices the indices\r
- * @param offset the offset into the indices array\r
- * @param count the number of indices to copy\r
+ * @param indices\r
+ * the indices\r
+ * @param offset\r
+ * the offset into the indices array\r
+ * @param count\r
+ * the number of indices to copy\r
*/\r
- public void setIndices (short[] indices, int offset, int count) {\r
+ public void setIndices(short[] indices, int offset, int count) {\r
this.indices.setIndices(indices, offset, count);\r
}\r
\r
/**\r
* @return the number of defined indices\r
*/\r
- public int getNumIndices () {\r
+ public int getNumIndices() {\r
return indices.getNumIndices();\r
}\r
\r
/**\r
* @return the number of defined vertices\r
*/\r
- public int getNumVertices () {\r
+ public int getNumVertices() {\r
return vertices.getNumVertices();\r
}\r
- \r
+\r
/**\r
* @return the maximum number of vertices this mesh can hold\r
*/\r
- public int getMaxVertices () {\r
+ public int getMaxVertices() {\r
return vertices.getNumMaxVertices();\r
}\r
\r
/**\r
* @return the maximum number of indices this mesh can hold\r
*/\r
- public int getMaxIndices () {\r
+ public int getMaxIndices() {\r
return indices.getNumMaxIndices();\r
}\r
\r
/**\r
* @return the size of a single vertex in bytes\r
*/\r
- public int getVertexSize () {\r
+ public int getVertexSize() {\r
return vertices.getAttributes().vertexSize;\r
}\r
\r
-// /**\r
-// * Sets whether to bind the underlying {@link VertexArray} or\r
-// * {@link VertexBufferObject} automatically on a call to one of the {@link #render(int)}\r
-// * methods or not.\r
-// * @param autoBind\r
-// */\r
-// public void setAutoBind( boolean autoBind ) {\r
-// this.autoBind = autoBind;\r
-// }\r
- \r
- \r
+ // /**\r
+ // * Sets whether to bind the underlying {@link VertexArray} or\r
+ // * {@link VertexBufferObject} automatically on a call to one of the {@link\r
+ // #render(int)}\r
+ // * methods or not.\r
+ // * @param autoBind\r
+ // */\r
+ // public void setAutoBind( boolean autoBind ) {\r
+ // this.autoBind = autoBind;\r
+ // }\r
+\r
/**\r
* Binds the underlying {@link VertexArray}/{@link VertexBufferObject} and\r
- * {@link IndexBufferObject} if indices were given. Use this with OpenGL ES 1.x\r
- * and when auto-bind is disabled.\r
+ * {@link IndexBufferObject} if indices were given. Use this with OpenGL ES\r
+ * 1.x and when auto-bind is disabled.\r
*/\r
- public void bind () {\r
- if (Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 2.0");\r
+ public void bind() {\r
+ if (Gdx.graphics.isGL20Available())\r
+ throw new IllegalStateException(\r
+ "can't use this render method with OpenGL ES 2.0");\r
vertices.bind();\r
- if( !isVertexArray && indices.getNumIndices() > 0 )\r
- indices.bind(); \r
+ if (!isVertexArray && indices.getNumIndices() > 0)\r
+ indices.bind();\r
}\r
\r
/**\r
* Unbinds the underlying {@link VertexArray}/{@link VertexBufferObject} and\r
- * {@link IndexBufferObject} is indices were given. Use this with OpenGL ES 1.x\r
- * and when auto-bind is disabled.\r
+ * {@link IndexBufferObject} is indices were given. Use this with OpenGL ES\r
+ * 1.x and when auto-bind is disabled.\r
*/\r
- public void unbind () {\r
- if (Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 2.0");\r
+ public void unbind() {\r
+ if (Gdx.graphics.isGL20Available())\r
+ throw new IllegalStateException(\r
+ "can't use this render method with OpenGL ES 2.0");\r
vertices.unbind();\r
- if( !isVertexArray && indices.getNumIndices() > 0 )\r
+ if (!isVertexArray && indices.getNumIndices() > 0)\r
indices.unbind();\r
}\r
- \r
+\r
/**\r
- * Binds the underlying {@link VertexBufferObject} and {@link IndexBufferObject} if\r
- * indices where given. Use this with OpenGL ES 2.0 and when auto-bind is disabled.\r
- * @param shader the shader (does not bind the shader)\r
+ * Binds the underlying {@link VertexBufferObject} and\r
+ * {@link IndexBufferObject} if indices where given. Use this with OpenGL ES\r
+ * 2.0 and when auto-bind is disabled.\r
+ * \r
+ * @param shader\r
+ * the shader (does not bind the shader)\r
*/\r
public void bind(ShaderProgram shader) {\r
- if (!Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 1.x");\r
+ if (!Gdx.graphics.isGL20Available())\r
+ throw new IllegalStateException(\r
+ "can't use this render method with OpenGL ES 1.x");\r
\r
- ((VertexBufferObject)vertices).bind(shader);\r
- if( indices.getNumIndices() > 0 )\r
+ ((VertexBufferObject) vertices).bind(shader);\r
+ if (indices.getNumIndices() > 0)\r
indices.bind();\r
}\r
- \r
+\r
/**\r
* Unbinds the underlying {@link VertexBufferObject} and\r
- * {@link IndexBufferObject} is indices were given. Use this with OpenGL ES 1.x\r
- * and when auto-bind is disabled.\r
- * @param shader the shader (does not unbind the shader)\r
+ * {@link IndexBufferObject} is indices were given. Use this with OpenGL ES\r
+ * 1.x and when auto-bind is disabled.\r
+ * \r
+ * @param shader\r
+ * the shader (does not unbind the shader)\r
*/\r
- public void unbind (ShaderProgram shader) {\r
- if (!Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 1.x");\r
+ public void unbind(ShaderProgram shader) {\r
+ if (!Gdx.graphics.isGL20Available())\r
+ throw new IllegalStateException(\r
+ "can't use this render method with OpenGL ES 1.x");\r
\r
- ((VertexBufferObject)vertices).unbind(shader);\r
- if( indices.getNumIndices() > 0 )\r
+ ((VertexBufferObject) vertices).unbind(shader);\r
+ if (indices.getNumIndices() > 0)\r
indices.unbind();\r
}\r
- \r
+\r
/**\r
* <p>\r
- * Renders the mesh using the given primitive type. If indices are set for this mesh then getNumIndices() / #vertices per\r
- * primitive primitives are rendered. If no indices are set then getNumVertices() / #vertices per primitive are rendered.\r
+ * Renders the mesh using the given primitive type. If indices are set for\r
+ * this mesh then getNumIndices() / #vertices per primitive primitives are\r
+ * rendered. If no indices are set then getNumVertices() / #vertices per\r
+ * primitive are rendered.\r
* </p>\r
* \r
* <p>\r
- * This method is intended for use with OpenGL ES 1.x and will throw an IllegalStateException when OpenGL ES 2.0 is used.\r
+ * This method is intended for use with OpenGL ES 1.x and will throw an\r
+ * IllegalStateException when OpenGL ES 2.0 is used.\r
* </p>\r
* \r
- * @param primitiveType the primitive type\r
+ * @param primitiveType\r
+ * the primitive type\r
*/\r
- public void render (int primitiveType) {\r
- render(primitiveType, 0, indices.getNumMaxIndices() > 0 ? getNumIndices() : getNumVertices());\r
+ public void render(int primitiveType) {\r
+ render(primitiveType, 0,\r
+ indices.getNumMaxIndices() > 0 ? getNumIndices()\r
+ : getNumVertices());\r
}\r
\r
/**\r
* <p>\r
- * Renders the mesh using the given primitive type. offset specifies the offset into vertex buffer and is ignored for the index\r
- * buffer. Count specifies the number of vertices or indices to use thus count /\r
- * #vertices per primitive primitives are rendered.\r
+ * Renders the mesh using the given primitive type. offset specifies the\r
+ * offset into vertex buffer and is ignored for the index buffer. Count\r
+ * specifies the number of vertices or indices to use thus count / #vertices\r
+ * per primitive primitives are rendered.\r
* </p>\r
* \r
* <p>\r
- * This method is intended for use with OpenGL ES 1.x and will throw an IllegalStateException when OpenGL ES 2.0 is used.\r
+ * This method is intended for use with OpenGL ES 1.x and will throw an\r
+ * IllegalStateException when OpenGL ES 2.0 is used.\r
* </p>\r
* \r
- * @param primitiveType the primitive type\r
- * @param offset the offset into the vertex buffer, ignored for indexed rendering\r
- * @param count number of vertices or indices to use\r
+ * @param primitiveType\r
+ * the primitive type\r
+ * @param offset\r
+ * the offset into the vertex buffer, ignored for indexed\r
+ * rendering\r
+ * @param count\r
+ * number of vertices or indices to use\r
*/\r
- public void render (int primitiveType, int offset, int count) {\r
- if (Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 2.0");\r
- \r
- if( autoBind )\r
+ public void render(int primitiveType, int offset, int count) {\r
+ if (Gdx.graphics.isGL20Available())\r
+ throw new IllegalStateException(\r
+ "can't use this render method with OpenGL ES 2.0");\r
+\r
+ if (autoBind)\r
bind();\r
- \r
- if( isVertexArray ) {\r
- if( indices.getNumIndices() > 0 ) {\r
+\r
+ if (isVertexArray) {\r
+ if (indices.getNumIndices() > 0) {\r
int oldPosition = indices.getBuffer().position();\r
indices.getBuffer().position(offset);\r
- Gdx.gl10.glDrawElements(primitiveType, count, GL10.GL_UNSIGNED_SHORT, indices.getBuffer());\r
+ Gdx.gl10.glDrawElements(primitiveType, count,\r
+ GL10.GL_UNSIGNED_SHORT, indices.getBuffer());\r
indices.getBuffer().position(oldPosition);\r
- }\r
- else\r
- Gdx.gl10.glDrawArrays( primitiveType, offset, count); \r
- } \r
- else {\r
- if( indices.getNumIndices() > 0 ) \r
- Gdx.gl11.glDrawElements(primitiveType, count, GL10.GL_UNSIGNED_SHORT, offset); \r
+ } else\r
+ Gdx.gl10.glDrawArrays(primitiveType, offset, count);\r
+ } else {\r
+ if (indices.getNumIndices() > 0)\r
+ Gdx.gl11.glDrawElements(primitiveType, count,\r
+ GL10.GL_UNSIGNED_SHORT, offset);\r
else\r
Gdx.gl11.glDrawArrays(primitiveType, offset, count);\r
}\r
- \r
- if( autoBind )\r
+\r
+ if (autoBind)\r
unbind();\r
}\r
\r
/**\r
* <p>\r
- * Renders the mesh using the given primitive type. If indices are set for this mesh then getNumIndices() / #vertices per\r
- * primitive primitives are rendered. If no indices are set then getNumVertices() / #vertices per primitive are rendered.\r
+ * Renders the mesh using the given primitive type. If indices are set for\r
+ * this mesh then getNumIndices() / #vertices per primitive primitives are\r
+ * rendered. If no indices are set then getNumVertices() / #vertices per\r
+ * primitive are rendered.\r
* </p>\r
* \r
* <p>\r
- * This method will automatically bind each vertex attribute as specified at construction time via {@link VertexAttributes} to\r
- * the respective shader attributes. The binding is based on the alias defined for each VertexAttribute.\r
+ * This method will automatically bind each vertex attribute as specified at\r
+ * construction time via {@link VertexAttributes} to the respective shader\r
+ * attributes. The binding is based on the alias defined for each\r
+ * VertexAttribute.\r
* </p>\r
* \r
* <p>\r
- * This method must only be called after the {@link ShaderProgram#begin()} method has been called!\r
+ * This method must only be called after the {@link ShaderProgram#begin()}\r
+ * method has been called!\r
* </p>\r
* \r
* <p>\r
- * This method is intended for use with OpenGL ES 2.0 and will throw an IllegalStateException when OpenGL ES 1.x is used.\r
+ * This method is intended for use with OpenGL ES 2.0 and will throw an\r
+ * IllegalStateException when OpenGL ES 1.x is used.\r
* </p>\r
* \r
- * @param primitiveType the primitive type\r
+ * @param primitiveType\r
+ * the primitive type\r
*/\r
- public void render (ShaderProgram shader, int primitiveType) {\r
- render(shader, primitiveType, 0, indices.getNumMaxIndices() > 0 ? getNumIndices() : getNumVertices());\r
+ public void render(ShaderProgram shader, int primitiveType) {\r
+ render(shader, primitiveType, 0,\r
+ indices.getNumMaxIndices() > 0 ? getNumIndices()\r
+ : getNumVertices());\r
}\r
\r
/**\r
* <p>\r
- * Renders the mesh using the given primitive type. offset specifies the offset into either the vertex buffer or the index\r
- * buffer depending on whether indices are defined. count specifies the number of vertices or indices to use thus count /\r
- * #vertices per primitive primitives are rendered.\r
+ * Renders the mesh using the given primitive type. offset specifies the\r
+ * offset into either the vertex buffer or the index buffer depending on\r
+ * whether indices are defined. count specifies the number of vertices or\r
+ * indices to use thus count / #vertices per primitive primitives are\r
+ * rendered.\r
* </p>\r
* \r
* <p>\r
- * This method will automatically bind each vertex attribute as specified at construction time via {@link VertexAttributes} to\r
- * the respective shader attributes. The binding is based on the alias defined for each VertexAttribute.\r
+ * This method will automatically bind each vertex attribute as specified at\r
+ * construction time via {@link VertexAttributes} to the respective shader\r
+ * attributes. The binding is based on the alias defined for each\r
+ * VertexAttribute.\r
* </p>\r
* \r
* <p>\r
- * This method must only be called after the {@link ShaderProgram#begin()} method has been called!\r
+ * This method must only be called after the {@link ShaderProgram#begin()}\r
+ * method has been called!\r
* </p>\r
* \r
* <p>\r
- * This method is intended for use with OpenGL ES 2.0 and will throw an IllegalStateException when OpenGL ES 1.x is used.\r
+ * This method is intended for use with OpenGL ES 2.0 and will throw an\r
+ * IllegalStateException when OpenGL ES 1.x is used.\r
* </p>\r
* \r
- * @param shader the shader to be used\r
- * @param primitiveType the primitive type\r
- * @param offset the offset into the vertex or index buffer\r
- * @param count number of vertices or indices to use\r
+ * @param shader\r
+ * the shader to be used\r
+ * @param primitiveType\r
+ * the primitive type\r
+ * @param offset\r
+ * the offset into the vertex or index buffer\r
+ * @param count\r
+ * number of vertices or indices to use\r
*/\r
- public void render (ShaderProgram shader, int primitiveType, int offset, int count) {\r
- if (!Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 1.x");\r
+ public void render(ShaderProgram shader, int primitiveType, int offset,\r
+ int count) {\r
+ if (!Gdx.graphics.isGL20Available())\r
+ throw new IllegalStateException(\r
+ "can't use this render method with OpenGL ES 1.x");\r
\r
- if( autoBind )\r
+ if (autoBind)\r
bind(shader);\r
- \r
- if( indices.getNumIndices() > 0 ) \r
- Gdx.gl20.glDrawElements(primitiveType, count, GL10.GL_UNSIGNED_SHORT, offset); \r
+\r
+ if (indices.getNumIndices() > 0)\r
+ Gdx.gl20.glDrawElements(primitiveType, count,\r
+ GL10.GL_UNSIGNED_SHORT, offset);\r
else\r
- Gdx.gl20.glDrawArrays(primitiveType, offset, count); \r
- \r
- if( autoBind )\r
+ Gdx.gl20.glDrawArrays(primitiveType, offset, count);\r
+\r
+ if (autoBind)\r
unbind(shader);\r
}\r
\r
/**\r
* Frees all resources associated with this Mesh\r
*/\r
- public void dispose () {\r
- meshes.remove(this); \r
+ public void dispose() {\r
+ meshes.remove(this);\r
vertices.dispose();\r
indices.dispose();\r
}\r
- \r
\r
/**\r
* Returns the first {@link VertexAttribute} having the given {@link Usage}.\r
* \r
- * @param usage the Usage.\r
- * @return the VertexAttribute or null if no attribute with that usage was found.\r
+ * @param usage\r
+ * the Usage.\r
+ * @return the VertexAttribute or null if no attribute with that usage was\r
+ * found.\r
*/\r
- public VertexAttribute getVertexAttribute (int usage) {\r
+ public VertexAttribute getVertexAttribute(int usage) {\r
VertexAttributes attributes = vertices.getAttributes();\r
int len = attributes.size();\r
for (int i = 0; i < len; i++)\r
- if (attributes.get(i).usage == usage) return attributes.get(i);\r
+ if (attributes.get(i).usage == usage)\r
+ return attributes.get(i);\r
\r
return null;\r
}\r
/**\r
* @return the vertex attributes of this Mesh\r
*/\r
- public VertexAttributes getVertexAttributes () {\r
+ public VertexAttributes getVertexAttributes() {\r
return vertices.getAttributes();\r
}\r
\r
/**\r
- * @return the backing FloatBuffer holding the vertices. Does not have to be a\r
- * direct buffer on Android!\r
+ * @return the backing FloatBuffer holding the vertices. Does not have to be\r
+ * a direct buffer on Android!\r
*/\r
- public FloatBuffer getVerticesBuffer () {\r
+ public FloatBuffer getVerticesBuffer() {\r
return vertices.getBuffer();\r
}\r
\r
/**\r
- * @return the backing shortbuffer holding the indices. Does not have to be a direct buffer on Android!\r
+ * @return the backing shortbuffer holding the indices. Does not have to be\r
+ * a direct buffer on Android!\r
*/\r
- public ShortBuffer getIndicesBuffer () {\r
+ public ShortBuffer getIndicesBuffer() {\r
return indices.getBuffer();\r
}\r
\r
/**\r
- * Invalidates all meshes so the next time they are rendered new VBO handles are generated.\r
+ * Invalidates all meshes so the next time they are rendered new VBO handles\r
+ * are generated.\r
*/\r
- public static void invalidateAllMeshes () {\r
+ public static void invalidateAllMeshes() {\r
\r
for (int i = 0; i < meshes.size(); i++) {\r
- if( meshes.get(i).vertices instanceof VertexBufferObject ) { \r
- ((VertexBufferObject)meshes.get(i).vertices).invalidate();\r
+ if (meshes.get(i).vertices instanceof VertexBufferObject) {\r
+ ((VertexBufferObject) meshes.get(i).vertices).invalidate();\r
meshes.get(i).indices.invalidate();\r
}\r
}\r
/**\r
* Will clear the managed mesh cache. I wouldn't use this if i was you :)\r
*/\r
- public static void clearAllMeshes () {\r
+ public static void clearAllMeshes() {\r
meshes.clear();\r
}\r
}\r
import com.badlogic.gdx.math.Vector3;\r
\r
/**\r
- * A class for loading various model formats such as Wavefront OBJ or the Quake II MD2 format. Ties in all the loaders from the\r
- * loaders package.\r
+ * A class for loading various model formats such as Wavefront OBJ. Ties in all\r
+ * the loaders from the loaders package.\r
* \r
* @author mzechner\r
* \r
*/\r
public class ModelLoader {\r
/**\r
- * Loads a Wavefront OBJ file from the given InputStream. The OBJ file must only contain triangulated meshes. Materials are\r
- * ignored.\r
+ * Loads a Wavefront OBJ file from the given InputStream. The OBJ file must\r
+ * only contain triangulated meshes. Materials are ignored.\r
* \r
- * @param in the InputStream \r
+ * @param in\r
+ * the InputStream\r
* @return a Mesh holding the OBJ data or null in case something went wrong.\r
*/\r
- public static Mesh loadObj (InputStream in) {\r
+ public static Mesh loadObj(InputStream in) {\r
return ObjLoader.loadObj(in);\r
}\r
-\r
- /**\r
- * Loads an OCT file as can be found in many of Paul Nettle's demo programs. See the source at\r
- * http://www.paulnettle.com/pub/FluidStudios/CollisionDetection/Fluid_Studios_Collision_Detection_Demo_and_Source.zip for more\r
- * information.\r
- * \r
- * @param in the InputStream\r
- * @param start the start position as defined in the map\r
- * @return a Mesh holding the OCT data or null in case something went wrong.\r
- */\r
- public static Mesh loadOct (InputStream in, Vector3 start) {\r
- return OctLoader.loadOct(in, start);\r
- }\r
-\r
- /**\r
- * Loads a GDX3D file previously written with {@link ModelWriter.writeGdx3D}.\r
- * \r
- * @param in the InputStream\r
- * @return a Mesh holding the Gdx3D data or null in case something went wrong.\r
- */\r
- public static Mesh loadGdx3D (InputStream in) {\r
- try {\r
- DataInputStream din = new DataInputStream(new BufferedInputStream(in));\r
- int numAttributes = din.readInt();\r
- ArrayList<VertexAttribute> attributes = new ArrayList<VertexAttribute>();\r
- for (int i = 0; i < numAttributes; i++) {\r
- int usage = din.readInt();\r
- int numComponents = din.readInt();\r
- int strlen = din.readInt();\r
- byte[] bytes = new byte[strlen];\r
- din.readFully(bytes);\r
- String alias = new String(bytes, "UTF8");\r
-\r
- VertexAttribute attribute = new VertexAttribute(usage, numComponents, alias);\r
- attributes.add(attribute);\r
- }\r
- \r
- int numVertices = din.readInt();\r
- int numElements = din.readInt();\r
- int numIndices = din.readInt();\r
-\r
- Mesh mesh = new Mesh(true, numVertices, numIndices, attributes.toArray(new VertexAttribute[0]));\r
- \r
- float[] vertices = new float[numElements];\r
- for (int i = 0; i < numElements; i++)\r
- vertices[i] = din.readFloat();\r
- mesh.setVertices(vertices); \r
-\r
- if (numIndices > 0) {\r
- short[] indices = new short[numIndices];\r
- for (int i = 0; i < numIndices; i++)\r
- indices[i] = din.readShort();\r
- mesh.setIndices(indices);\r
- }\r
-\r
- return mesh;\r
- } catch (IOException ex) {\r
- ex.printStackTrace();\r
- return null;\r
- }\r
- }\r
}\r
import com.badlogic.gdx.math.collision.Ray;\r
\r
/**\r
- * An orthographic camera having a position and a scale value for zooming. Looks at one of the sides given in the {@link Side}\r
- * enums, default is front, looking along the z-Axis. Generally you will want to alter the camera's scale and position and then\r
- * set its matrices via a call to {@link OrthographicCamera.setMatrices()} which takes a {@link Graphics} instance from which it\r
- * retrieves an GL10 instance to set the matrices. You can get a picking ray via a call to {@link OrthographicCamera.getPickRay()}\r
- * . For OpenGL ES 2.0 you can get the matrices via {@link OrthographicCamera.getCombinedMatrix()} to set them as a uniform. For\r
- * this you have to call {@link OrthographicCamera.update()} before you retrieve the matrices.\r
+ * An orthographic camera having a position and a scale value for zooming. Looks\r
+ * at one of the sides given in the {@link Side} enums, default is front,\r
+ * looking along the z-Axis. Generally you will want to alter the camera's scale\r
+ * and position and then set its matrices via a call to\r
+ * {@link OrthographicCamera#setMatrices()} to set the OpenGL perspective and\r
+ * modelview matrices. You can get a picking ray via a call to {@link\r
+ * OrthographicCamera#getPickRay(int, int)} . For OpenGL ES 2.0 you can get the matrices\r
+ * via {@link OrthographicCamera#getCombinedMatrix()} to set them as a uniform.\r
+ * For this you have to call {@link OrthographicCamera#update()} before you\r
+ * retrieve the matrices.\r
* \r
* @author badlogicgames@gmail.com\r
* \r
private final Matrix4 rotationMatrix = new Matrix4();\r
\r
/**\r
- * Constructor, sets side to {@link Side.FRONT}\r
+ * Constructor, sets side to {@link Side#FRONT}\r
*/\r
- public OrthographicCamera () {\r
+ public OrthographicCamera() {\r
setSide(Side.FRONT);\r
}\r
\r
/**\r
* @return Which side the camera looks at\r
*/\r
- public Side getSide () {\r
+ public Side getSide() {\r
return side;\r
}\r
\r
/**\r
* Sets the side the camera looks at.\r
- * @param side The side.\r
+ * \r
+ * @param side\r
+ * The side.\r
*/\r
- public void setSide (Side side) {\r
+ public void setSide(Side side) {\r
this.side = side;\r
calculateRotationMatrix();\r
}\r
/**\r
* @return The near plane.\r
*/\r
- public float getNear () {\r
+ public float getNear() {\r
return near;\r
}\r
\r
/**\r
* Sets the near plane.\r
* \r
- * @param near The near plane\r
+ * @param near\r
+ * The near plane\r
*/\r
- public void setNear (float near) {\r
+ public void setNear(float near) {\r
this.near = near;\r
}\r
\r
/**\r
* @return The far plane.\r
*/\r
- public float getFar () {\r
+ public float getFar() {\r
return far;\r
}\r
\r
/**\r
* Sets the far plane\r
- * @param far the far plane\r
+ * \r
+ * @param far\r
+ * the far plane\r
*/\r
- public void setFar (float far) {\r
+ public void setFar(float far) {\r
this.far = far;\r
}\r
\r
/**\r
* @return The scale\r
*/\r
- public float getScale () {\r
+ public float getScale() {\r
return scale;\r
}\r
\r
/**\r
- * @param scale Sets the scale\r
+ * @param scale\r
+ * Sets the scale\r
*/\r
- public void setScale (float scale) {\r
+ public void setScale(float scale) {\r
this.scale = scale;\r
}\r
\r
/**\r
* @return The position\r
*/\r
- public Vector3 getPosition () {\r
+ public Vector3 getPosition() {\r
return position;\r
}\r
\r
/**\r
* Sets the viewport\r
* \r
- * @param width The viewport width in pixels\r
- * @param height The viewport height in pixels\r
+ * @param width\r
+ * The viewport width in pixels\r
+ * @param height\r
+ * The viewport height in pixels\r
*/\r
- public void setViewport (float width, float height) {\r
+ public void setViewport(float width, float height) {\r
this.viewportWidth = width;\r
this.viewportHeight = height;\r
}\r
Vector3 tmp = new Vector3();\r
\r
/**\r
- * Updates the frustum as well as the matrices of the camera based on the near and far plane, the position, the side and the\r
- * scale.\r
+ * Updates the frustum as well as the matrices of the camera based on the\r
+ * near and far plane, the position, the side and the scale.\r
*/\r
- public void update () {\r
- proj.setToOrtho2D(0, 0, (viewportWidth * scale), (viewportHeight * scale), near, far);\r
- model.setToTranslation(tmp.set((-position.x + (viewportWidth / 2) * scale), (-position.y + (viewportHeight / 2) * scale),\r
- (-position.z)));\r
+ public void update() {\r
+ proj.setToOrtho2D(0, 0, (viewportWidth * scale),\r
+ (viewportHeight * scale), near, far);\r
+ model.setToTranslation(tmp.set((-position.x + (viewportWidth / 2)\r
+ * scale), (-position.y + (viewportHeight / 2) * scale),\r
+ (-position.z)));\r
combined.set(proj);\r
combined.mul(model);\r
combined.mul(rotationMatrix);\r
}\r
\r
/**\r
- * Sets the projection matrix that also incorporates the camera's scale and position and loads an identity to the model view\r
- * matrix of OpenGL ES 1.x. The current matrices get overwritten. The matrix mode will be left in the model view state after a\r
- * call to this.\r
+ * Sets the projection matrix that also incorporates the camera's scale and\r
+ * position and loads an identity to the model view matrix of OpenGL ES 1.x.\r
+ * The current matrices get overwritten. The matrix mode will be left in the\r
+ * model view state after a call to this.\r
*/\r
- public void setMatrices () {\r
+ public void setMatrices() {\r
update();\r
GL10 gl = Gdx.gl10;\r
gl.glMatrixMode(GL10.GL_PROJECTION);\r
gl.glLoadIdentity();\r
}\r
\r
- private Matrix4 calculateRotationMatrix () {\r
+ private Matrix4 calculateRotationMatrix() {\r
float rotation = 0;\r
if (side == Side.FRONT) {\r
direction.set(0, 0, -1);\r
}\r
\r
/**\r
- * Calculates the world coordinates of the given screen coordinates and stores the result in world\r
- * @param screenX the x-coordinate of the screen position\r
- * @param screenY the y-coordinate of the screen position\r
- * @param world the vector to store the result in\r
+ * Calculates the world coordinates of the given screen coordinates and\r
+ * stores the result in world\r
+ * \r
+ * @param screenX\r
+ * the x-coordinate of the screen position\r
+ * @param screenY\r
+ * the y-coordinate of the screen position\r
+ * @param world\r
+ * the vector to store the result in\r
*/\r
- public void getScreenToWorld (float screenX, float screenY, Vector2 world) {\r
+ public void getScreenToWorld(float screenX, float screenY, Vector2 world) {\r
screenX = screenX / Gdx.graphics.getWidth() * viewportWidth;\r
screenY = screenY / Gdx.graphics.getHeight() * viewportHeight;\r
\r
- world.set((screenX * scale) - (viewportWidth * scale) / 2 + position.x, ((viewportHeight - screenY) * scale)\r
- - (viewportHeight * scale) / 2 + position.y);\r
+ world.set((screenX * scale) - (viewportWidth * scale) / 2 + position.x,\r
+ ((viewportHeight - screenY) * scale) - (viewportHeight * scale)\r
+ / 2 + position.y);\r
}\r
\r
/**\r
* Calculates the screen coordinates of the given world coordinates\r
* \r
- * @param worldX world x-coordinate\r
- * @param worldY world y-coordinate\r
- * @param screen the screen coordinates get stored here\r
+ * @param worldX\r
+ * world x-coordinate\r
+ * @param worldY\r
+ * world y-coordinate\r
+ * @param screen\r
+ * the screen coordinates get stored here\r
*/\r
- public void getWorldToScreen (float worldX, float worldY, Vector2 screen) {\r
- screen.x = (int)((worldX + (viewportWidth * scale) / 2 - position.x) / scale);\r
- screen.y = (int)(-(-worldY + (viewportHeight * scale) / 2 + position.y - viewportHeight * scale) / scale);\r
+ public void getWorldToScreen(float worldX, float worldY, Vector2 screen) {\r
+ screen.x = (int) ((worldX + (viewportWidth * scale) / 2 - position.x) / scale);\r
+ screen.y = (int) (-(-worldY + (viewportHeight * scale) / 2 + position.y - viewportHeight\r
+ * scale) / scale);\r
}\r
\r
/**\r
* Returns the given screen x-coordinates as a world x-coordinate\r
- * @param screenX The screen x-coordinate\r
+ * \r
+ * @param screenX\r
+ * The screen x-coordinate\r
* @return The world x-coordinate\r
*/\r
- public float getScreenToWorldX (float screenX) {\r
+ public float getScreenToWorldX(float screenX) {\r
return (screenX * scale) - (viewportWidth * scale) / 2 + position.x;\r
}\r
\r
/**\r
* Returns the given world x-coordinate as a screen x-coordinate\r
- * @param worldX The world x-coordinate\r
+ * \r
+ * @param worldX\r
+ * The world x-coordinate\r
* @return The screen x-coordinate\r
*/\r
- public int getWorldToScreenX (float worldX) {\r
- return (int)((worldX + (viewportWidth * scale) / 2 - position.x) / scale);\r
+ public int getWorldToScreenX(float worldX) {\r
+ return (int) ((worldX + (viewportWidth * scale) / 2 - position.x) / scale);\r
}\r
\r
/**\r
* Returns the given screen y-coordinates as a world y-coordinate\r
- * @param screenY The screen y-coordinate\r
+ * \r
+ * @param screenY\r
+ * The screen y-coordinate\r
* @return The world y-coordinate\r
*/\r
- public float getScreenToWorldY (float screenY) {\r
- return ((viewportHeight - screenY - 1) * scale) - (viewportHeight * scale) / 2 + position.y;\r
+ public float getScreenToWorldY(float screenY) {\r
+ return ((viewportHeight - screenY - 1) * scale)\r
+ - (viewportHeight * scale) / 2 + position.y;\r
}\r
\r
/**\r
* Returns the given world y-coordinate as a screen x-coordinate\r
- * @param worldY The world y-coordinate\r
+ * \r
+ * @param worldY\r
+ * The world y-coordinate\r
* @return The screen y-coordinate\r
*/\r
- public int getWorldToScreenY (float worldY) {\r
- return (int)(-(-worldY + (viewportHeight * scale) / 2 + position.y - viewportHeight * scale) / scale);\r
+ public int getWorldToScreenY(float worldY) {\r
+ return (int) (-(-worldY + (viewportHeight * scale) / 2 + position.y - viewportHeight\r
+ * scale) / scale);\r
}\r
\r
Ray ray = new Ray(new Vector3(), new Vector3());\r
Vector3 tmp2 = new Vector3();\r
\r
/**\r
- * Returns a ray in world space form the given screen coordinates. This can be used for picking. The returned Ray is an\r
- * internal member of this class to reduce memory allocations. Do not reuse it outside of this class.\r
+ * Returns a ray in world space form the given screen coordinates. This can\r
+ * be used for picking. The returned Ray is an internal member of this class\r
+ * to reduce memory allocations. Do not reuse it outside of this class.\r
* \r
- * @param screenX The screen x-coordinate\r
- * @param screenY The screen y-coordinate\r
+ * @param screenX\r
+ * The screen x-coordinate\r
+ * @param screenY\r
+ * The screen y-coordinate\r
* @return The picking ray.\r
*/\r
- public Ray getPickRay (int screenX, int screenY) {\r
+ public Ray getPickRay(int screenX, int screenY) {\r
float x = getScreenToWorldX(screenX);\r
float y = getScreenToWorldY(screenY);\r
\r
} else if (side == Side.BOTTOM) {\r
return ray.set(x, 1000 / 2, y, 0, 1, 0);\r
} else\r
- return ray.set(tmp2.set(x, y, 10000 / 2).mul(rotationMatrix), tmp.set(0, 0, -1).mul(rotationMatrix));\r
+ return ray.set(tmp2.set(x, y, 10000 / 2).mul(rotationMatrix), tmp\r
+ .set(0, 0, -1).mul(rotationMatrix));\r
}\r
\r
/**\r
* @return The combined matrix.\r
*/\r
- public Matrix4 getCombinedMatrix () {\r
+ public Matrix4 getCombinedMatrix() {\r
return combined;\r
}\r
}\r
import com.badlogic.gdx.math.collision.Ray;\r
\r
/**\r
- * A perspective camera, having a position, a direction an up vector, a near plane, a far plane and a field of view. Use the\r
- * {@link PerspectiveCamera.setViewport()} method to set the viewport from which the aspect ratio is derrived from, then call\r
- * {@link PerspectiveCamera.update()} to update all the camera matrices as well as the {@link Frustum}. The combined matrix\r
- * (projection, modelview) can be retrieved via a call to {@link PerspectiveCamera.getCombinedMatrix()} and directly passed to\r
- * OpenGL. A convenience method called {@link PerspectiveCamera.setMatrices()} exists for OpenGL ES 1.x that will update the\r
- * matrices and set them via a {@link Graphics} instance to OpenGL. You can also get a picking ray via {@link\r
- * PerspectiveCamera.getPickRay()}.\r
+ * A perspective camera, having a position, a direction an up vector, a near\r
+ * plane, a far plane and a field of view. Use the {@link\r
+ * PerspectiveCamera#setViewport(float, float)} method to set the viewport from which the\r
+ * aspect ratio is derrived from, then call {@link PerspectiveCamera#update()}\r
+ * to update all the camera matrices as well as the {@link Frustum}. The\r
+ * combined matrix (projection, modelview) can be retrieved via a call to\r
+ * {@link PerspectiveCamera#getCombinedMatrix()} and directly passed to OpenGL.\r
+ * A convenience method called {@link PerspectiveCamera#setMatrices()} exists\r
+ * for OpenGL ES 1.x that will update the OpenGL perspective and modelview. You can also get a picking ray via\r
+ * {@link PerspectiveCamera#getPickRay(int, int)}.\r
* \r
* @author badlogicgames@gmail.com\r
* \r
/**\r
* @return The near plane.\r
*/\r
- public float getNear () {\r
+ public float getNear() {\r
return near;\r
}\r
\r
/**\r
* Sets the near plane.\r
- * @param near The near plane\r
+ * \r
+ * @param near\r
+ * The near plane\r
*/\r
- public void setNear (float near) {\r
+ public void setNear(float near) {\r
this.near = near;\r
}\r
\r
/**\r
* @return The far plane\r
*/\r
- public float getFar () {\r
+ public float getFar() {\r
return far;\r
}\r
\r
/**\r
* Sets the far plane\r
- * @param far The far plane\r
+ * \r
+ * @param far\r
+ * The far plane\r
*/\r
- public void setFar (float far) {\r
+ public void setFar(float far) {\r
this.far = far;\r
}\r
\r
/**\r
* @return The field of view in degrees\r
*/\r
- public float getFov () {\r
+ public float getFov() {\r
return fov;\r
}\r
\r
/**\r
* Sets the field of view in degrees\r
- * @param fov The field of view\r
+ * \r
+ * @param fov\r
+ * The field of view\r
*/\r
- public void setFov (float fov) {\r
+ public void setFov(float fov) {\r
this.fov = fov;\r
}\r
\r
/**\r
* @return The viewport height\r
*/\r
- public float getViewportWidth () {\r
+ public float getViewportWidth() {\r
return viewportWidth;\r
}\r
\r
/**\r
* Sets the viewport dimensions.\r
- * @param viewportWidth The viewport width in pixels.\r
- * @param viewportHeight The viewport height in pixels.\r
+ * \r
+ * @param viewportWidth\r
+ * The viewport width in pixels.\r
+ * @param viewportHeight\r
+ * The viewport height in pixels.\r
*/\r
- public void setViewport (float viewportWidth, float viewportHeight) {\r
+ public void setViewport(float viewportWidth, float viewportHeight) {\r
this.viewportWidth = viewportWidth;\r
this.viewportHeight = viewportHeight;\r
}\r
/**\r
* @return The projection matrix.\r
*/\r
- public Matrix4 getProjectionMatrix () {\r
+ public Matrix4 getProjectionMatrix() {\r
return proj;\r
}\r
\r
/**\r
* @return The modelview matrix.\r
*/\r
- public Matrix4 getModelviewMatrix () {\r
+ public Matrix4 getModelviewMatrix() {\r
return model;\r
}\r
\r
/**\r
* @return The combined matrix, projection * modelview\r
*/\r
- public Matrix4 getCombinedMatrix () {\r
+ public Matrix4 getCombinedMatrix() {\r
return comb;\r
}\r
\r
/**\r
* @return The {@link Frustum}\r
*/\r
- public Frustum getFrustum () {\r
+ public Frustum getFrustum() {\r
return frustum;\r
}\r
\r
Vector3 tmp2 = new Vector3();\r
\r
/**\r
- * Updates all matrices as well as the Frustum based on the last set parameters for position, direction, up vector, field of\r
- * view, near and far plane and viewport.\r
+ * Updates all matrices as well as the Frustum based on the last set\r
+ * parameters for position, direction, up vector, field of view, near and\r
+ * far plane and viewport.\r
*/\r
- public void update () {\r
+ public void update() {\r
float aspect = viewportWidth / viewportHeight;\r
\r
frustum.setCameraParameters(fov, aspect, near, far);\r
\r
proj.setToProjection(near, far, fov, aspect);\r
model.setToLookAt(position, tmp2.set(position).add(direction), up);\r
-// model.mul( tmp.setToTranslation( tmp2.set(position).mul(-1) ) );\r
+ // model.mul( tmp.setToTranslation( tmp2.set(position).mul(-1) ) );\r
comb.set(proj).mul(model);\r
}\r
\r
/**\r
- * Sets the projection and model view matrix of OpenGL ES 1.x to this camera's projection and model view matrix. Any previously\r
- * set matrices are overwritten. Upon returning from this method the matrix mode will be GL10.GL_MODELVIEW.\r
+ * Sets the projection and model view matrix of OpenGL ES 1.x to this\r
+ * camera's projection and model view matrix. Any previously set matrices\r
+ * are overwritten. Upon returning from this method the matrix mode will be\r
+ * GL10.GL_MODELVIEW.\r
* \r
*/\r
- public void setMatrices () {\r
+ public void setMatrices() {\r
setViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
update();\r
GL10 gl = Gdx.gl10;\r
/**\r
* @return The direction vector.\r
*/\r
- public Vector3 getDirection () {\r
+ public Vector3 getDirection() {\r
return direction;\r
}\r
\r
/**\r
* @return The right vector\r
*/\r
- public Vector3 getRight () {\r
+ public Vector3 getRight() {\r
return right;\r
}\r
\r
/**\r
* @return The up vector.\r
*/\r
- public Vector3 getUp () {\r
+ public Vector3 getUp() {\r
return up;\r
}\r
\r
/**\r
* @return The position.\r
*/\r
- public Vector3 getPosition () {\r
+ public Vector3 getPosition() {\r
return position;\r
}\r
\r
/**\r
- * Returns a ray in world space form the given screen coordinates. This can be used for picking. The returned Ray is an\r
- * internal member of this class to reduce memory allocations. Do not reuse it outside of this class.\r
+ * Returns a ray in world space form the given screen coordinates. This can\r
+ * be used for picking. The returned Ray is an internal member of this class\r
+ * to reduce memory allocations. Do not reuse it outside of this class.\r
* \r
- * @param screenX The screen x-coordinate\r
- * @param mouse_y The screen y-coordinate\r
+ * @param screenX\r
+ * The screen x-coordinate\r
+ * @param screenY\r
+ * The screen y-coordinate\r
* @return The picking ray\r
*/\r
- public Ray getPickRay (int screenX, int screenY) {\r
- return frustum.calculatePickRay(viewportWidth, viewportHeight, screenX, viewportHeight - screenY - 1, position, direction,\r
- up);\r
+ public Ray getPickRay(int screenX, int screenY) {\r
+ return frustum.calculatePickRay(viewportWidth, viewportHeight, screenX,\r
+ viewportHeight - screenY - 1, position, direction, up);\r
}\r
\r
/**\r
- * Projects the given vector in world space to screen space, overwritting the x- and y-coordinate of the provided vector.\r
- * @param pos The vector to project\r
+ * Projects the given vector in world space to screen space, overwritting\r
+ * the x- and y-coordinate of the provided vector.\r
+ * \r
+ * @param pos\r
+ * The vector to project\r
*/\r
- public void project (Vector3 pos) {\r
+ public void project(Vector3 pos) {\r
Matrix4 m = getCombinedMatrix();\r
pos.prj(m);\r
pos.x = viewportWidth * (pos.x + 1) / 2;\r
package com.badlogic.gdx.graphics;\r
\r
/**\r
- * A Pixmap represents a plattform specific bitmap. On Android it encapsulates a Bitmap on the desktop it encapsulates a\r
- * BufferedImage. Various methods are available to manipulate the Pixmap. This uses the common bitmap coordinate system with the\r
- * origin being in the top left corner and the y-axis pointing downwards. Bitmaps can be disposed to free all related resources.\r
- * Use after disposing will result in nasty exceptions.\r
+ * A Pixmap represents a platform specific bitmap. On Android it encapsulates a\r
+ * Bitmap on the desktop it encapsulates a BufferedImage. Various methods are\r
+ * available to manipulate the Pixmap. This uses the common bitmap coordinate\r
+ * system with the origin being in the top left corner and the y-axis pointing\r
+ * downwards. Bitmaps can be disposed to free all related resources. Use after\r
+ * disposing will result in nasty exceptions.\r
* \r
* @author badlogicgames@gmail.com\r
* \r
/**\r
* Sets the color for the following drawing operations.\r
* \r
- * @param r The red component.\r
- * @param g The green component.\r
- * @param b The blue component.\r
- * @param a The alpha component.\r
+ * @param r\r
+ * The red component.\r
+ * @param g\r
+ * The green component.\r
+ * @param b\r
+ * The blue component.\r
+ * @param a\r
+ * The alpha component.\r
*/\r
- public void setColor (float r, float g, float b, float a);\r
+ public void setColor(float r, float g, float b, float a);\r
\r
/**\r
* Fills the complete bitmap with the currently set color.\r
*/\r
- public void fill ();\r
+ public void fill();\r
\r
/**\r
* Sets the width in pixels of strokes.\r
* \r
- * @param width The stroke width in pixels.\r
+ * @param width\r
+ * The stroke width in pixels.\r
*/\r
- public void setStrokeWidth (int width);\r
+ public void setStrokeWidth(int width);\r
\r
/**\r
- * Draws a line between the given coordinates using the currently set color and stroke width.\r
- * @param x The x-coodinate of the first point\r
- * @param y The y-coordinate of the first point\r
- * @param x2 The x-coordinate of the first point\r
- * @param y2 The y-coordinate of the first point\r
+ * Draws a line between the given coordinates using the currently set color\r
+ * and stroke width.\r
+ * \r
+ * @param x\r
+ * The x-coodinate of the first point\r
+ * @param y\r
+ * The y-coordinate of the first point\r
+ * @param x2\r
+ * The x-coordinate of the first point\r
+ * @param y2\r
+ * The y-coordinate of the first point\r
*/\r
- public void drawLine (int x, int y, int x2, int y2);\r
+ public void drawLine(int x, int y, int x2, int y2);\r
\r
/**\r
- * Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards)\r
- * using the current color and stroke width.\r
+ * Draws a rectangle outline starting at x, y extending by width to the\r
+ * right and by height downwards (y-axis points downwards) using the current\r
+ * color and stroke width.\r
* \r
- * @param x The x coordinate\r
- * @param y The y coordinate\r
- * @param width The width in pixels\r
- * @param height The height in pixels\r
+ * @param x\r
+ * The x coordinate\r
+ * @param y\r
+ * The y coordinate\r
+ * @param width\r
+ * The width in pixels\r
+ * @param height\r
+ * The height in pixels\r
*/\r
- public void drawRectangle (int x, int y, int width, int height);\r
+ public void drawRectangle(int x, int y, int width, int height);\r
\r
/**\r
* Draws an area form another Pixmap to this Pixmap.\r
* \r
- * @param Pixmap The other Pixmap\r
- * @param x The target x-coordinate\r
- * @param y The target y-coordinate\r
- * @param srcx The source x-coordinate\r
- * @param srcy The source y-coordinate\r
- * @param width The width of the area form the other Pixmap in pixels\r
- * @param height The height of the area form the other Pixmap in pixles\r
- */\r
- public void drawPixmap (Pixmap Pixmap, int x, int y, int srcx, int srcy, int width, int height);\r
-\r
- /**\r
- * Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using\r
- * the current color.\r
- * @param x The x coordinate\r
- * @param y The y coordinate\r
- * @param width The width in pixels\r
- * @param height The height in pixels\r
+ * @param pixmap\r
+ * The other Pixmap\r
+ * @param x\r
+ * The target x-coordinate\r
+ * @param y\r
+ * The target y-coordinate\r
+ * @param srcx\r
+ * The source x-coordinate\r
+ * @param srcy\r
+ * The source y-coordinate\r
+ * @param srcWidth\r
+ * The width of the area form the other Pixmap in pixels\r
+ * @param srcHeight\r
+ * The height of the area form the other Pixmap in pixles\r
+ */\r
+ public void drawPixmap(Pixmap pixmap, int x, int y, int srcx, int srcy,\r
+ int srcWidth, int srcHeight);\r
+\r
+ /**\r
+ * Fills a rectangle starting at x, y extending by width to the right and by\r
+ * height downwards (y-axis points downwards) using the current color.\r
+ * \r
+ * @param x\r
+ * The x coordinate\r
+ * @param y\r
+ * The y coordinate\r
+ * @param width\r
+ * The width in pixels\r
+ * @param height\r
+ * The height in pixels\r
*/\r
- public void fillRectangle (int x, int y, int width, int height);\r
+ public void fillRectangle(int x, int y, int width, int height);\r
\r
/**\r
- * Draws a circle outline with the center at x,y and a radius using the current color and stroke width.\r
+ * Draws a circle outline with the center at x,y and a radius using the\r
+ * current color and stroke width.\r
* \r
- * @param x The x-coordinate of the center\r
- * @param y The y-coordinate of the center\r
- * @param radius The radius in pixels\r
+ * @param x\r
+ * The x-coordinate of the center\r
+ * @param y\r
+ * The y-coordinate of the center\r
+ * @param radius\r
+ * The radius in pixels\r
*/\r
- public void drawCircle (int x, int y, int radius);\r
+ public void drawCircle(int x, int y, int radius);\r
\r
/**\r
- * Fills a circle with the center at x,y and a radius using the current color.\r
+ * Fills a circle with the center at x,y and a radius using the current\r
+ * color.\r
* \r
- * @param x The x-coordinate of the center\r
- * @param y The y-coordinate of the center\r
- * @param radius The radius in pixels\r
+ * @param x\r
+ * The x-coordinate of the center\r
+ * @param y\r
+ * The y-coordinate of the center\r
+ * @param radius\r
+ * The radius in pixels\r
*/\r
- public void fillCircle (int x, int y, int radius);\r
+ public void fillCircle(int x, int y, int radius);\r
\r
/**\r
* Returns the 32-bit argb value of the pixel at x, y\r
- * @param x The x-coordinate\r
- * @param y The y-coordinate\r
+ * \r
+ * @param x\r
+ * The x-coordinate\r
+ * @param y\r
+ * The y-coordinate\r
* @return The pixel color in 32-bit argb format.\r
*/\r
- public int getPixel (int x, int y);\r
+ public int getPixel(int x, int y);\r
\r
/**\r
- * Returns the yth row of pixels form the Pixmap in the provided pixels array. The pixels array must have at least\r
- * Pixmap.getWidth() elements. The values are returned as 32-bit argb values.\r
+ * Returns the yth row of pixels form the Pixmap in the provided pixels\r
+ * array. The pixels array must have at least Pixmap.getWidth() elements.\r
+ * The values are returned as 32-bit argb values.\r
* \r
- * @param pixels The array to store the pixels in.\r
- * @param y The y-coordinate of the row.\r
+ * @param pixels\r
+ * The array to store the pixels in.\r
+ * @param y\r
+ * The y-coordinate of the row.\r
*/\r
- public void getPixelRow (int[] pixels, int y);\r
+ public void getPixelRow(int[] pixels, int y);\r
\r
/**\r
- * @return The native bitmap object that backs this interface, Bitmap on Android, BufferedImage on PC\r
+ * @return The native bitmap object that backs this interface, Bitmap on\r
+ * Android, BufferedImage on PC\r
*/\r
- public Object getNativePixmap ();\r
+ public Object getNativePixmap();\r
\r
/**\r
* @return The width of the Pixmap in pixels.\r
*/\r
- public int getWidth ();\r
+ public int getWidth();\r
\r
/**\r
* @return The height of the Pixmap in pixels.\r
*/\r
- public int getHeight ();\r
+ public int getHeight();\r
\r
/**\r
* Releases all resources associated with this Pixmap.\r
*/\r
- public void dispose ();\r
+ public void dispose();\r
}\r
-\r
package com.badlogic.gdx.graphics;\r
\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.utils.MathUtils;\r
\r
/**\r
- * Holds the geometry, color, and texture information for drawing 2D sprites using {@link SpriteBatch}. A Sprite has a position\r
- * and a size given as width and height. The position is relative to the origin of the coordinate system specified via\r
- * {@link SpriteBatch#begin()} and the respective matrices. A Sprite is always rectangular and its position (x, y) are located in\r
- * the bottom left corner of that rectangle. A Sprite also has an origin around which rotations and scaling are performed. The\r
- * origin is given relative to the bottom left corner of the Sprite. Texture information is given as pixels and is always relative\r
- * to texture space.\r
+ * Holds the geometry, color, and texture information for drawing 2D sprites\r
+ * using {@link SpriteBatch}. A Sprite has a position and a size given as width\r
+ * and height. The position is relative to the origin of the coordinate system\r
+ * specified via {@link SpriteBatch#begin()} and the respective matrices. A\r
+ * Sprite is always rectangular and its position (x, y) are located in the\r
+ * bottom left corner of that rectangle. A Sprite also has an origin around\r
+ * which rotations and scaling are performed. The origin is given relative to\r
+ * the bottom left corner of the Sprite, its position. Texture information is given as pixels\r
+ * and is always relative to texture space.\r
* \r
* @author mzechner\r
* @author Nathan Sweet <misc@n4te.com>\r
private boolean dirty;\r
\r
/**\r
- * Creates an uninitialized sprite. The sprite will need a texture, texture region, bounds, and color set before it can be\r
- * drawn.\r
+ * Creates an uninitialized sprite. The sprite will need a texture, texture\r
+ * region, bounds, and color set before it can be drawn.\r
*/\r
- public Sprite () {\r
+ public Sprite() {\r
}\r
\r
/**\r
- * Creates a sprite with width, height, and texture region equal to the size of the texture.\r
+ * Creates a sprite with width, height, and texture region equal to the size\r
+ * of the texture.\r
*/\r
- public Sprite (Texture texture) {\r
+ public Sprite(Texture texture) {\r
this(texture, 0, 0, texture.getWidth(), texture.getHeight());\r
}\r
\r
/**\r
- * Creates a sprite with width, height, and texture region equal to the specified size. The texture region's upper left corner\r
- * will be 0,0.\r
- * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn.\r
- * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn.\r
+ * Creates a sprite with width, height, and texture region equal to the\r
+ * specified size. The texture region's upper left corner will be 0,0.\r
+ * \r
+ * @param srcWidth\r
+ * The width of the texture region. May be negative to flip the\r
+ * sprite when drawn.\r
+ * @param srcHeight\r
+ * The height of the texture region. May be negative to flip the\r
+ * sprite when drawn.\r
*/\r
- public Sprite (Texture texture, int srcWidth, int srcHeight) {\r
+ public Sprite(Texture texture, int srcWidth, int srcHeight) {\r
this(texture, 0, 0, srcWidth, srcHeight);\r
}\r
\r
/**\r
- * Creates a sprite with width, height, and texture region equal to the specified size.\r
- * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn.\r
- * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn.\r
+ * Creates a sprite with width, height, and texture region equal to the\r
+ * specified size.\r
+ * \r
+ * @param srcWidth\r
+ * The width of the texture region. May be negative to flip the\r
+ * sprite when drawn.\r
+ * @param srcHeight\r
+ * The height of the texture region. May be negative to flip the\r
+ * sprite when drawn.\r
*/\r
- public Sprite (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) {\r
- if (texture == null) throw new IllegalArgumentException("texture cannot be null.");\r
+ public Sprite(Texture texture, int srcX, int srcY, int srcWidth,\r
+ int srcHeight) {\r
+ if (texture == null)\r
+ throw new IllegalArgumentException("texture cannot be null.");\r
this.texture = texture;\r
setTextureRegion(srcX, srcY, srcWidth, srcHeight);\r
setColor(1, 1, 1, 1);\r
}\r
\r
/**\r
- * Creates a sprite with width, height, and texture region equal to the specified size, relative to specified sprite's texture\r
- * region.\r
- * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn.\r
- * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn.\r
+ * Creates a sprite with width, height, and texture region equal to the\r
+ * specified size, relative to specified sprite's texture region.\r
+ * \r
+ * @param srcWidth\r
+ * The width of the texture region. May be negative to flip the\r
+ * sprite when drawn.\r
+ * @param srcHeight\r
+ * The height of the texture region. May be negative to flip the\r
+ * sprite when drawn.\r
*/\r
- public Sprite (Sprite parent, int srcX, int srcY, int srcWidth, int srcHeight) {\r
- this(parent.texture, (int)(srcX + parent.vertices[U1] * parent.texture.getWidth()), (int)(srcY + parent.vertices[V2]\r
- * parent.texture.getHeight()), srcWidth, srcHeight);\r
+ public Sprite(Sprite parent, int srcX, int srcY, int srcWidth, int srcHeight) {\r
+ this(parent.texture, (int) (srcX + parent.vertices[U1]\r
+ * parent.texture.getWidth()), (int) (srcY + parent.vertices[V2]\r
+ * parent.texture.getHeight()), srcWidth, srcHeight);\r
}\r
\r
/**\r
- * Sets the position and size of the sprite when drawn, before scaling and rotation are applied. If origin, rotation, or scale\r
- * are changed, it is slightly more efficient to set the bounds after those operations.\r
+ * Sets the position and size of the sprite when drawn, before scaling and\r
+ * rotation are applied. If origin, rotation, or scale are changed, it is\r
+ * slightly more efficient to set the bounds after those operations.\r
*/\r
- public void setBounds (float x, float y, float width, float height) {\r
+ public void setBounds(float x, float y, float width, float height) {\r
this.x = x;\r
this.y = y;\r
this.width = width;\r
this.height = height;\r
\r
- if (dirty) return;\r
+ if (dirty)\r
+ return;\r
\r
float x2 = x + width;\r
float y2 = y + height;\r
vertices[X4] = x2;\r
vertices[Y4] = y;\r
\r
- if (rotation != 0 || scaleX != 1 || scaleY != 1) dirty = true;\r
+ if (rotation != 0 || scaleX != 1 || scaleY != 1)\r
+ dirty = true;\r
}\r
\r
/**\r
- * Sets the size of the sprite when drawn, before scaling and rotation are applied. If origin, rotation, or scale are changed,\r
- * it is slightly more efficient to set the size after those operations. If both position and size are to be changed, it is\r
- * better to use {@link #setBounds(float, float, float, float)}.\r
+ * Sets the size of the sprite when drawn, before scaling and rotation are\r
+ * applied. If origin, rotation, or scale are changed, it is slightly more\r
+ * efficient to set the size after those operations. If both position and\r
+ * size are to be changed, it is better to use\r
+ * {@link #setBounds(float, float, float, float)}.\r
*/\r
- public void setSize (float width, float height) {\r
+ public void setSize(float width, float height) {\r
this.width = width;\r
this.height = height;\r
\r
- if (dirty) return;\r
+ if (dirty)\r
+ return;\r
\r
float x2 = x + width;\r
float y2 = y + height;\r
vertices[X4] = x2;\r
vertices[Y4] = y;\r
\r
- if (rotation != 0 || scaleX != 1 || scaleY != 1) dirty = true;\r
+ if (rotation != 0 || scaleX != 1 || scaleY != 1)\r
+ dirty = true;\r
}\r
\r
/**\r
- * Sets the position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient\r
- * to set the position after those operations. If both position and size are to be changed, it is better to use\r
- * {@link #setBounds(float, float, float, float)}.\r
+ * Sets the position where the sprite will be drawn. If origin, rotation, or\r
+ * scale are changed, it is slightly more efficient to set the position\r
+ * after those operations. If both position and size are to be changed, it\r
+ * is better to use {@link #setBounds(float, float, float, float)}.\r
*/\r
- public void setPosition (float x, float y) {\r
+ public void setPosition(float x, float y) {\r
translate(x - this.x, y - this.y);\r
}\r
\r
/**\r
- * Sets the position relative to the current position where the sprite will be drawn. If origin, rotation, or scale are\r
- * changed, it is slightly more efficient to translate after those operations.\r
+ * Sets the position relative to the current position where the sprite will\r
+ * be drawn. If origin, rotation, or scale are changed, it is slightly more\r
+ * efficient to translate after those operations.\r
*/\r
- public void translate (float xAmount, float yAmount) {\r
+ public void translate(float xAmount, float yAmount) {\r
x += xAmount;\r
y += yAmount;\r
\r
- if (dirty) return;\r
+ if (dirty)\r
+ return;\r
\r
float[] vertices = this.vertices;\r
vertices[X1] += xAmount;\r
}\r
\r
/**\r
- * Sets the texture coordinates in pixels to apply to the sprite. This resets calling {@link #flip(boolean, boolean)}.\r
- * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn.\r
- * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn.\r
+ * Sets the texture coordinates in pixels to apply to the sprite. This\r
+ * resets calling {@link #flip(boolean, boolean)}.\r
+ * \r
+ * @param srcWidth\r
+ * The width of the texture region. May be negative to flip the\r
+ * sprite when drawn.\r
+ * @param srcHeight\r
+ * The height of the texture region. May be negative to flip the\r
+ * sprite when drawn.\r
*/\r
- public void setTextureRegion (int srcX, int srcY, int srcWidth, int srcHeight) {\r
+ public void setTextureRegion(int srcX, int srcY, int srcWidth, int srcHeight) {\r
float invTexWidth = 1.0f / texture.getWidth();\r
float invTexHeight = 1.0f / texture.getHeight();\r
float u = srcX * invTexWidth;\r
}\r
\r
/**\r
- * Sets whether the texture will be repeated or stetched. The default is stretched.\r
- * @param x If true, the texture will be repeated.\r
- * @param y If true, the texture will be repeated.\r
+ * Sets whether the texture will be repeated or stetched. The default is\r
+ * stretched.\r
+ * \r
+ * @param x\r
+ * If true, the texture will be repeated.\r
+ * @param y\r
+ * If true, the texture will be repeated.\r
*/\r
- public void setTextureRepeat (boolean x, boolean y) {\r
+ public void setTextureRepeat(boolean x, boolean y) {\r
texture.bind();\r
GL10 gl = Gdx.gl10;\r
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, x ? GL10.GL_REPEAT : GL10.GL_CLAMP_TO_EDGE);\r
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, y ? GL10.GL_REPEAT : GL10.GL_CLAMP_TO_EDGE);\r
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,\r
+ x ? GL10.GL_REPEAT : GL10.GL_CLAMP_TO_EDGE);\r
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,\r
+ y ? GL10.GL_REPEAT : GL10.GL_CLAMP_TO_EDGE);\r
}\r
\r
/**\r
* Flips the current texture region.\r
*/\r
- public void flip (boolean x, boolean y) {\r
+ public void flip(boolean x, boolean y) {\r
float[] vertices = this.vertices;\r
if (x) {\r
float u = vertices[U1];\r
\r
/**\r
* Offsets the texture region relative to the current texture region.\r
- * @param xAmount The percentage to offset horizontally.\r
- * @param yAmount The percentage to offset vertically.\r
+ * \r
+ * @param xAmount\r
+ * The percentage to offset horizontally.\r
+ * @param yAmount\r
+ * The percentage to offset vertically.\r
*/\r
- public void scrollTexture (float xAmount, float yAmount) {\r
+ public void scrollTexture(float xAmount, float yAmount) {\r
float[] vertices = this.vertices;\r
if (xAmount != 0) {\r
float u = (vertices[U1] + xAmount) % 1;\r
}\r
}\r
\r
- public void setColor (Color tint) {\r
+ public void setColor(Color tint) {\r
float color = tint.toFloatBits();\r
float[] vertices = this.vertices;\r
vertices[C1] = color;\r
vertices[C4] = color;\r
}\r
\r
- public void setColor (float r, float g, float b, float a) {\r
- int intBits = ((int)(255 * a) << 24) | //\r
- ((int)(255 * b) << 16) | //\r
- ((int)(255 * g) << 8) | //\r
- ((int)(255 * r));\r
+ public void setColor(float r, float g, float b, float a) {\r
+ int intBits = ((int) (255 * a) << 24) | //\r
+ ((int) (255 * b) << 16) | //\r
+ ((int) (255 * g) << 8) | //\r
+ ((int) (255 * r));\r
float color = Float.intBitsToFloat(intBits);\r
float[] vertices = this.vertices;\r
vertices[C1] = color;\r
}\r
\r
/**\r
- * Sets the origin in relation to the sprite's position for scaling and rotation.\r
+ * Sets the origin in relation to the sprite's position for scaling and\r
+ * rotation.\r
*/\r
- public void setOrigin (float originX, float originY) {\r
+ public void setOrigin(float originX, float originY) {\r
this.originX = originX;\r
this.originY = originY;\r
dirty = true;\r
}\r
\r
- public void setRotation (float degrees) {\r
+ public void setRotation(float degrees) {\r
this.rotation = degrees;\r
dirty = true;\r
}\r
/**\r
* Sets the sprite's rotation relative to the current rotation.\r
*/\r
- public void rotate (float degrees) {\r
+ public void rotate(float degrees) {\r
rotation += degrees;\r
dirty = true;\r
}\r
\r
- public void setScale (float scaleXY) {\r
+ public void setScale(float scaleXY) {\r
this.scaleX = this.scaleY = scaleXY;\r
dirty = true;\r
}\r
\r
- public void setScale (float scaleX, float scaleY) {\r
+ public void setScale(float scaleX, float scaleY) {\r
this.scaleX = scaleX;\r
this.scaleY = scaleY;\r
dirty = true;\r
/**\r
* Sets the sprite's scale relative to the current scale.\r
*/\r
- public void scale (float amount) {\r
+ public void scale(float amount) {\r
this.scaleX += amount;\r
this.scaleY += amount;\r
dirty = true;\r
}\r
\r
- public void draw (SpriteBatch spriteBatch) {\r
+ public void draw(SpriteBatch spriteBatch) {\r
if (dirty) {\r
dirty = false;\r
\r
spriteBatch.draw(texture, vertices, 0, 20);\r
}\r
\r
- public void setTexture (Texture texture) {\r
+ public void setTexture(Texture texture) {\r
this.texture = texture;\r
}\r
\r
- public Texture getTexture () {\r
+ public Texture getTexture() {\r
return texture;\r
}\r
\r
- public float getX () {\r
+ public float getX() {\r
return x;\r
}\r
\r
- public float getY () {\r
+ public float getY() {\r
return y;\r
}\r
\r
- public float getWidth () {\r
+ public float getWidth() {\r
return width;\r
}\r
\r
- public float getHeight () {\r
+ public float getHeight() {\r
return height;\r
}\r
\r
- public float getOriginX () {\r
+ public float getOriginX() {\r
return originX;\r
}\r
\r
- public float getOriginY () {\r
+ public float getOriginY() {\r
return originY;\r
}\r
\r
- public float getRotation () {\r
+ public float getRotation() {\r
return rotation;\r
}\r
\r
- public float getScaleX () {\r
+ public float getScaleX() {\r
return scaleX;\r
}\r
\r
- public float getScaleY () {\r
+ public float getScaleY() {\r
return scaleY;\r
}\r
\r
/**\r
- * Returns the color for this sprite. Changing the returned color will have no affect. {@link #setColor(Color)} or\r
+ * Returns the color for this sprite. Changing the returned color will have\r
+ * no affect. {@link #setColor(Color)} or\r
* {@link #setColor(float, float, float, float)} must be used.\r
*/\r
- public Color getColor () {\r
+ public Color getColor() {\r
int intBits = Float.floatToIntBits(vertices[C1]);\r
Color color = this.color;\r
color.r = (intBits & 0xff) / 255f;\r
\r
/**\r
* <p>\r
- * A SpriteBatch is used to draw 2D rectangles that reference a texture (region). The class will batch the drawing commands and\r
- * optimize them for processing by the GPU.\r
+ * A SpriteBatch is used to draw 2D rectangles that reference a texture\r
+ * (region). The class will batch the drawing commands and optimize them for\r
+ * processing by the GPU.\r
* </p>\r
* \r
* <p>\r
- * To draw something with a SpriteBatch one has to first call the {@link SpriteBatch.begin()} method which will setup appropriate\r
- * render states. When you are done with drawing you have to call {@link SpriteBatch.end()} which will actually draw the things\r
- * you specified.\r
+ * To draw something with a SpriteBatch one has to first call the\r
+ * {@link SpriteBatch#begin()} method which will setup appropriate render\r
+ * states. When you are done with drawing you have to call\r
+ * {@link SpriteBatch#end()} which will actually draw the things you specified.\r
* </p>\r
* \r
* <p>\r
- * All drawing commands of the SpriteBatch operate in screen coordinates. The screen coordinate system has an x-axis pointing to\r
- * the right, an y-axis pointing upwards and the origin is in the lower left corner of the screen. You can also provide your own\r
- * transformation and projection matrices if you so wish.\r
+ * All drawing commands of the SpriteBatch operate in screen coordinates. The\r
+ * screen coordinate system has an x-axis pointing to the right, an y-axis\r
+ * pointing upwards and the origin is in the lower left corner of the screen.\r
+ * You can also provide your own transformation and projection matrices if you\r
+ * so wish.\r
* </p>\r
* \r
* <p>\r
- * A sprite rendered via this batch has an origin relative to it's top left corner and a position in screen coordinates for that\r
- * origin.\r
+ * A SpriteBatch is managed. In case the OpenGL context is lost all OpenGL\r
+ * resources a SpriteBatch uses internally get invalidated. A context is lost\r
+ * when a user switches to another application or receives an incoming call on\r
+ * Android. A SpriteBatch will be automatically reloaded after the\r
+ * OpenGL context is restored.\r
* </p>\r
* \r
* <p>\r
- * A sprite has a width and height in screen coordinates\r
+ * A SpriteBatch is a pretty heavy object so you should only ever have one in\r
+ * your program.\r
* </p>\r
* \r
* <p>\r
- * A sprite can be scaled on the x and y axis.\r
- * </p>\r
- * \r
- * <p>\r
- * A sprite can be rotated around the origin by some angle.\r
- * </p>\r
- * \r
- * <p>\r
- * A sprite references a portion of a texture where the portion is specified in texels.\r
- * </p>\r
- * \r
- * <p>\r
- * A SpriteBatch can be managed. In case the OpenGL context is lost all OpenGL resources a SpriteBatch uses internally get\r
- * invalidated. A context is lost when a user switches to another application or receives an incoming call. A managed SpriteBatch\r
- * will be automatically reloaded after the OpenGL context is restored.\r
- * </p>\r
- * \r
- * <p>\r
- * A SpriteBatch is a pretty heavy object so you should only ever have one in your program.\r
- * </p>\r
- * \r
- * <p>\r
- * A SpriteBatch works with OpenGL ES 1.x and 2.0. In the case of a 2.0 context it will use its own custom shader to draw all\r
- * provided sprites. Specifying your own shader does not work (yet).\r
+ * A SpriteBatch works with OpenGL ES 1.x and 2.0. In the case of a 2.0 context\r
+ * it will use its own custom shader to draw all provided sprites. Specifying\r
+ * your own shader does not work (yet).\r
* </p>\r
* \r
* <p>\r
protected boolean blendingDisabled = false;\r
\r
/**\r
- * Constructs a new SpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards, x-axis\r
- * point to the right and the origin being in the bottome left corner of the screen. The projection will be pixel perfect with\r
- * respect to the screen resolution.\r
+ * Constructs a new SpriteBatch. Sets the projection matrix to an\r
+ * orthographic projection with y-axis point upwards, x-axis point to the\r
+ * right and the origin being in the bottome left corner of the screen. The\r
+ * projection will be pixel perfect with respect to the screen resolution.\r
*/\r
- public SpriteBatch () {\r
+ public SpriteBatch() {\r
this(1000);\r
}\r
\r
/**\r
* <p>\r
- * Constructs a new SpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards, x-axis\r
- * point to the right and the origin being in the bottome left corner of the screen. The projection will be pixel perfect with\r
- * respect to the screen resolution.\r
+ * Constructs a new SpriteBatch. Sets the projection matrix to an\r
+ * orthographic projection with y-axis point upwards, x-axis point to the\r
+ * right and the origin being in the bottome left corner of the screen. The\r
+ * projection will be pixel perfect with respect to the screen resolution.\r
* </p>\r
* \r
* <p>\r
- * The size parameter specifies the maximum size of a single batch in number of sprites\r
+ * The size parameter specifies the maximum size of a single batch in number\r
+ * of sprites\r
* </p>\r
* \r
- * @param size the batch size in number of sprites\r
+ * @param size\r
+ * the batch size in number of sprites\r
*/\r
- public SpriteBatch (int size) {\r
- this.mesh = new Mesh(false, size * 4, size * 6, new VertexAttribute(Usage.Position, 2, "a_position"),\r
- new VertexAttribute(Usage.ColorPacked, 4, "a_color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));\r
- \r
- projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
+ public SpriteBatch(int size) {\r
+ this.mesh = new Mesh(false, size * 4, size * 6, new VertexAttribute(\r
+ Usage.Position, 2, "a_position"), new VertexAttribute(\r
+ Usage.ColorPacked, 4, "a_color"), new VertexAttribute(\r
+ Usage.TextureCoordinates, 2, "a_texCoords"));\r
+\r
+ projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(),\r
+ Gdx.graphics.getHeight());\r
\r
vertices = new float[size * SPRITE_SIZE];\r
\r
int len = size * 6;\r
short j = 0;\r
for (int i = 0; i < len; i += 6, j += 4) {\r
- indices[i + 0] = (short)(j + 0);\r
- indices[i + 1] = (short)(j + 1);\r
- indices[i + 2] = (short)(j + 2);\r
- indices[i + 3] = (short)(j + 2);\r
- indices[i + 4] = (short)(j + 3);\r
- indices[i + 5] = (short)(j + 0);\r
+ indices[i + 0] = (short) (j + 0);\r
+ indices[i + 1] = (short) (j + 1);\r
+ indices[i + 2] = (short) (j + 2);\r
+ indices[i + 3] = (short) (j + 2);\r
+ indices[i + 4] = (short) (j + 3);\r
+ indices[i + 5] = (short) (j + 0);\r
}\r
mesh.setIndices(indices);\r
\r
- if (Gdx.graphics.isGL20Available()) createShader();\r
+ if (Gdx.graphics.isGL20Available())\r
+ createShader();\r
}\r
\r
- private void createShader () {\r
- String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color; \n" + "attribute vec2 a_texCoords; \n"\r
- + "uniform mat4 u_projectionViewMatrix; \n" + "varying vec4 v_color; \n" + "varying vec2 v_texCoords; \n" + " \n"\r
- + "void main() \n" + "{ \n" + " v_color = a_color; \n"\r
- + " v_texCoords = a_texCoords; \n" + " gl_Position = u_projectionViewMatrix * a_position; \n" + "} \n";\r
- String fragmentShader = "precision mediump float;\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n"\r
- + "uniform sampler2D u_texture;\n" + "void main() \n"\r
- + "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords); \n"\r
- + "}";\r
+ private void createShader() {\r
+ String vertexShader = "attribute vec4 a_position; \n"\r
+ + "attribute vec4 a_color; \n"\r
+ + "attribute vec2 a_texCoords; \n"\r
+ + "uniform mat4 u_projectionViewMatrix; \n"\r
+ + "varying vec4 v_color; \n" + "varying vec2 v_texCoords; \n"\r
+ + " \n" + "void main() \n"\r
+ + "{ \n"\r
+ + " v_color = a_color; \n"\r
+ + " v_texCoords = a_texCoords; \n"\r
+ + " gl_Position = u_projectionViewMatrix * a_position; \n"\r
+ + "} \n";\r
+ String fragmentShader = "precision mediump float;\n"\r
+ + "varying vec4 v_color;\n"\r
+ + "varying vec2 v_texCoords;\n"\r
+ + "uniform sampler2D u_texture;\n"\r
+ + "void main() \n"\r
+ + "{ \n"\r
+ + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords); \n"\r
+ + "}";\r
\r
shader = new ShaderProgram(vertexShader, fragmentShader);\r
- if (shader.isCompiled() == false) throw new IllegalArgumentException("couldn't compile shader: " + shader.getLog());\r
+ if (shader.isCompiled() == false)\r
+ throw new IllegalArgumentException("couldn't compile shader: "\r
+ + shader.getLog());\r
}\r
\r
/**\r
- * Sets up the SpriteBatch for drawing. This will disable depth buffer testing and writting, culling and lighting. It enables\r
- * blending and alpha testing. If you have more texture units enabled than the first one you have to disable them before\r
- * calling this. Applies the given transformation {@link Matrix4} to all subsequently specified sprites. Uses the provided\r
- * projection matrix and therefore does not necessarily work in screen coordinates anymore. You have to know what you do if you\r
- * use this.\r
- * \r
- * @param projection the projection matrix;\r
- * @param transform the transformation matrix.\r
+ * Sets up the SpriteBatch for drawing. This will disable depth buffer\r
+ * testing and writting, culling and lighting. It enables blending and alpha\r
+ * testing. If you have more texture units enabled than the first one you\r
+ * have to disable them before calling this. Uses a screen coordinate system\r
+ * by default where everything is given in pixels. You can specify your own\r
+ * projection and modelview matrices via {@link #setProjectionMatrix(Matrix4)}\r
+ * and {@link #setTransformMatrix(Matrix4)}.\r
*/\r
- public void begin () {\r
- if (drawing) throw new IllegalStateException("you have to call SpriteBatch.end() first");\r
- renderCalls = 0; \r
- \r
+ public void begin() {\r
+ if (drawing)\r
+ throw new IllegalStateException(\r
+ "you have to call SpriteBatch.end() first");\r
+ renderCalls = 0;\r
+\r
if (Gdx.graphics.isGL20Available() == false) {\r
GL10 gl = Gdx.gl10;\r
- gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
+ gl.glViewport(0, 0, Gdx.graphics.getWidth(),\r
+ Gdx.graphics.getHeight());\r
gl.glDisable(GL10.GL_LIGHTING);\r
gl.glDisable(GL10.GL_DEPTH_TEST);\r
gl.glDisable(GL10.GL_CULL_FACE);\r
gl.glMatrixMode(GL10.GL_PROJECTION);\r
gl.glLoadMatrixf(projectionMatrix.val, 0);\r
gl.glMatrixMode(GL10.GL_MODELVIEW);\r
- gl.glLoadMatrixf(transformMatrix.val, 0); \r
+ gl.glLoadMatrixf(transformMatrix.val, 0);\r
} else {\r
combinedMatrix.set(projectionMatrix).mul(transformMatrix);\r
\r
GL20 gl = Gdx.gl20;\r
- gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
+ gl.glViewport(0, 0, Gdx.graphics.getWidth(),\r
+ Gdx.graphics.getHeight());\r
gl.glDisable(GL20.GL_DEPTH_TEST);\r
gl.glDisable(GL20.GL_CULL_FACE);\r
gl.glDepthMask(false);\r
\r
shader.begin();\r
shader.setUniformMatrix("u_projectionViewMatrix", combinedMatrix);\r
- shader.setUniformi("u_texture", 0); \r
+ shader.setUniformi("u_texture", 0);\r
}\r
\r
idx = 0;\r
}\r
\r
/**\r
- * Finishes off rendering of the last batch of sprites\r
+ * Finishes off rendering. Must always be called after a call to {@link #begin()}\r
*/\r
- public void end () {\r
- if (!drawing) throw new IllegalStateException("you have to call SpriteBatch.begin() first");\r
- if (idx > 0) renderMesh();\r
+ public void end() {\r
+ if (!drawing)\r
+ throw new IllegalStateException(\r
+ "you have to call SpriteBatch.begin() first");\r
+ if (idx > 0)\r
+ renderMesh();\r
lastTexture = null;\r
idx = 0;\r
drawing = false;\r
GL10 gl = Gdx.gl10;\r
gl.glDepthMask(true);\r
gl.glDisable(GL10.GL_BLEND);\r
- gl.glDisable(GL10.GL_TEXTURE_2D); \r
+ gl.glDisable(GL10.GL_TEXTURE_2D);\r
} else {\r
shader.end();\r
GL20 gl = Gdx.gl20;\r
gl.glDepthMask(true);\r
gl.glDisable(GL20.GL_BLEND);\r
- gl.glDisable(GL20.GL_TEXTURE_2D); \r
- } \r
+ gl.glDisable(GL20.GL_TEXTURE_2D);\r
+ }\r
}\r
\r
/**\r
- * Draws a rectangle with the top left corner at x,y having the given width and height in pixels. The rectangle is offset by\r
- * originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle should be scaled around\r
- * originX,originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around originX, originY. The\r
- * portion of the {@link Texture} given by srcX, srcY and srcWidth, srcHeight is used. These coordinates and sizes are given in\r
- * texels. The rectangle will have the given tint {@link Color}. FlipX and flipY specify whether the texture portion should be\r
- * fliped horizontally or vertically.\r
+ * Draws a rectangle with the top left corner at x,y having the given width\r
+ * and height in pixels. The rectangle is offset by originX, originY\r
+ * relative to the origin. Scale specifies the scaling factor by which the\r
+ * rectangle should be scaled around originX,originY. Rotation specifies the\r
+ * angle of counter clockwise rotation of the rectangle around originX,\r
+ * originY. The portion of the {@link Texture} given by srcX, srcY and\r
+ * srcWidth, srcHeight is used. These coordinates and sizes are given in\r
+ * texels. The rectangle will have the given tint {@link Color}. FlipX and\r
+ * flipY specify whether the texture portion should be fliped horizontally\r
+ * or vertically.\r
* \r
- * @param texture the Texture\r
- * @param x the x-coordinate in screen space\r
- * @param y the y-coordinate in screen space\r
- * @param originX the x-coordinate of the scaling and rotation origin relative to the screen space coordinates\r
- * @param originY the y-coordinate of the scaling and rotation origin relative to the screen space coordinates\r
- * @param width the width in pixels\r
- * @param height the height in pixels\r
- * @param scaleX the scale of the rectangle around originX/originY in x\r
- * @param scaleY the scale of the rectangle around originX/originY in y\r
- * @param rotation the angle of counter clockwise rotation of the rectangle around originX/originY\r
- * @param srcX the x-coordinate in texel space\r
- * @param srcY the y-coordinate in texel space\r
- * @param srcWidth the source with in texels\r
- * @param srcHeight the source height in texels\r
- * @param tint the tint Color\r
- * @param flipX whether to flip the sprite horizontally\r
- * @param flipY whether to flip the sprite vertically\r
+ * @param texture\r
+ * the Texture\r
+ * @param x\r
+ * the x-coordinate in screen space\r
+ * @param y\r
+ * the y-coordinate in screen space\r
+ * @param originX\r
+ * the x-coordinate of the scaling and rotation origin relative\r
+ * to the screen space coordinates\r
+ * @param originY\r
+ * the y-coordinate of the scaling and rotation origin relative\r
+ * to the screen space coordinates\r
+ * @param width\r
+ * the width in pixels\r
+ * @param height\r
+ * the height in pixels\r
+ * @param scaleX\r
+ * the scale of the rectangle around originX/originY in x\r
+ * @param scaleY\r
+ * the scale of the rectangle around originX/originY in y\r
+ * @param rotation\r
+ * the angle of counter clockwise rotation of the rectangle\r
+ * around originX/originY\r
+ * @param srcX\r
+ * the x-coordinate in texel space\r
+ * @param srcY\r
+ * the y-coordinate in texel space\r
+ * @param srcWidth\r
+ * the source with in texels\r
+ * @param srcHeight\r
+ * the source height in texels\r
+ * @param tint\r
+ * the tint Color\r
+ * @param flipX\r
+ * whether to flip the sprite horizontally\r
+ * @param flipY\r
+ * whether to flip the sprite vertically\r
*/\r
- public void draw (Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX,\r
- float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, Color tint, boolean flipX, boolean flipY) {\r
- if (!drawing) throw new IllegalStateException("you have to call SpriteBatch.begin() first");\r
+ public void draw(Texture texture, float x, float y, float originX,\r
+ float originY, float width, float height, float scaleX,\r
+ float scaleY, float rotation, int srcX, int srcY, int srcWidth,\r
+ int srcHeight, Color tint, boolean flipX, boolean flipY) {\r
+ if (!drawing)\r
+ throw new IllegalStateException(\r
+ "you have to call SpriteBatch.begin() first");\r
\r
if (texture != lastTexture) {\r
renderMesh();\r
vertices[idx++] = u2;\r
vertices[idx++] = v;\r
\r
- if (idx == vertices.length) renderMesh();\r
+ if (idx == vertices.length)\r
+ renderMesh();\r
}\r
\r
/**\r
- * Draws a rectangle with the top left corner at x,y having the given width and height in pixels. The portion of the\r
- * {@link Texture} given by srcX, srcY and srcWidth, srcHeight is used. These coordinates and sizes are given in texels. The\r
- * rectangle will have the given tint {@link Color}. FlipX and flipY specify whether the texture portion should be fliped\r
+ * Draws a rectangle with the top left corner at x,y having the given width\r
+ * and height in pixels. The portion of the {@link Texture} given by srcX,\r
+ * srcY and srcWidth, srcHeight is used. These coordinates and sizes are\r
+ * given in texels. The rectangle will have the given tint {@link Color}.\r
+ * FlipX and flipY specify whether the texture portion should be fliped\r
* horizontally or vertically.\r
* \r
- * @param texture the Texture\r
- * @param x the x-coordinate in screen space\r
- * @param y the y-coordinate in screen space\r
- * @param width the width in pixels\r
- * @param height the height in pixels\r
- * @param srcX the x-coordinate in texel space\r
- * @param srcY the y-coordinate in texel space\r
- * @param srcWidth the source with in texels\r
- * @param srcHeight the source height in texels\r
- * @param tint the tint Color\r
- * @param flipX whether to flip the sprite horizontally\r
- * @param flipY whether to flip the sprite vertically\r
+ * @param texture\r
+ * the Texture\r
+ * @param x\r
+ * the x-coordinate in screen space\r
+ * @param y\r
+ * the y-coordinate in screen space\r
+ * @param width\r
+ * the width in pixels\r
+ * @param height\r
+ * the height in pixels\r
+ * @param srcX\r
+ * the x-coordinate in texel space\r
+ * @param srcY\r
+ * the y-coordinate in texel space\r
+ * @param srcWidth\r
+ * the source with in texels\r
+ * @param srcHeight\r
+ * the source height in texels\r
+ * @param tint\r
+ * the tint Color\r
+ * @param flipX\r
+ * whether to flip the sprite horizontally\r
+ * @param flipY\r
+ * whether to flip the sprite vertically\r
*/\r
- public void draw (Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth,\r
- int srcHeight, Color tint, boolean flipX, boolean flipY) {\r
- if (!drawing) throw new IllegalStateException("you have to call SpriteBatch.begin() first");\r
+ public void draw(Texture texture, float x, float y, float width,\r
+ float height, int srcX, int srcY, int srcWidth, int srcHeight,\r
+ Color tint, boolean flipX, boolean flipY) {\r
+ if (!drawing)\r
+ throw new IllegalStateException(\r
+ "you have to call SpriteBatch.begin() first");\r
\r
if (texture != lastTexture) {\r
renderMesh();\r
vertices[idx++] = u2;\r
vertices[idx++] = v;\r
\r
- if (idx == vertices.length) renderMesh();\r
+ if (idx == vertices.length)\r
+ renderMesh();\r
}\r
\r
/**\r
- * Draws a rectangle with the top left corner at x,y having the given width and height in pixels. The portion of the\r
- * {@link Texture} given by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels. The\r
- * rectangle will have the given tint {@link Color}.\r
+ * Draws a rectangle with the top left corner at x,y having the given width\r
+ * and height in pixels. The portion of the {@link Texture} given by srcX,\r
+ * srcY and srcWidth, srcHeight are used. These coordinates and sizes are\r
+ * given in texels. The rectangle will have the given tint {@link Color}.\r
* \r
- * @param texture the Texture\r
- * @param x the x-coordinate in screen space\r
- * @param y the y-coordinate in screen space\r
- * @param srcX the x-coordinate in texel space\r
- * @param srcY the y-coordinate in texel space\r
- * @param srcWidth the source with in texels\r
- * @param srcHeight the source height in texels\r
- * @param tint the tint Color\r
+ * @param texture\r
+ * the Texture\r
+ * @param x\r
+ * the x-coordinate in screen space\r
+ * @param y\r
+ * the y-coordinate in screen space\r
+ * @param srcX\r
+ * the x-coordinate in texel space\r
+ * @param srcY\r
+ * the y-coordinate in texel space\r
+ * @param srcWidth\r
+ * the source with in texels\r
+ * @param srcHeight\r
+ * the source height in texels\r
+ * @param tint\r
+ * the tint Color\r
*/\r
- public void draw (Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight, Color tint) {\r
- if (!drawing) throw new IllegalStateException("you have to call SpriteBatch.begin() first");\r
+ public void draw(Texture texture, float x, float y, int srcX, int srcY,\r
+ int srcWidth, int srcHeight, Color tint) {\r
+ if (!drawing)\r
+ throw new IllegalStateException(\r
+ "you have to call SpriteBatch.begin() first");\r
\r
if (texture != lastTexture) {\r
renderMesh();\r
vertices[idx++] = u2;\r
vertices[idx++] = v;\r
\r
- if (idx == vertices.length) renderMesh();\r
+ if (idx == vertices.length)\r
+ renderMesh();\r
}\r
\r
/**\r
- * Draws a rectangle with the top left corner at x,y having the given width and height in pixels. The portion of the\r
- * {@link Texture} given by u, v and u2, v2 are used. These coordinates and sizes are given in texture size percentage. The\r
- * rectangle will have the given tint {@link Color}.\r
+ * Draws a rectangle with the top left corner at x,y having the given width\r
+ * and height in pixels. The portion of the {@link Texture} given by u, v\r
+ * and u2, v2 are used. These coordinates and sizes are given in texture\r
+ * size percentage. The rectangle will have the given tint {@link Color}.\r
* \r
- * @param texture the Texture\r
- * @param x the x-coordinate in screen space\r
- * @param y the y-coordinate in screen space\r
- * @param srcWidth the source with in texels\r
- * @param srcHeight the source height in texels\r
- * @param color the tint Color\r
+ * @param texture\r
+ * the Texture\r
+ * @param x\r
+ * the x-coordinate in screen space\r
+ * @param y\r
+ * the y-coordinate in screen space\r
+ * @param srcWidth\r
+ * the source with in texels\r
+ * @param srcHeight\r
+ * the source height in texels\r
+ * @param color\r
+ * the tint Color\r
*/\r
- public void draw (Texture texture, float x, float y, int srcWidth, int srcHeight, float u, float v, float u2, float v2,\r
- float color) {\r
- if (!drawing) throw new IllegalStateException("you have to call SpriteBatch.begin() first");\r
+ public void draw(Texture texture, float x, float y, int srcWidth,\r
+ int srcHeight, float u, float v, float u2, float v2, float color) {\r
+ if (!drawing)\r
+ throw new IllegalStateException(\r
+ "you have to call SpriteBatch.begin() first");\r
\r
if (texture != lastTexture) {\r
renderMesh();\r
vertices[idx++] = u2;\r
vertices[idx++] = v;\r
\r
- if (idx == vertices.length) renderMesh();\r
+ if (idx == vertices.length)\r
+ renderMesh();\r
}\r
\r
- public void draw (Texture texture, float[] spriteVertices, int offset, int length) {\r
- if (!drawing) throw new IllegalStateException("you have to call SpriteBatch.begin() first");\r
+ public void draw(Texture texture, float[] spriteVertices, int offset,\r
+ int length) {\r
+ if (!drawing)\r
+ throw new IllegalStateException(\r
+ "you have to call SpriteBatch.begin() first");\r
\r
if (texture != lastTexture) {\r
renderMesh();\r
invTexHeight = 1.0f / texture.getHeight();\r
}\r
\r
- if (idx + length >= vertices.length) renderMesh();\r
+ if (idx + length >= vertices.length)\r
+ renderMesh();\r
\r
System.arraycopy(spriteVertices, offset, vertices, idx, length);\r
idx += length;\r
}\r
\r
/**\r
- * Causes any pending sprites to be rendered, without ending the SpriteBatch.\r
+ * Causes any pending sprites to be rendered, without ending the\r
+ * SpriteBatch.\r
*/\r
- public void flush () {\r
+ public void flush() {\r
renderMesh();\r
}\r
- \r
- private void renderMesh () {\r
- if (idx == 0) return;\r
+\r
+ private void renderMesh() {\r
+ if (idx == 0)\r
+ return;\r
\r
renderCalls++;\r
\r
mesh.render(GL10.GL_TRIANGLES, 0, idx / 20 * 6);\r
}\r
idx = 0;\r
- } \r
+ }\r
\r
/**\r
- * Disables blending for drawing sprites. Does not disable blending for text rendering\r
+ * Disables blending for drawing sprites. Does not disable blending for text\r
+ * rendering\r
*/\r
- public void disableBlending () {\r
+ public void disableBlending() {\r
renderMesh();\r
blendingDisabled = true;\r
}\r
/**\r
* Enables blending for sprites\r
*/\r
- public void enableBlending () {\r
+ public void enableBlending() {\r
renderMesh();\r
blendingDisabled = false;\r
}\r
/**\r
* Sets the blending function to be used when rendering sprites.\r
* \r
- * @param srcFunc the source function, e.g. GL11.GL_SRC_ALPHA\r
- * @param dstFunc the destination function, e.g. GL11.GL_ONE_MINUS_SRC_ALPHA\r
+ * @param srcFunc\r
+ * the source function, e.g. GL11.GL_SRC_ALPHA\r
+ * @param dstFunc\r
+ * the destination function, e.g. GL11.GL_ONE_MINUS_SRC_ALPHA\r
*/\r
- public void setBlendFunction (int srcFunc, int dstFunc) {\r
+ public void setBlendFunction(int srcFunc, int dstFunc) {\r
renderMesh();\r
blendSrcFunc = srcFunc;\r
blendDstFunc = dstFunc;\r
/**\r
* Disposes all resources associated with this SpriteBatch\r
*/\r
- public void dispose () {\r
+ public void dispose() {\r
mesh.dispose();\r
- if (shader != null) shader.dispose();\r
+ if (shader != null)\r
+ shader.dispose();\r
}\r
\r
/**\r
- * Returns the current projection matrix. Changing this will result in undefined behaviour.\r
+ * Returns the current projection matrix. Changing this will result in\r
+ * undefined behaviour.\r
* \r
* @return the currently set projection matrix\r
*/\r
- public Matrix4 getProjectionMatrix () {\r
+ public Matrix4 getProjectionMatrix() {\r
return projectionMatrix;\r
}\r
\r
/**\r
- * Returns the current transform matrix. Changing this will result in undefined behaviour.\r
+ * Returns the current transform matrix. Changing this will result in\r
+ * undefined behaviour.\r
* \r
* @return the currently set transform matrix\r
*/\r
- public Matrix4 getTransformMatrix () {\r
+ public Matrix4 getTransformMatrix() {\r
return transformMatrix;\r
}\r
\r
/**\r
- * Sets the projection matrix to be used by this SpriteBatch. Can only be set outside a {@link #begin()}/{@link #end()} block.\r
- * @param projection the projection matrix\r
+ * Sets the projection matrix to be used by this SpriteBatch. Can only be\r
+ * set outside a {@link #begin()}/{@link #end()} block.\r
+ * \r
+ * @param projection\r
+ * the projection matrix\r
*/\r
- public void setProjectionMatrix (Matrix4 projection) {\r
- if (drawing) throw new GdxRuntimeException("Can't set the matrix within begin()/end() block");\r
+ public void setProjectionMatrix(Matrix4 projection) {\r
+ if (drawing)\r
+ throw new GdxRuntimeException(\r
+ "Can't set the matrix within begin()/end() block");\r
\r
projectionMatrix.set(projection);\r
}\r
\r
/**\r
- * Sets the transform matrix to be used by this SpriteBatch. Can only be set outside a {@link #begin()}/{@link #end()} block.\r
- * @param projection the projection matrix\r
+ * Sets the transform matrix to be used by this SpriteBatch. Can only be set\r
+ * outside a {@link #begin()}/{@link #end()} block.\r
+ * \r
+ * @param transform\r
+ * the transform matrix\r
*/\r
- public void setTransformMatrix (Matrix4 transform) {\r
- if (drawing) throw new GdxRuntimeException("Can't set the matrix within begin()/end() block");\r
+ public void setTransformMatrix(Matrix4 transform) {\r
+ if (drawing)\r
+ throw new GdxRuntimeException(\r
+ "Can't set the matrix within begin()/end() block");\r
\r
transformMatrix.set(transform);\r
}\r
/**\r
* @return whether blending for sprites is enabled\r
*/\r
- public boolean isBlendingEnabled () {\r
+ public boolean isBlendingEnabled() {\r
return !blendingDisabled;\r
}\r
}\r
\r
package com.badlogic.gdx.graphics;\r
\r
+import com.badlogic.gdx.Graphics;\r
+\r
/**\r
* <p>\r
* A Texture wraps a standard OpenGL ES texture.\r
* </p>\r
* \r
* <p>\r
- * It is constructed by an {@link Graphics} via one of the {@link Graphics.newTexture()} methods.\r
+ * It is constructed by an {@link Graphics} via one of the following methods:\r
+ * <ul>\r
+ * <li>{@link Graphics#newTexture(com.badlogic.gdx.files.FileHandle, TextureFilter, TextureFilter, TextureWrap, TextureWrap)}</li>\r
+ * <li>{@link Graphics#newUnmanagedTexture(Pixmap, TextureFilter, TextureFilter, TextureWrap, TextureWrap)}</li>\r
+ * <li>{@link Graphics#newUnmanagedTexture(int, int, com.badlogic.gdx.graphics.Pixmap.Format, TextureFilter, TextureFilter, TextureWrap, TextureWrap)}</li>\r
+ * </ul>\r
* </p>\r
* \r
* <p>\r
- * A Texture can be managed. If the OpenGL context is lost all textures get invalidated. This happens when a user switches to\r
- * another application or receives an incoming call. Managed textures get reloaded automatically.\r
+ * A Texture can be managed. If the OpenGL context is lost all managed textures get\r
+ * invalidated. This happens when a user switches to another application or\r
+ * receives an incoming call. Managed textures get reloaded automatically.\r
* </p>\r
* \r
* <p>\r
- * A Texture has to be bound via the {@link Texture.bind()} method in order for it to be applied to geometry.\r
+ * A Texture has to be bound via the {@link Texture#bind()} method in order for\r
+ * it to be applied to geometry. The texture will be bound to the currently active\r
+ * texture unit specified via {@link GLCommon#glActiveTexture(int)}.\r
* </p>\r
* \r
* <p>\r
- * You can draw {@link Pixmap}s to a texture at any time. The changes will be automatically uploaded to texture memory. This is of\r
- * course not extremely fast so use it with care.\r
+ * You can draw {@link Pixmap}s to a texture at any time. The changes will be\r
+ * automatically uploaded to texture memory. This is of course not extremely\r
+ * fast so use it with care. It also only works with unmanaged textures.\r
* </p>\r
* \r
* <p>\r
public interface Texture {\r
/**\r
* Texture filter enum featuring the 3 most used filters.\r
+ * \r
* @author badlogicgames@gmail.com\r
* \r
*/\r
}\r
\r
/**\r
- * Binds this texture. You have to enable texturing via {@link Application.enable( RenderState.Texturing )} in order for the\r
- * texture to actually be applied to geometry.\r
+ * Binds this texture. The texture will be bound to the currently active\r
+ * texture unit specified via {@link GLCommon#glActiveTexture(int)}.\r
*/\r
- public void bind ();\r
+ public void bind();\r
\r
/**\r
* Draws the given {@link Pixmap} to the texture at position x, y.\r
+ * No clipping is performed so you have to make sure that you\r
+ * draw only inside the texture region.\r
* \r
- * @param pixmap The Pixmap\r
- * @param x The x coordinate in pixels\r
- * @param y The y coordinate in pixels\r
+ * @param pixmap\r
+ * The Pixmap\r
+ * @param x\r
+ * The x coordinate in pixels\r
+ * @param y\r
+ * The y coordinate in pixels\r
*/\r
- public void draw (Pixmap pixmap, int x, int y);\r
+ public void draw(Pixmap pixmap, int x, int y);\r
\r
/**\r
* \r
* @return the width of the texture in pixels\r
*/\r
- public int getWidth ();\r
+ public int getWidth();\r
\r
/**\r
* \r
* @return the height of the texture in pixels\r
*/\r
- public int getHeight ();\r
+ public int getHeight();\r
\r
/**\r
* @return whether this texture is managed or not.\r
*/\r
- public boolean isManaged ();\r
+ public boolean isManaged();\r
\r
/**\r
* Disposes all resources associated with the texture\r
- * @return\r
*/\r
- public void dispose ();\r
+ public void dispose();\r
\r
/**\r
- * @return the OpenGL texture object handle so you can change texture parameters.\r
+ * @return the OpenGL texture object handle so you can change texture\r
+ * parameters.\r
*/\r
- public int getTextureObjectHandle ();\r
+ public int getTextureObjectHandle();\r
}\r
-\r
package com.badlogic.gdx.graphics;\r
\r
import java.util.HashMap;\r
import java.util.Map;\r
\r
/**\r
- * A TextureAtlas is composed of a single {@link Texture} and named {@link TextureRegion}s. You can add new regions at any time\r
- * either programmatically or by reading them in from a file.\r
+ * A TextureAtlas is composed of a single {@link Texture} and named\r
+ * {@link TextureRegion}s. You can add new regions at any time.\r
* \r
* @author mzechner\r
* \r
private final Texture texture;\r
\r
/**\r
- * Constructs a new texture atlas with the given texture. Use {@link #addRegion()} or one of the {@link #load()} methods to add\r
- * {@link TextureRegions}\r
+ * Constructs a new texture atlas with the given texture. Use\r
+ * {@link #addRegion(String, TextureRegion)} or {@link #addRegion(String, int, int, int, int)} to add\r
+ * {@link TextureRegion}s\r
* \r
- * @param texture the texture\r
+ * @param texture\r
+ * the texture\r
*/\r
- public TextureAtlas (Texture texture) {\r
+ public TextureAtlas(Texture texture) {\r
this.texture = texture;\r
}\r
\r
/**\r
- * Returns the {@link TextureRegion} with name regionName or null in case the region is undefined.\r
+ * Returns the {@link TextureRegion} with name regionName or null in case\r
+ * the region is undefined.\r
* \r
- * @param regionName the region name\r
+ * @param regionName\r
+ * the region name\r
* @return the region or null.\r
*/\r
- public TextureRegion getRegion (String regionName) {\r
+ public TextureRegion getRegion(String regionName) {\r
return regions.get(regionName);\r
}\r
\r
/**\r
- * Adds the {@link TextureRegion} with name regionName to this atlas. If a region with the given name was present already it\r
- * will be overwritten.\r
+ * Adds the {@link TextureRegion} with name regionName to this atlas. If a\r
+ * region with the given name was present already it will be overwritten.\r
* \r
- * @param regionName the region name\r
- * @param region the region\r
+ * @param regionName\r
+ * the region name\r
+ * @param region\r
+ * the region\r
*/\r
- public void addRegion (String regionName, TextureRegion region) {\r
+ public void addRegion(String regionName, TextureRegion region) {\r
regions.put(regionName, region);\r
}\r
\r
/**\r
- * Adds a new {@link TextureRegion} with name regionName to this atlas. If a region with the given name was already present it\r
- * is overwritten.\r
+ * Adds a new {@link TextureRegion} with name regionName to this atlas. If a\r
+ * region with the given name was already present it is overwritten.\r
* \r
- * @param regionName the region name\r
- * @param x the x coordinate of the region in pixels\r
- * @param y the y coordinate of the region in pixels\r
- * @param width the width of the region in pixels\r
- * @param height the height of the region in pixels\r
+ * @param regionName\r
+ * the region name\r
+ * @param x\r
+ * the x coordinate of the region in pixels\r
+ * @param y\r
+ * the y coordinate of the region in pixels\r
+ * @param width\r
+ * the width of the region in pixels\r
+ * @param height\r
+ * the height of the region in pixels\r
*/\r
- public void addRegion (String regionName, int x, int y, int width, int height) {\r
+ public void addRegion(String regionName, int x, int y, int width, int height) {\r
regions.put(regionName, new TextureRegion(texture, x, y, width, height));\r
}\r
\r
/**\r
* @return the {@link Texture} of this atlas\r
*/\r
- public Texture getTexture () {\r
+ public Texture getTexture() {\r
return texture;\r
}\r
}\r
package com.badlogic.gdx.graphics;\r
\r
/**\r
- * A TextureRegion defines a rectangular area in a texture given in pixels.\r
+ * A TextureRegion defines a rectangular area in a texture given in pixels. The\r
+ * coordinate system used has its origin in the upper left corner with the x-axis\r
+ * pointing to the left and the y axis pointing downwards.\r
* \r
* @author mzechner\r
* \r
import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
\r
/**\r
- * A single vertex attribute defined by its {@link Usage}, its number of components and its shader alias. The Usage is needed for\r
- * the fixed function pipeline of OpenGL ES 1.x. Generic attributes are not supported in the fixed function pipeline. The number\r
- * of components defines how many components the attribute has. The alias defines to which shader attribute this attribute should\r
- * bind. The alias is used by a {@link Mesh} when drawing with a {@link ShaderProgram}. The alias can be changed at any time.\r
+ * A single vertex attribute defined by its {@link Usage}, its number of\r
+ * components and its shader alias. The Usage is needed for the fixed function\r
+ * pipeline of OpenGL ES 1.x. Generic attributes are not supported in the fixed\r
+ * function pipeline. The number of components defines how many components the\r
+ * attribute has. The alias defines to which shader attribute this attribute\r
+ * should bind. The alias is used by a {@link Mesh} when drawing with a\r
+ * {@link ShaderProgram}. The alias can be changed at any time.\r
* \r
* @author mzechner\r
* \r
/**\r
* Constructs a new VertexAttribute.\r
* \r
- * @param usage the usage, used for the fixed function pipeline. Generic attributes are not supported in the fixed function\r
- * pipeline.\r
- * @param numComponents the number of components of this attribute, must be between 1 and 4.\r
- * @param alias the alias used in a shader for this attribute. Can be changed after construction.\r
+ * @param usage\r
+ * the usage, used for the fixed function pipeline. Generic\r
+ * attributes are not supported in the fixed function pipeline.\r
+ * @param numComponents\r
+ * the number of components of this attribute, must be between 1\r
+ * and 4.\r
+ * @param alias\r
+ * the alias used in a shader for this attribute. Can be changed\r
+ * after construction.\r
*/\r
- public VertexAttribute (int usage, int numComponents, String alias) {\r
+ public VertexAttribute(int usage, int numComponents, String alias) {\r
this.usage = usage;\r
this.numComponents = numComponents;\r
this.alias = alias;\r
package com.badlogic.gdx.graphics;\r
\r
/**\r
- * Instances of this class specify the vertex attributes of a mesh. VertexAttributes are used by {@link Mesh} instances to define\r
- * its vertex structure. Vertex attributes have an order. The order is specified by the order they are added to this class.\r
+ * Instances of this class specify the vertex attributes of a mesh.\r
+ * VertexAttributes are used by {@link Mesh} instances to define its vertex\r
+ * structure. Vertex attributes have an order. The order is specified by the\r
+ * order they are added to this class.\r
* \r
* @author mzechner\r
* \r
/**\r
* Constructor, sets the vertex attributes in a specific order\r
*/\r
- public VertexAttributes (VertexAttribute... attributes) {\r
- if (attributes.length == 0) throw new IllegalArgumentException("attributes must be >= 1");\r
+ public VertexAttributes(VertexAttribute... attributes) {\r
+ if (attributes.length == 0)\r
+ throw new IllegalArgumentException("attributes must be >= 1");\r
\r
VertexAttribute[] list = new VertexAttribute[attributes.length];\r
for (int i = 0; i < attributes.length; i++)\r
vertexSize = calculateOffsets();\r
}\r
\r
- private int calculateOffsets () {\r
+ private int calculateOffsets() {\r
int count = 0;\r
for (int i = 0; i < attributes.length; i++) {\r
VertexAttribute attribute = attributes[i];\r
return count;\r
}\r
\r
- private void checkValidity () {\r
+ private void checkValidity() {\r
boolean pos = false;\r
boolean cols = false;\r
boolean nors = false;\r
for (int i = 0; i < attributes.length; i++) {\r
VertexAttribute attribute = attributes[i];\r
if (attribute.usage == Usage.Position) {\r
- if (pos) throw new IllegalArgumentException("two position attributes were specified");\r
+ if (pos)\r
+ throw new IllegalArgumentException(\r
+ "two position attributes were specified");\r
pos = true;\r
}\r
\r
if (attribute.usage == Usage.Normal) {\r
- if (nors) throw new IllegalArgumentException("two normal attributes were specified");\r
+ if (nors)\r
+ throw new IllegalArgumentException(\r
+ "two normal attributes were specified");\r
}\r
\r
- if (attribute.usage == Usage.Color || attribute.usage == Usage.ColorPacked) {\r
- if (attribute.numComponents != 4) throw new IllegalArgumentException("color attribute must have 4 components");\r
+ if (attribute.usage == Usage.Color\r
+ || attribute.usage == Usage.ColorPacked) {\r
+ if (attribute.numComponents != 4)\r
+ throw new IllegalArgumentException(\r
+ "color attribute must have 4 components");\r
\r
- if (cols) throw new IllegalArgumentException("two color attributes were specified");\r
+ if (cols)\r
+ throw new IllegalArgumentException(\r
+ "two color attributes were specified");\r
cols = true;\r
}\r
}\r
\r
- if (pos == false) throw new IllegalArgumentException("no position attribute was specified");\r
+ if (pos == false)\r
+ throw new IllegalArgumentException(\r
+ "no position attribute was specified");\r
}\r
\r
/**\r
* @return the number of attributes\r
*/\r
- public int size () {\r
+ public int size() {\r
return attributes.length;\r
}\r
\r
/**\r
- * @param index the index\r
+ * @param index\r
+ * the index\r
* @return the VertexAttribute at the given index\r
*/\r
- public VertexAttribute get (int index) {\r
+ public VertexAttribute get(int index) {\r
return attributes[index];\r
}\r
}\r