[DEBUG] correct the display bug
This commit is contained in:
parent
438b8aeee4
commit
3664c311ef
12
.classpath
12
.classpath
@ -87,7 +87,17 @@
|
|||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/atriasoft-etk">
|
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/atriasoft-egami">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/atriasoft-etk">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/atriasoft-io-gami">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
@ -14,27 +14,22 @@ open module org.atriasoft.gale {
|
|||||||
exports org.atriasoft.gale.resource;
|
exports org.atriasoft.gale.resource;
|
||||||
|
|
||||||
requires transitive org.atriasoft.etk;
|
requires transitive org.atriasoft.etk;
|
||||||
|
requires transitive org.atriasoft.egami;
|
||||||
|
|
||||||
// requires transitive vecmath;
|
|
||||||
requires transitive org.lwjgl;
|
requires transitive org.lwjgl;
|
||||||
requires transitive org.lwjgl.natives;
|
requires transitive org.lwjgl.natives;
|
||||||
requires transitive org.lwjgl.glfw;
|
requires transitive org.lwjgl.glfw;
|
||||||
requires transitive org.lwjgl.glfw.natives;
|
requires transitive org.lwjgl.glfw.natives;
|
||||||
requires transitive org.lwjgl.assimp;
|
requires transitive org.lwjgl.assimp;
|
||||||
requires transitive org.lwjgl.assimp.natives;
|
requires transitive org.lwjgl.assimp.natives;
|
||||||
// requires transitive org.lwjgl.openal;
|
|
||||||
// requires transitive org.lwjgl.openal.natives;
|
|
||||||
requires transitive org.lwjgl.stb;
|
requires transitive org.lwjgl.stb;
|
||||||
requires transitive org.lwjgl.stb.natives;
|
requires transitive org.lwjgl.stb.natives;
|
||||||
requires transitive org.lwjgl.jawt;
|
requires transitive org.lwjgl.jawt;
|
||||||
// requires transitive org.lwjgl.opengl.awt;
|
|
||||||
requires transitive org.lwjgl.opengl;
|
requires transitive org.lwjgl.opengl;
|
||||||
requires transitive org.lwjgl.opengl.natives;
|
requires transitive org.lwjgl.opengl.natives;
|
||||||
// requires org.lwjgl.openvr;
|
|
||||||
|
|
||||||
// requires transitive jogamp.fat;
|
|
||||||
|
|
||||||
requires transitive java.desktop;
|
requires transitive java.desktop;
|
||||||
requires transitive pngdecoder;
|
requires transitive pngdecoder;
|
||||||
requires transitive lwjgl3.awt;
|
requires transitive lwjgl3.awt;
|
||||||
|
requires io.scenarium.logger;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class Application {
|
|||||||
private Uri iconName = null;
|
private Uri iconName = null;
|
||||||
private final Cursor cursor = Cursor.arrow;
|
private final Cursor cursor = Cursor.arrow;
|
||||||
private Orientation orientation = Orientation.screenAuto;
|
private Orientation orientation = Orientation.screenAuto;
|
||||||
Vector2f windowsSize = new Vector2f(800, 600);
|
private Vector2f windowsSize = new Vector2f(800, 600);
|
||||||
|
|
||||||
public Application() {
|
public Application() {
|
||||||
Log.verbose("Constructor Gale Application");
|
Log.verbose("Constructor Gale Application");
|
||||||
@ -286,6 +286,9 @@ public class Application {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public void setSize(final Vector2f size) {
|
public void setSize(final Vector2f size) {
|
||||||
|
if (size.x() <= 0 || size.y() <= 0) {
|
||||||
|
Log.error("Wrong windows size: " + size);
|
||||||
|
}
|
||||||
this.windowsSize = size;
|
this.windowsSize = size;
|
||||||
final Context context = Gale.getContext();
|
final Context context = Gale.getContext();
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
|
@ -1,282 +0,0 @@
|
|||||||
/** @file
|
|
||||||
* @author Edouard DUPIN
|
|
||||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
||||||
* @license MPL v2.0 (see license file)
|
|
||||||
*/
|
|
||||||
package org.atriasoft.gale;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.math.Vector2f;
|
|
||||||
import org.atriasoft.etk.math.Vector2i;
|
|
||||||
import org.atriasoft.gale.internal.Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* in the dimension class we store the data as the more usefull unit (pixel)
|
|
||||||
* but one case need to be dynamic the %, then when requested in % the register the % value
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("preview")
|
|
||||||
public record Dimension(
|
|
||||||
Vector2f size,
|
|
||||||
Distance type) {
|
|
||||||
public static final Dimension ZERO = new Dimension(Vector2f.ZERO, Distance.PIXEL);
|
|
||||||
private static Vector2f ratio = new Vector2f(9999999, 888888);
|
|
||||||
private static Vector2f invRatio = new Vector2f(1, 1);
|
|
||||||
private static Dimension windowsSize = new Dimension(Vector2f.MAX_VALUE, Distance.PIXEL);
|
|
||||||
|
|
||||||
public static final float INCH_TO_MILLIMETER = 1.0f / 25.4f;
|
|
||||||
public static final float FOOT_TO_MILLIMETER = 1.0f / 304.8f;
|
|
||||||
public static final float METER_TO_MILLIMETER = 1.0f / 1000.0f;
|
|
||||||
public static final float CENTIMETER_TO_MILLIMETER = 1.0f / 10.0f;
|
|
||||||
public static final float KILOMETER_TO_MILLIMETER = 1.0f / 1000000.0f;
|
|
||||||
public static final float MILLIMETER_TO_INCH = 25.4f;
|
|
||||||
public static final float MILLIMETER_TO_FOOT = 304.8f;
|
|
||||||
public static final float MILLIMETER_TO_METER = 1000.0f;
|
|
||||||
public static final float MILLIMETER_TO_CENTIMETER = 10.0f;
|
|
||||||
public static final float MILLIMETER_TO_KILOMETER = 1000000.0f;
|
|
||||||
/**
|
|
||||||
* basic init
|
|
||||||
*/
|
|
||||||
static {
|
|
||||||
final Dimension conversion = new Dimension(new Vector2f(72, 72), Distance.INCH);
|
|
||||||
ratio = conversion.getMillimeter();
|
|
||||||
invRatio = new Vector2f(1.0f / ratio.x(), 1.0f / ratio.y());
|
|
||||||
windowsSize = new Dimension(new Vector2f(200, 200), Distance.PIXEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the Windows diagonal size in the request unit
|
|
||||||
* @param type Unit type requested.
|
|
||||||
* @return the requested size
|
|
||||||
*/
|
|
||||||
public static float getWindowsDiag(final Distance type) {
|
|
||||||
final Vector2f size = getWindowsSize(type);
|
|
||||||
return size.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the Windows size in the request unit
|
|
||||||
* @param type Unit type requested.
|
|
||||||
* @return the requested size
|
|
||||||
*/
|
|
||||||
public static Vector2f getWindowsSize(final Distance type) {
|
|
||||||
return windowsSize.get(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the Milimeter ratio for calculation
|
|
||||||
* @param ratio Milimeter ration for the screen calculation interpolation
|
|
||||||
* @param type Unit type requested.
|
|
||||||
* @note: same as @ref setPixelPerInch (internal manage convertion)
|
|
||||||
*/
|
|
||||||
public static void setPixelRatio(final Vector2f ratio, final Distance type) {
|
|
||||||
Log.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
|
|
||||||
final Dimension conversion = new Dimension(ratio, type);
|
|
||||||
Log.info(" == > " + conversion);
|
|
||||||
Dimension.ratio = conversion.getMillimeter();
|
|
||||||
invRatio = new Vector2f(1.0f / Dimension.ratio.x(), 1.0f / Dimension.ratio.y());
|
|
||||||
Log.info("Set a new screen ratio for the screen : ratioMm=" + Dimension.ratio);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the current Windows size
|
|
||||||
* @param size size of the current windows in pixel.
|
|
||||||
*/
|
|
||||||
public static void setPixelWindowsSize(final Vector2f size) {
|
|
||||||
windowsSize = new Dimension(size);
|
|
||||||
Log.verbose("Set a new Windows property size " + windowsSize + "px");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor (default :0,0 mode pixel)
|
|
||||||
*/
|
|
||||||
public Dimension() {
|
|
||||||
this(Vector2f.ZERO, Distance.PIXEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
* @param size Requested dimension
|
|
||||||
*/
|
|
||||||
public Dimension(final Vector2f size) {
|
|
||||||
this(size, Distance.PIXEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dimension(final Vector2f size, final Distance type) {
|
|
||||||
this.size = size;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in requested type
|
|
||||||
* @param type Type of unit requested.
|
|
||||||
* @return dimension requested.
|
|
||||||
*/
|
|
||||||
public Vector2f get(final Distance type) {
|
|
||||||
return switch (type) {
|
|
||||||
case POURCENT -> getPourcent();
|
|
||||||
case PIXEL -> getPixel();
|
|
||||||
case METER -> getMeter();
|
|
||||||
case CENTIMETER -> getCentimeter();
|
|
||||||
case MILLIMETER -> getMillimeter();
|
|
||||||
case KILOMETER -> getKilometer();
|
|
||||||
case INCH -> getInch();
|
|
||||||
case FOOT -> getFoot();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in Centimeter
|
|
||||||
* @return dimension in Centimeter
|
|
||||||
*/
|
|
||||||
public Vector2f getCentimeter() {
|
|
||||||
return getMillimeter().multiply(MILLIMETER_TO_CENTIMETER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in Foot
|
|
||||||
* @return dimension in Foot
|
|
||||||
*/
|
|
||||||
public Vector2f getFoot() {
|
|
||||||
return getMillimeter().multiply(MILLIMETER_TO_FOOT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in Inch
|
|
||||||
* @return dimension in Inch
|
|
||||||
*/
|
|
||||||
public Vector2f getInch() {
|
|
||||||
return getMillimeter().multiply(MILLIMETER_TO_INCH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in Kilometer
|
|
||||||
* @return dimension in Kilometer
|
|
||||||
*/
|
|
||||||
public Vector2f getKilometer() {
|
|
||||||
return getMillimeter().multiply(MILLIMETER_TO_KILOMETER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in Meter
|
|
||||||
* @return dimension in Meter
|
|
||||||
*/
|
|
||||||
public Vector2f getMeter() {
|
|
||||||
return getMillimeter().multiply(MILLIMETER_TO_METER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in Millimeter
|
|
||||||
* @return dimension in Millimeter
|
|
||||||
*/
|
|
||||||
public Vector2f getMillimeter() {
|
|
||||||
return new Vector2f(getPixel().x() * invRatio.x(), getPixel().y() * invRatio.y());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in pixel
|
|
||||||
* @return dimension in Pixel
|
|
||||||
*/
|
|
||||||
public Vector2f getPixel() {
|
|
||||||
if (this.type != Distance.POURCENT) {
|
|
||||||
return this.size;
|
|
||||||
}
|
|
||||||
final Vector2f windDim = windowsSize.getPixel();
|
|
||||||
final Vector2f res = new Vector2f(windDim.x() * this.size.x(), windDim.y() * this.size.y());
|
|
||||||
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2i getPixeli() {
|
|
||||||
if (this.type != Distance.POURCENT) {
|
|
||||||
return new Vector2i((int) this.size.x(), (int) this.size.y());
|
|
||||||
}
|
|
||||||
final Vector2f windDim = windowsSize.getPixel();
|
|
||||||
final Vector2i res = new Vector2i((int) (windDim.x() * this.size.x()), (int) (windDim.y() * this.size.y()));
|
|
||||||
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the current dimension in Pourcent
|
|
||||||
* @return dimension in Pourcent
|
|
||||||
*/
|
|
||||||
public Vector2f getPourcent() {
|
|
||||||
if (this.type != Distance.POURCENT) {
|
|
||||||
final Vector2f windDim = windowsSize.getPixel();
|
|
||||||
//GALE_DEBUG(" windows dimension : " /*+ windowsSize*/ + " == > " + windDim + "px"); // ==> infinite loop ...
|
|
||||||
//printf(" windows dimension : %f,%f", windDim.x(),windDim.y());
|
|
||||||
//printf(" data : %f,%f", m_data.x(),m_data.y());
|
|
||||||
return new Vector2f((this.size.x() / windDim.x()) * 100.0f, (this.size.y() / windDim.y()) * 100.0f);
|
|
||||||
}
|
|
||||||
return new Vector2f(this.size.x() * 100.0f, this.size.y() * 100.0f);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the dimension type
|
|
||||||
* @return the type
|
|
||||||
*/
|
|
||||||
public Distance getType() {
|
|
||||||
return this.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the current dimension in requested type
|
|
||||||
* @param config dimension configuration.
|
|
||||||
*/
|
|
||||||
public static Dimension valueOf(String config) {
|
|
||||||
final Vector2f size = Vector2f.ZERO;
|
|
||||||
Distance type = Distance.PIXEL;
|
|
||||||
if (config.endsWith("%")) {
|
|
||||||
type = Distance.POURCENT;
|
|
||||||
config = config.substring(0, config.length() - 1);
|
|
||||||
} else if (config.endsWith("px")) {
|
|
||||||
type = Distance.PIXEL;
|
|
||||||
config = config.substring(0, config.length() - 2);
|
|
||||||
} else if (config.endsWith("ft")) {
|
|
||||||
type = Distance.FOOT;
|
|
||||||
config = config.substring(0, config.length() - 2);
|
|
||||||
} else if (config.endsWith("in")) {
|
|
||||||
type = Distance.INCH;
|
|
||||||
config = config.substring(0, config.length() - 2);
|
|
||||||
} else if (config.endsWith("km")) {
|
|
||||||
type = Distance.KILOMETER;
|
|
||||||
config = config.substring(0, config.length() - 2);
|
|
||||||
} else if (config.endsWith("mm")) {
|
|
||||||
type = Distance.MILLIMETER;
|
|
||||||
config = config.substring(0, config.length() - 2);
|
|
||||||
} else if (config.endsWith("cm")) {
|
|
||||||
type = Distance.CENTIMETER;
|
|
||||||
config = config.substring(0, config.length() - 2);
|
|
||||||
} else if (config.endsWith("m")) {
|
|
||||||
type = Distance.METER;
|
|
||||||
config = config.substring(0, config.length() - 1);
|
|
||||||
} else {
|
|
||||||
Log.critical("Can not parse dimension : '" + config + "'");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final Vector2f tmp = Vector2f.valueOf(config);
|
|
||||||
final Dimension ret = new Dimension(tmp, type);
|
|
||||||
Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* string cast :
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String str = get(getType()).toString();
|
|
||||||
switch (getType()) {
|
|
||||||
case POURCENT -> str += "%";
|
|
||||||
case PIXEL -> str += "px";
|
|
||||||
case METER -> str += "m";
|
|
||||||
case CENTIMETER -> str += "cm";
|
|
||||||
case MILLIMETER -> str += "mm";
|
|
||||||
case KILOMETER -> str += "km";
|
|
||||||
case INCH -> str += "in";
|
|
||||||
case FOOT -> str += "ft";
|
|
||||||
default -> str += "";
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package org.atriasoft.gale;
|
|
||||||
|
|
||||||
public enum Distance {
|
|
||||||
POURCENT,
|
|
||||||
PIXEL,
|
|
||||||
METER,
|
|
||||||
CENTIMETER,
|
|
||||||
MILLIMETER,
|
|
||||||
KILOMETER,
|
|
||||||
INCH,
|
|
||||||
FOOT;
|
|
||||||
}
|
|
@ -41,9 +41,7 @@ public class OpenGL {
|
|||||||
|
|
||||||
// We map all the flag, but not all is supported by all platform...
|
// We map all the flag, but not all is supported by all platform...
|
||||||
public static enum Flag {
|
public static enum Flag {
|
||||||
flag_blend, // !< If enabled, blend the computed fragment color values with the values in
|
flag_blend, // !< If enabled, blend the computed fragment color values with the values in the color buffers. See glBlendFunc.
|
||||||
// the color buffers.
|
|
||||||
// See glBlendFunc.
|
|
||||||
flag_clipDistanceI, // !< If enabled, clip geometry against user-defined half space i.
|
flag_clipDistanceI, // !< If enabled, clip geometry against user-defined half space i.
|
||||||
flag_colorLogigOP, // !< If enabled, apply the currently selected logical operation to the computed
|
flag_colorLogigOP, // !< If enabled, apply the currently selected logical operation to the computed
|
||||||
// fragment color and color buffer values. See glLogicOp.
|
// fragment color and color buffer values. See glLogicOp.
|
||||||
@ -62,10 +60,8 @@ public class OpenGL {
|
|||||||
// glDepthRange.
|
// glDepthRange.
|
||||||
flag_depthTest, // !< If enabled, do depth comparisons and update the depth buffer. Note that
|
flag_depthTest, // !< If enabled, do depth comparisons and update the depth buffer. Note that
|
||||||
// even if the depth buffer exists and the depth mask is non-zero, the depth
|
// even if the depth buffer exists and the depth mask is non-zero, the depth
|
||||||
// buffer is not updated if the depth test is disabled. See glDepthFunc and
|
// buffer is not updated if the depth test is disabled. See glDepthFunc and glDepthRange.
|
||||||
// glDepthRange.
|
flag_dither, // !< If enabled, dither color components or indices before they are written to the color buffer.
|
||||||
flag_dither, // !< If enabled, dither color components or indices before they are written to
|
|
||||||
// the color buffer.
|
|
||||||
flag_framebufferSRGB, // !< If enabled and the value of GLFRAMEBUFFERATTACHMENTCOLORENCODING for the
|
flag_framebufferSRGB, // !< If enabled and the value of GLFRAMEBUFFERATTACHMENTCOLORENCODING for the
|
||||||
// framebuffer attachment corresponding to the destination buffer is GLSRGB, the
|
// framebuffer attachment corresponding to the destination buffer is GLSRGB, the
|
||||||
// R, G, and B destination color values (after conversion from fixed-point to
|
// R, G, and B destination color values (after conversion from fixed-point to
|
||||||
@ -438,6 +434,10 @@ public class OpenGL {
|
|||||||
GL11.glDrawElements(CONVERT_RENDER_MODE.get(mode), vertexCount, GL11.GL_UNSIGNED_INT, 0);
|
GL11.glDrawElements(CONVERT_RENDER_MODE.get(mode), vertexCount, GL11.GL_UNSIGNED_INT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void drawTriangleRed(final Vector3f aaa, final Vector3f bbb, final Vector3f ccc) {
|
||||||
|
GL11.glFinish();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enable a flag on the system
|
* enable a flag on the system
|
||||||
* @param flagID The flag requested
|
* @param flagID The flag requested
|
||||||
@ -526,7 +526,11 @@ public class OpenGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void glTexImage2D(final int level, final int internalFormat, final int width, final int height, final int border, final int format, final int sizeObject, final byte[] data) {
|
public static void glTexImage2D(final int level, final int internalFormat, final int width, final int height, final int border, final int format, final int sizeObject, final byte[] data) {
|
||||||
final ByteBuffer dataBuffer = ByteBuffer.wrap(data);
|
final ByteBuffer dataBuffer = ByteBuffer.allocateDirect(data.length);
|
||||||
|
for (int iii = 0; iii < data.length; iii++) {
|
||||||
|
dataBuffer.put(data[iii]);
|
||||||
|
}
|
||||||
|
dataBuffer.flip();
|
||||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, internalFormat, width, height, border, format, sizeObject, dataBuffer);
|
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, internalFormat, width, height, border, format, sizeObject, dataBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,7 +539,11 @@ public class OpenGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void glTexSubImage2D(final int level, final int xOffset, final int yOffset, final int width, final int height, final int format, final int sizeObject, final byte[] data) {
|
public static void glTexSubImage2D(final int level, final int xOffset, final int yOffset, final int width, final int height, final int format, final int sizeObject, final byte[] data) {
|
||||||
final ByteBuffer dataBuffer = ByteBuffer.wrap(data);
|
final ByteBuffer dataBuffer = ByteBuffer.allocateDirect(data.length);
|
||||||
|
for (int iii = 0; iii < data.length; iii++) {
|
||||||
|
dataBuffer.put(data[iii]);
|
||||||
|
}
|
||||||
|
dataBuffer.flip();
|
||||||
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, level, xOffset, yOffset, width, height, format, sizeObject, dataBuffer);
|
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, level, xOffset, yOffset, width, height, format, sizeObject, dataBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public abstract class Context {
|
|||||||
private final Fps fpsSystemContext = new Fps("SystemContext", this.displayFps);
|
private final Fps fpsSystemContext = new Fps("SystemContext", this.displayFps);
|
||||||
private final Fps fpsSystem = new Fps("System", this.displayFps);
|
private final Fps fpsSystem = new Fps("System", this.displayFps);
|
||||||
private final Fps fpsFlush = new Fps("Flush", this.displayFps);
|
private final Fps fpsFlush = new Fps("Flush", this.displayFps);
|
||||||
protected Vector2f windowsSize = new Vector2f(0, 0); //!< current size of the system
|
protected Vector2f windowsSize = Vector2f.ZERO; //!< current size of the system
|
||||||
protected boolean fullscreen = false;
|
protected boolean fullscreen = false;
|
||||||
protected Vector2f windowsPos; //!< current size of the system
|
protected Vector2f windowsPos; //!< current size of the system
|
||||||
|
|
||||||
@ -155,6 +155,9 @@ public abstract class Context {
|
|||||||
if (this.application == null) {
|
if (this.application == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.windowsSize == Vector2f.ZERO) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.application.onResize(this.windowsSize);
|
this.application.onResize(this.windowsSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,6 +618,7 @@ public abstract class Context {
|
|||||||
* Processing all the event arrived ... (commoly called in draw function)
|
* Processing all the event arrived ... (commoly called in draw function)
|
||||||
*/
|
*/
|
||||||
public void processEvents() {
|
public void processEvents() {
|
||||||
|
try {
|
||||||
int nbEvent = 0;
|
int nbEvent = 0;
|
||||||
//Log.debug(" ******** Event " << this.msgSystem.count());
|
//Log.debug(" ******** Event " << this.msgSystem.count());
|
||||||
while (this.msgSystem.size() > 0) {
|
while (this.msgSystem.size() > 0) {
|
||||||
@ -626,6 +630,9 @@ public abstract class Context {
|
|||||||
}
|
}
|
||||||
func.run(this);
|
func.run(this);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.critical("Catch exception in main event Loop ...", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// gale::Context::~Context() {
|
// gale::Context::~Context() {
|
||||||
|
@ -26,6 +26,8 @@ import java.util.List;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
import io.scenarium.logger.Logger;
|
||||||
|
|
||||||
import org.atriasoft.etk.Uri;
|
import org.atriasoft.etk.Uri;
|
||||||
import org.atriasoft.etk.math.Vector2f;
|
import org.atriasoft.etk.math.Vector2f;
|
||||||
import org.atriasoft.gale.Application;
|
import org.atriasoft.gale.Application;
|
||||||
@ -173,6 +175,9 @@ public class ContextLWJGLAWT extends Context implements MouseListener, MouseMoti
|
|||||||
}
|
}
|
||||||
operatingSystemDraw(true);
|
operatingSystemDraw(true);
|
||||||
swapBuffers();
|
swapBuffers();
|
||||||
|
if (Logger.isCriticalOccured()) {
|
||||||
|
ContextLWJGLAWT.this.frame.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, BorderLayout.CENTER);
|
}, BorderLayout.CENTER);
|
||||||
this.frame.pack();
|
this.frame.pack();
|
||||||
|
@ -15,46 +15,61 @@ public class Log {
|
|||||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||||
|
|
||||||
private Log() {}
|
public static void critical(final String data) {
|
||||||
|
if (PRINT_CRITICAL) {
|
||||||
public static void print(String data) {
|
|
||||||
if (PRINT_PRINT)
|
|
||||||
Logger.print(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void todo(String data) {
|
|
||||||
if (PRINT_TODO)
|
|
||||||
Logger.todo(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void critical(String data) {
|
|
||||||
if (PRINT_CRITICAL)
|
|
||||||
Logger.critical(LIB_NAME_DRAW, data);
|
Logger.critical(LIB_NAME_DRAW, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(String data) {
|
|
||||||
if (PRINT_ERROR)
|
|
||||||
Logger.error(LIB_NAME_DRAW, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(String data) {
|
public static void critical(final String data, final Exception e) {
|
||||||
if (PRINT_WARNING)
|
e.printStackTrace();
|
||||||
Logger.warning(LIB_NAME_DRAW, data);
|
if (PRINT_CRITICAL) {
|
||||||
|
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(String data) {
|
public static void debug(final String data) {
|
||||||
if (PRINT_INFO)
|
if (PRINT_DEBUG) {
|
||||||
Logger.info(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void debug(String data) {
|
|
||||||
if (PRINT_DEBUG)
|
|
||||||
Logger.debug(LIB_NAME_DRAW, data);
|
Logger.debug(LIB_NAME_DRAW, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void verbose(String data) {
|
|
||||||
if (PRINT_VERBOSE)
|
|
||||||
Logger.verbose(LIB_NAME_DRAW, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void error(final String data) {
|
||||||
|
if (PRINT_ERROR) {
|
||||||
|
Logger.error(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(final String data) {
|
||||||
|
if (PRINT_INFO) {
|
||||||
|
Logger.info(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void print(final String data) {
|
||||||
|
if (PRINT_PRINT) {
|
||||||
|
Logger.print(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void todo(final String data) {
|
||||||
|
if (PRINT_TODO) {
|
||||||
|
Logger.todo(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void verbose(final String data) {
|
||||||
|
if (PRINT_VERBOSE) {
|
||||||
|
Logger.verbose(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(final String data) {
|
||||||
|
if (PRINT_WARNING) {
|
||||||
|
Logger.warning(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Log() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,8 @@ public class ResourceManager {
|
|||||||
* Call by the system to send all the needed data on the graphic card chen they change ...
|
* Call by the system to send all the needed data on the graphic card chen they change ...
|
||||||
* @param object The resources that might be updated
|
* @param object The resources that might be updated
|
||||||
*/
|
*/
|
||||||
public synchronized void update(final Resource object) {
|
public void update(final Resource object) {
|
||||||
|
synchronized (this.resourceListToUpdate) {
|
||||||
// check if not added before
|
// check if not added before
|
||||||
for (final Resource it : this.resourceListToUpdate) {
|
for (final Resource it : this.resourceListToUpdate) {
|
||||||
if (it == object) {
|
if (it == object) {
|
||||||
@ -152,11 +153,12 @@ public class ResourceManager {
|
|||||||
// add it ...
|
// add it ...
|
||||||
this.resourceListToUpdate.add(object);
|
this.resourceListToUpdate.add(object);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other ....
|
* Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other ....
|
||||||
*/
|
*/
|
||||||
public synchronized void updateContext() {
|
public void updateContext() {
|
||||||
if (this.exiting) {
|
if (this.exiting) {
|
||||||
Log.error("Request update after application EXIT ...");
|
Log.error("Request update after application EXIT ...");
|
||||||
return;
|
return;
|
||||||
@ -165,7 +167,9 @@ public class ResourceManager {
|
|||||||
if (this.contextHasBeenRemoved) {
|
if (this.contextHasBeenRemoved) {
|
||||||
// need to update all ...
|
// need to update all ...
|
||||||
this.contextHasBeenRemoved = false;
|
this.contextHasBeenRemoved = false;
|
||||||
|
synchronized (this.resourceListToUpdate) {
|
||||||
this.resourceListToUpdate.clear();
|
this.resourceListToUpdate.clear();
|
||||||
|
}
|
||||||
synchronized (this.resourceList) {
|
synchronized (this.resourceList) {
|
||||||
if (this.resourceList.size() != 0) {
|
if (this.resourceList.size() != 0) {
|
||||||
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) {
|
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) {
|
||||||
@ -175,6 +179,7 @@ public class ResourceManager {
|
|||||||
//Log.debug("Update context named : " + lresourceList[iii].getName());
|
//Log.debug("Update context named : " + lresourceList[iii].getName());
|
||||||
if (!it.updateContext()) {
|
if (!it.updateContext()) {
|
||||||
// Lock error ==> postponned
|
// Lock error ==> postponned
|
||||||
|
synchronized (this.resourceListToUpdate) {
|
||||||
this.resourceListToUpdate.add(it);
|
this.resourceListToUpdate.add(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,6 +187,7 @@ public class ResourceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
List<Resource> resourceListToUpdate = null;
|
List<Resource> resourceListToUpdate = null;
|
||||||
synchronized (this.resourceListToUpdate) {
|
synchronized (this.resourceListToUpdate) {
|
||||||
|
@ -205,12 +205,10 @@ public class ResourceProgram extends Resource {
|
|||||||
tmp.elementId = OpenGL.programGetAttributeLocation(this.program, tmp.name);
|
tmp.elementId = OpenGL.programGetAttributeLocation(this.program, tmp.name);
|
||||||
tmp.isLinked = true;
|
tmp.isLinked = true;
|
||||||
if (tmp.elementId < 0) {
|
if (tmp.elementId < 0) {
|
||||||
Log.warning(" {" + this.program + "}[" + this.elementList.size() + "] glGetAttribLocation(\""
|
Log.warning(" {" + this.program + "}[" + this.elementList.size() + "] glGetAttribLocation(\"" + tmp.name + "\") = " + tmp.elementId);
|
||||||
+ tmp.name + "\") = " + tmp.elementId);
|
|
||||||
tmp.isLinked = false;
|
tmp.isLinked = false;
|
||||||
} else {
|
} else {
|
||||||
Log.debug(" {" + this.program + "}[" + this.elementList.size() + "] glGetAttribLocation(\""
|
Log.debug(" {" + this.program + "}[" + this.elementList.size() + "] glGetAttribLocation(\"" + tmp.name + "\") = " + tmp.elementId);
|
||||||
+ tmp.name + "\") = " + tmp.elementId);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// program is not loaded ==> just local reister ...
|
// program is not loaded ==> just local reister ...
|
||||||
@ -253,12 +251,10 @@ public class ResourceProgram extends Resource {
|
|||||||
tmp.elementId = OpenGL.programGetUniformLocation(this.program, tmp.name);
|
tmp.elementId = OpenGL.programGetUniformLocation(this.program, tmp.name);
|
||||||
tmp.isLinked = true;
|
tmp.isLinked = true;
|
||||||
if (tmp.elementId < 0) {
|
if (tmp.elementId < 0) {
|
||||||
Log.warning(" {" + this.program + "}[" + this.elementList.size() + "] glGetUniformLocation(\""
|
Log.warning(" {" + this.program + "}[" + this.elementList.size() + "] glGetUniformLocation(\"" + tmp.name + "\") = " + tmp.elementId);
|
||||||
+ tmp.name + "\") = " + tmp.elementId);
|
|
||||||
tmp.isLinked = false;
|
tmp.isLinked = false;
|
||||||
} else {
|
} else {
|
||||||
Log.debug(" {" + this.program + "}[" + this.elementList.size() + "] glGetUniformLocation(\""
|
Log.debug(" {" + this.program + "}[" + this.elementList.size() + "] glGetUniformLocation(\"" + tmp.name + "\") = " + tmp.elementId);
|
||||||
+ tmp.name + "\") = " + tmp.elementId);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// program is not loaded ==> just local reister ...
|
// program is not loaded ==> just local reister ...
|
||||||
@ -367,8 +363,7 @@ public class ResourceProgram extends Resource {
|
|||||||
// public void sendAttribute(int idElem, List<Vector3f> data) {
|
// public void sendAttribute(int idElem, List<Vector3f> data) {
|
||||||
// sendAttribute3fv(idElem, convertInFloat(data));
|
// sendAttribute3fv(idElem, convertInFloat(data));
|
||||||
// }
|
// }
|
||||||
public void sendAttribute(final int idElem, final int nbElement, final FloatBuffer data,
|
public void sendAttribute(final int idElem, final int nbElement, final FloatBuffer data, final int jumpBetweenSample) {
|
||||||
final int jumpBetweenSample) {
|
|
||||||
if (!this.exist) {
|
if (!this.exist) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -382,8 +377,7 @@ public class ResourceProgram extends Resource {
|
|||||||
// GL40.glBindVertexArray(this.elementList.get(idElem).elementId);
|
// GL40.glBindVertexArray(this.elementList.get(idElem).elementId);
|
||||||
// Log.error("[" + this.elementList.get(idElem).name + "] send " + 3 + "
|
// Log.error("[" + this.elementList.get(idElem).name + "] send " + 3 + "
|
||||||
// element");
|
// element");
|
||||||
GL40.glVertexAttribPointer(this.elementList.get(idElem).elementId, nbElement, GL40.GL_FLOAT, false,
|
GL40.glVertexAttribPointer(this.elementList.get(idElem).elementId, nbElement, GL40.GL_FLOAT, false, jumpBetweenSample * 4, /* 4 is the size of float in the generic system... */
|
||||||
jumpBetweenSample * 4, /* 4 is the size of float in the generic system... */
|
|
||||||
data);
|
data);
|
||||||
// checkGlError("glVertexAttribPointer", LINE, idElem);
|
// checkGlError("glVertexAttribPointer", LINE, idElem);
|
||||||
GL40.glEnableVertexAttribArray(this.elementList.get(idElem).elementId);
|
GL40.glEnableVertexAttribArray(this.elementList.get(idElem).elementId);
|
||||||
@ -449,8 +443,7 @@ public class ResourceProgram extends Resource {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.verbose("[" + this.elementList.get(idElem).name + "] send on oglID=" + vbo.getOpenGlId(index) + " VBOindex="
|
Log.verbose("[" + this.elementList.get(idElem).name + "] send on oglID=" + vbo.getOpenGlId(index) + " VBOindex=" + index);
|
||||||
+ index);
|
|
||||||
GL20.glBindBuffer(GL20.GL_ARRAY_BUFFER, vbo.getOpenGlId(index));
|
GL20.glBindBuffer(GL20.GL_ARRAY_BUFFER, vbo.getOpenGlId(index));
|
||||||
// checkGlError("glBindBuffer", __LINE__, _idElem);
|
// checkGlError("glBindBuffer", __LINE__, _idElem);
|
||||||
Log.verbose(" id=" + this.elementList.get(idElem).elementId);
|
Log.verbose(" id=" + this.elementList.get(idElem).elementId);
|
||||||
@ -597,8 +590,7 @@ public class ResourceProgram extends Resource {
|
|||||||
* @param value3 Value to send at the Uniform
|
* @param value3 Value to send at the Uniform
|
||||||
* @param value4 Value to send at the Uniform
|
* @param value4 Value to send at the Uniform
|
||||||
*/
|
*/
|
||||||
public void uniformFloat(final int idElem, final float value1, final float value2, final float value3,
|
public void uniformFloat(final int idElem, final float value1, final float value2, final float value3, final float value4) {
|
||||||
final float value4) {
|
|
||||||
|
|
||||||
if (!this.exist) {
|
if (!this.exist) {
|
||||||
return;
|
return;
|
||||||
@ -836,8 +828,7 @@ public class ResourceProgram extends Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_POSITIONS, "in_position");
|
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_POSITIONS, "in_position");
|
||||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_TEXTURE_COORDINATES,
|
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_TEXTURE_COORDINATES, "tin_extureCoords");
|
||||||
"tin_extureCoords");
|
|
||||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_NORMALS, "in_normal");
|
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_NORMALS, "in_normal");
|
||||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_COLORS, "in_colors");
|
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_COLORS, "in_colors");
|
||||||
|
|
||||||
@ -853,23 +844,19 @@ public class ResourceProgram extends Resource {
|
|||||||
it.elementId = OpenGL.programGetAttributeLocation(this.program, it.name);
|
it.elementId = OpenGL.programGetAttributeLocation(this.program, it.name);
|
||||||
it.isLinked = true;
|
it.isLinked = true;
|
||||||
if (it.elementId < 0) {
|
if (it.elementId < 0) {
|
||||||
Log.warning(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name
|
Log.warning(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name + "\") = " + it.elementId);
|
||||||
+ "\") = " + it.elementId);
|
|
||||||
it.isLinked = false;
|
it.isLinked = false;
|
||||||
} else {
|
} else {
|
||||||
Log.debug(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name
|
Log.debug(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name + "\") = " + it.elementId);
|
||||||
+ "\") = " + it.elementId);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
it.elementId = OpenGL.programGetUniformLocation(this.program, it.name);
|
it.elementId = OpenGL.programGetUniformLocation(this.program, it.name);
|
||||||
it.isLinked = true;
|
it.isLinked = true;
|
||||||
if (it.elementId < 0) {
|
if (it.elementId < 0) {
|
||||||
Log.warning(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name
|
Log.warning(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name + "\") = " + it.elementId);
|
||||||
+ "\") = " + it.elementId);
|
|
||||||
it.isLinked = false;
|
it.isLinked = false;
|
||||||
} else {
|
} else {
|
||||||
Log.debug(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name
|
Log.debug(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name + "\") = " + it.elementId);
|
||||||
+ "\") = " + it.elementId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iii++;
|
iii++;
|
||||||
|
@ -2,8 +2,8 @@ package org.atriasoft.gale.resource;
|
|||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
import org.atriasoft.egami.Image;
|
||||||
import org.atriasoft.etk.Uri;
|
import org.atriasoft.etk.Uri;
|
||||||
import org.atriasoft.etk.math.Vector2f;
|
|
||||||
import org.atriasoft.etk.math.Vector2i;
|
import org.atriasoft.etk.math.Vector2i;
|
||||||
import org.atriasoft.gale.backend3d.OpenGL;
|
import org.atriasoft.gale.backend3d.OpenGL;
|
||||||
import org.atriasoft.gale.internal.Log;
|
import org.atriasoft.gale.internal.Log;
|
||||||
@ -48,8 +48,30 @@ public class ResourceTexture extends Resource {
|
|||||||
}
|
}
|
||||||
resource = new ResourceTexture(uriTexture, textureUnit);
|
resource = new ResourceTexture(uriTexture, textureUnit);
|
||||||
final ImageRawData decodedData = ImageLoader.decodePngFile(uriTexture);
|
final ImageRawData decodedData = ImageLoader.decodePngFile(uriTexture);
|
||||||
resource.setTexture(decodedData.getBuffer(), new Vector2i(decodedData.getWidth(), decodedData.getHeight()), (decodedData.isHasAlpha() ? TextureColorMode.rgba : TextureColorMode.rgb),
|
Image img = new Image(decodedData.getWidth(), decodedData.getHeight());
|
||||||
textureUnit);
|
ByteBuffer mlklmklm = decodedData.getBuffer();
|
||||||
|
byte[] elemData = new byte[mlklmklm.remaining()];
|
||||||
|
mlklmklm.get(elemData);
|
||||||
|
if (decodedData.isHasAlpha()) {
|
||||||
|
for (int yyy = 0; yyy < decodedData.getHeight(); yyy++) {
|
||||||
|
for (int xxx = 0; xxx < decodedData.getWidth(); xxx++) {
|
||||||
|
img.setR(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 4 + 0]);
|
||||||
|
img.setG(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 4 + 1]);
|
||||||
|
img.setB(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 4 + 2]);
|
||||||
|
img.setA(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 4 + 3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int yyy = 0; yyy < decodedData.getHeight(); yyy++) {
|
||||||
|
for (int xxx = 0; xxx < decodedData.getWidth(); xxx++) {
|
||||||
|
img.setA(xxx, yyy, 0xFF);
|
||||||
|
img.setR(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 3 + 0]);
|
||||||
|
img.setG(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 3 + 1]);
|
||||||
|
img.setB(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 3 + 2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resource.setTexture(img, new Vector2i(decodedData.getWidth(), decodedData.getHeight()), (decodedData.isHasAlpha() ? TextureColorMode.rgba : TextureColorMode.rgb), textureUnit);
|
||||||
resource.flush();
|
resource.flush();
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
@ -73,34 +95,26 @@ public class ResourceTexture extends Resource {
|
|||||||
|
|
||||||
protected int texId = -1; //!< openGl textureID.
|
protected int texId = -1; //!< openGl textureID.
|
||||||
// some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 . 1.0.
|
// some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 . 1.0.
|
||||||
protected Vector2f endPointSize = new Vector2f(-1, -1);
|
protected Vector2i endPointSize = new Vector2i(-1, -1);
|
||||||
// internal state of the openGl system.
|
// internal state of the openGl system.
|
||||||
protected boolean loaded = false;
|
protected boolean loaded = false;
|
||||||
// Image properties:
|
// Image properties:
|
||||||
// pointer on the image data.
|
// pointer on the image data.
|
||||||
private ByteBuffer data = null;
|
//private ByteBuffer data = null;
|
||||||
|
protected Image data = new Image(32, 32);
|
||||||
// size of the image data.
|
// size of the image data.
|
||||||
private Vector2i size = new Vector2i(-1, -1);
|
private Vector2i size = new Vector2i(-1, -1);
|
||||||
//!< Color space of the image.
|
//!< Color space of the image.
|
||||||
private TextureColorMode dataColorSpace = TextureColorMode.rgb;
|
private TextureColorMode dataColorSpace = TextureColorMode.rgb;
|
||||||
// number of lines and colomns in the texture (multiple texturing in a single texture)
|
// number of lines and colomns in the texture (multiple texturing in a single texture)
|
||||||
private int textureUnit = 0;
|
private int textureUnit = 0;
|
||||||
private String filename = "";
|
|
||||||
|
|
||||||
protected ResourceTexture() {
|
protected ResourceTexture() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public API:
|
|
||||||
protected ResourceTexture(final String filename, final int textureUnit) {
|
|
||||||
super(filename + "__" + textureUnit);
|
|
||||||
this.filename = filename;
|
|
||||||
this.textureUnit = textureUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ResourceTexture(final Uri filename, final int textureUnit) {
|
protected ResourceTexture(final Uri filename, final int textureUnit) {
|
||||||
super(filename + "__" + textureUnit);
|
super(filename.toString() + "__" + textureUnit);
|
||||||
this.filename = filename.get();
|
|
||||||
this.textureUnit = textureUnit;
|
this.textureUnit = textureUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +150,7 @@ public class ResourceTexture extends Resource {
|
|||||||
return this.texId;
|
return this.texId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2f getUsableSize() {
|
public Vector2i getUsableSize() {
|
||||||
return this.endPointSize;
|
return this.endPointSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,11 +171,11 @@ public class ResourceTexture extends Resource {
|
|||||||
this.texId = -1;
|
this.texId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTexture(final ByteBuffer data, final Vector2i size, final TextureColorMode dataColorSpace, final int textureUnit) {
|
public void setTexture(final Image data, final Vector2i size, final TextureColorMode dataColorSpace, final int textureUnit) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.textureUnit = textureUnit;
|
this.textureUnit = textureUnit;
|
||||||
this.endPointSize = new Vector2f(size.x(), size.y());
|
this.endPointSize = new Vector2i(size.x(), size.y());
|
||||||
this.dataColorSpace = dataColorSpace;
|
this.dataColorSpace = dataColorSpace;
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
@ -191,9 +205,11 @@ public class ResourceTexture extends Resource {
|
|||||||
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
||||||
Log.info("TEXTURE: add [" + getId() + "]=" + this.size + " OGlId=" + this.texId);
|
Log.info("TEXTURE: add [" + getId() + "]=" + this.size + " OGlId=" + this.texId);
|
||||||
if (this.dataColorSpace == TextureColorMode.rgb) {
|
if (this.dataColorSpace == TextureColorMode.rgb) {
|
||||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, this.data);
|
OpenGL.glTexImage2D(0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.data.getRaw());
|
||||||
|
//The local image has not RGB but only RGBA data ...
|
||||||
|
//OpenGL.glTexImage2D(0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, this.data.getRaw());
|
||||||
} else {
|
} else {
|
||||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.data);
|
OpenGL.glTexImage2D(0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.data.getRaw());
|
||||||
}
|
}
|
||||||
// generate multi-texture mapping
|
// generate multi-texture mapping
|
||||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||||
|
@ -172,7 +172,7 @@ public class ResourceVirtualBufferObject extends Resource {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean updateContext() {
|
public synchronized boolean updateContext() {
|
||||||
Log.verbose(" Start: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.length + ")");
|
Log.warning("updateContext (VBO Start: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.length + ")");
|
||||||
/*
|
/*
|
||||||
if (lock.tryLock() == false) {
|
if (lock.tryLock() == false) {
|
||||||
//Lock error ==> try later ...
|
//Lock error ==> try later ...
|
||||||
@ -187,8 +187,8 @@ public class ResourceVirtualBufferObject extends Resource {
|
|||||||
}
|
}
|
||||||
this.exist = true;
|
this.exist = true;
|
||||||
for (int iii = 0; iii < this.vbo.length; iii++) {
|
for (int iii = 0; iii < this.vbo.length; iii++) {
|
||||||
Log.verbose("VBO : add [" + getId() + "]=" + this.buffer[iii].getClass().getCanonicalName() + "*sizeof(float) OGl_Id=" + this.vbo[iii]);
|
|
||||||
if (this.buffer[iii] != null) {
|
if (this.buffer[iii] != null) {
|
||||||
|
Log.verbose("VBO : add [" + getId() + "]=" + this.buffer[iii].getClass().getCanonicalName() + "*sizeof(float) OGl_Id=" + this.vbo[iii]);
|
||||||
OpenGL.bindBuffer(this.vbo[iii]);
|
OpenGL.bindBuffer(this.vbo[iii]);
|
||||||
// select the buffer to set data inside it ...
|
// select the buffer to set data inside it ...
|
||||||
if (this.buffer[iii] instanceof float[]) {
|
if (this.buffer[iii] instanceof float[]) {
|
||||||
|
@ -4,9 +4,12 @@ import org.atriasoft.etk.Uri;
|
|||||||
import org.atriasoft.gale.Gale;
|
import org.atriasoft.gale.Gale;
|
||||||
|
|
||||||
public class Sample1 {
|
public class Sample1 {
|
||||||
private Sample1() {}
|
public static void main(final String[] args) {
|
||||||
public static void main(String[] args) {
|
Gale.init();
|
||||||
Uri.setGroup("DATA", "src/org/atriasoft/gale/test/sample1/");
|
//Uri.setGroup("DATA", "src/org/atriasoft/gale/test/sample1/");
|
||||||
|
Uri.setApplication(Sample1.class, "/org/atriasoft/gale/test/sample1/");
|
||||||
Gale.run(new Sample1Application(), args);
|
Gale.run(new Sample1Application(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Sample1() {}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,12 @@ import org.atriasoft.etk.math.Vector3f;
|
|||||||
import org.atriasoft.gale.Application;
|
import org.atriasoft.gale.Application;
|
||||||
import org.atriasoft.gale.backend3d.OpenGL;
|
import org.atriasoft.gale.backend3d.OpenGL;
|
||||||
import org.atriasoft.gale.context.Context;
|
import org.atriasoft.gale.context.Context;
|
||||||
import org.atriasoft.gale.resource.ResourceProgram;
|
|
||||||
import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
|
|
||||||
import org.atriasoft.gale.key.KeyKeyboard;
|
import org.atriasoft.gale.key.KeyKeyboard;
|
||||||
import org.atriasoft.gale.key.KeySpecial;
|
import org.atriasoft.gale.key.KeySpecial;
|
||||||
import org.atriasoft.gale.key.KeyStatus;
|
import org.atriasoft.gale.key.KeyStatus;
|
||||||
import org.atriasoft.gale.key.KeyType;
|
import org.atriasoft.gale.key.KeyType;
|
||||||
|
import org.atriasoft.gale.resource.ResourceProgram;
|
||||||
|
import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
|
||||||
|
|
||||||
public class Sample1Application extends Application {
|
public class Sample1Application extends Application {
|
||||||
private ResourceProgram oGLprogram;
|
private ResourceProgram oGLprogram;
|
||||||
@ -23,32 +23,21 @@ public class Sample1Application extends Application {
|
|||||||
private float angle;
|
private float angle;
|
||||||
private ResourceVirtualArrayObject verticesVBO;
|
private ResourceVirtualArrayObject verticesVBO;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Context context) {
|
public void onCreate(final Context context) {
|
||||||
this.canDraw = true;
|
//setSize(new Vector2f(800, 600));
|
||||||
setSize(new Vector2f(800, 600));
|
|
||||||
this.angle = 0.0f;
|
this.angle = 0.0f;
|
||||||
this.oGLprogram = ResourceProgram.create(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag"));
|
this.oGLprogram = ResourceProgram.create(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag"));
|
||||||
if (this.oGLprogram != null) {
|
if (this.oGLprogram != null) {
|
||||||
this.oGLMatrixTransformation = this.oGLprogram.getUniform("matrixTransformation");
|
this.oGLMatrixTransformation = this.oGLprogram.getUniform("in_matrixTransformation");
|
||||||
this.oGLMatrixProjection = this.oGLprogram.getUniform("matrixProjection");
|
this.oGLMatrixProjection = this.oGLprogram.getUniform("in_matrixProjection");
|
||||||
this.oGLMatrixView = this.oGLprogram.getUniform("matrixView");
|
this.oGLMatrixView = this.oGLprogram.getUniform("in_matrixView");
|
||||||
}
|
}
|
||||||
|
|
||||||
float[] vertices = {
|
//float[] vertices = { 0.2f, 0.1f, 0.0f, 0.3f, 0.4f, 0.0f, 0.1f, 0.4f, 0.0f };
|
||||||
-0.5f, -0.5f, -1.0f,
|
float[] vertices = { -0.5f, -0.5f, -1.0f, 0.0f, 0.5f, -1.0f, 0.5f, -0.5f, -1.0f };
|
||||||
0.0f, 0.5f, -1.0f,
|
float[] colors = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, };
|
||||||
0.5f,-0.5f, -1.0f
|
int[] indices = { 0, 1, 2 };
|
||||||
};
|
|
||||||
float[] colors = {
|
|
||||||
1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
};
|
|
||||||
int[] indices = {
|
|
||||||
0, 1, 2,
|
|
||||||
};
|
|
||||||
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer
|
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer
|
||||||
this.verticesVBO = ResourceVirtualArrayObject.create(vertices, colors, indices);
|
this.verticesVBO = ResourceVirtualArrayObject.create(vertices, colors, indices);
|
||||||
// TO facilitate some debugs we add a name of the VBO:
|
// TO facilitate some debugs we add a name of the VBO:
|
||||||
@ -57,24 +46,26 @@ public class Sample1Application extends Application {
|
|||||||
this.verticesVBO.flush();
|
this.verticesVBO.flush();
|
||||||
Log.info("==> Init APPL (END)");
|
Log.info("==> Init APPL (END)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Context context) {
|
public void onDraw(final Context context) {
|
||||||
this.angle += 0.01;
|
this.angle += 0.01;
|
||||||
//Log.info("==> appl Draw ...");
|
//Log.info("==> appl Draw ...");
|
||||||
Vector2f size = getSize();
|
Vector2f size = getSize();
|
||||||
// set the basic openGL view port: (position drawed in the windows)
|
// set the basic openGL view port: (position drawed in the windows)
|
||||||
OpenGL.setViewPort(new Vector2f(0,0), size);
|
OpenGL.setViewPort(Vector2f.ZERO, size);
|
||||||
// Clear all the stacked matrix ...
|
// Clear all the stacked matrix ...
|
||||||
OpenGL.setBasicMatrix(Matrix4f.IDENTITY);
|
OpenGL.setBasicMatrix(Matrix4f.IDENTITY);
|
||||||
// clear background
|
// clear background
|
||||||
Color bgColor = new Color(0.0f, 1.0f, 1.0f, 0.75f);
|
Color bgColor = Color.CYAN;
|
||||||
OpenGL.clearColor(bgColor);
|
OpenGL.clearColor(bgColor);
|
||||||
// real clear request:
|
// real clear request:
|
||||||
OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer);
|
OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer);
|
||||||
// create a local matrix environnement.
|
// create a local matrix environment.
|
||||||
OpenGL.push();
|
OpenGL.push();
|
||||||
|
|
||||||
Matrix4f tmpProjection = Matrix4f.createMatrixOrtho(-getAspectRatio(), getAspectRatio(), -1, 1, -50, 50);
|
Matrix4f tmpProjection = Matrix4f.createMatrixOrtho(-getAspectRatio(), getAspectRatio(), -1, 1, -50, 50);
|
||||||
|
//Matrix4f tmpProjection = Matrix4f.IDENTITY;
|
||||||
// set internal matrix system:
|
// set internal matrix system:
|
||||||
OpenGL.setMatrix(tmpProjection);
|
OpenGL.setMatrix(tmpProjection);
|
||||||
if (this.oGLprogram == null) {
|
if (this.oGLprogram == null) {
|
||||||
@ -84,9 +75,9 @@ public class Sample1Application extends Application {
|
|||||||
//EWOL_DEBUG(" display " + this.coord.size() + " elements" );
|
//EWOL_DEBUG(" display " + this.coord.size() + " elements" );
|
||||||
this.oGLprogram.use();
|
this.oGLprogram.use();
|
||||||
|
|
||||||
// set Matrix : translation/positionMatrix
|
// set Matrix: translation/positionMatrix
|
||||||
Matrix4f projectionMatrix = tmpProjection; //OpenGL.getMatrix();
|
Matrix4f projectionMatrix = tmpProjection; //OpenGL.getMatrix();
|
||||||
Matrix4f transforamtionMatrix = Matrix4f.createMatrixRotate(new Vector3f(0,0,1),this.angle);
|
Matrix4f transforamtionMatrix = Matrix4f.createMatrixRotate(new Vector3f(0, 0, 1), this.angle);
|
||||||
Matrix4f viewMatrix = OpenGL.getCameraMatrix();
|
Matrix4f viewMatrix = OpenGL.getCameraMatrix();
|
||||||
//Matrix4f tmpMatrix = projMatrix * camMatrix;
|
//Matrix4f tmpMatrix = projMatrix * camMatrix;
|
||||||
|
|
||||||
@ -96,34 +87,29 @@ public class Sample1Application extends Application {
|
|||||||
// Change the position for each element with the same pipeline you need to render ...
|
// Change the position for each element with the same pipeline you need to render ...
|
||||||
this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, transforamtionMatrix);
|
this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, transforamtionMatrix);
|
||||||
|
|
||||||
// Request the draw od the elements:
|
// Request the draw of the elements:
|
||||||
this.verticesVBO.render(OpenGL.RenderMode.triangle);
|
this.verticesVBO.render(OpenGL.RenderMode.triangle);
|
||||||
|
|
||||||
this.verticesVBO.unBindForRendering();
|
this.verticesVBO.unBindForRendering();
|
||||||
this.oGLprogram.unUse();
|
this.oGLprogram.unUse();
|
||||||
// Restore context of matrix
|
// Restore context of matrix
|
||||||
OpenGL.pop();
|
OpenGL.pop();
|
||||||
this.markDrawingIsNeeded();
|
markDrawingIsNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPointer(KeySpecial special,
|
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||||
KeyType type,
|
|
||||||
int pointerID,
|
|
||||||
Vector2f pos,
|
|
||||||
KeyStatus state) {
|
|
||||||
// Log.info("input event: type=" + type);
|
|
||||||
// Log.info(" id=" + pointerID);
|
|
||||||
// Log.info(" pos=" + pos);
|
|
||||||
// Log.info(" state=" + state);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onKeyboard( KeySpecial special,
|
|
||||||
KeyKeyboard type,
|
|
||||||
Character value,
|
|
||||||
KeyStatus state) {
|
|
||||||
Log.info("Keyboard event: special=" + special);
|
Log.info("Keyboard event: special=" + special);
|
||||||
Log.info(" type=" + type);
|
Log.info(" type=" + type);
|
||||||
Log.info(" value='" + value + "'");
|
Log.info(" value='" + value + "'");
|
||||||
Log.info(" state=" + state);
|
Log.info(" state=" + state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
|
||||||
|
// Log.info("input event: type=" + type);
|
||||||
|
// Log.info(" id=" + pointerID);
|
||||||
|
// Log.info(" pos=" + pos);
|
||||||
|
// Log.info(" state=" + state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ uniform mat4 in_matrixView;
|
|||||||
out vec4 io_color;
|
out vec4 io_color;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
|
//gl_Position = in_matrixProjection * vec4(in_position, 1.0);
|
||||||
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
|
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
|
||||||
f_color = in_colors;
|
//gl_Position = vec4(in_position, 1.0);
|
||||||
|
io_color = in_colors;
|
||||||
}
|
}
|
@ -2,11 +2,14 @@ package org.atriasoft.gale.test.sample2;
|
|||||||
|
|
||||||
import org.atriasoft.etk.Uri;
|
import org.atriasoft.etk.Uri;
|
||||||
import org.atriasoft.gale.Gale;
|
import org.atriasoft.gale.Gale;
|
||||||
|
import org.atriasoft.gale.test.sample1.Sample1;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private Main() {}
|
public static void main(final String[] args) {
|
||||||
public static void main(String[] args) {
|
Gale.init();
|
||||||
Uri.setGroup("DATA", "src/org/atriasoft/gale/test/sample2/");
|
Uri.setApplication(Sample1.class, "/org/atriasoft/gale/test/sample2/");
|
||||||
Gale.run(new Sample2Application(), args);
|
Gale.run(new Sample2Application(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Main() {}
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,13 @@ import org.atriasoft.etk.math.Vector3f;
|
|||||||
import org.atriasoft.gale.Application;
|
import org.atriasoft.gale.Application;
|
||||||
import org.atriasoft.gale.backend3d.OpenGL;
|
import org.atriasoft.gale.backend3d.OpenGL;
|
||||||
import org.atriasoft.gale.context.Context;
|
import org.atriasoft.gale.context.Context;
|
||||||
import org.atriasoft.gale.resource.ResourceProgram;
|
|
||||||
import org.atriasoft.gale.resource.ResourceTexture;
|
|
||||||
import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
|
|
||||||
import org.atriasoft.gale.key.KeyKeyboard;
|
import org.atriasoft.gale.key.KeyKeyboard;
|
||||||
import org.atriasoft.gale.key.KeySpecial;
|
import org.atriasoft.gale.key.KeySpecial;
|
||||||
import org.atriasoft.gale.key.KeyStatus;
|
import org.atriasoft.gale.key.KeyStatus;
|
||||||
import org.atriasoft.gale.key.KeyType;
|
import org.atriasoft.gale.key.KeyType;
|
||||||
|
import org.atriasoft.gale.resource.ResourceProgram;
|
||||||
|
import org.atriasoft.gale.resource.ResourceTexture;
|
||||||
|
import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
|
||||||
|
|
||||||
public class Sample2Application extends Application {
|
public class Sample2Application extends Application {
|
||||||
private ResourceProgram oGLprogram;
|
private ResourceProgram oGLprogram;
|
||||||
@ -27,18 +27,16 @@ public class Sample2Application extends Application {
|
|||||||
private ResourceVirtualArrayObject verticesVBO;
|
private ResourceVirtualArrayObject verticesVBO;
|
||||||
private ResourceTexture texture;
|
private ResourceTexture texture;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Context context) {
|
public void onCreate(final Context context) {
|
||||||
this.canDraw = true;
|
|
||||||
setSize(new Vector2f(800, 600));
|
setSize(new Vector2f(800, 600));
|
||||||
this.oGLprogram = ResourceProgram.create(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag"));
|
this.oGLprogram = ResourceProgram.create(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag"));
|
||||||
if (this.oGLprogram != null) {
|
if (this.oGLprogram != null) {
|
||||||
this.oGLMatrixTransformation = this.oGLprogram.getUniform("matrixTransformation");
|
this.oGLMatrixTransformation = this.oGLprogram.getUniform("in_matrixTransformation");
|
||||||
this.oGLMatrixProjection = this.oGLprogram.getUniform("matrixProjection");
|
this.oGLMatrixProjection = this.oGLprogram.getUniform("in_matrixProjection");
|
||||||
this.oGLMatrixView = this.oGLprogram.getUniform("matrixView");
|
this.oGLMatrixView = this.oGLprogram.getUniform("in_matrixView");
|
||||||
}
|
}
|
||||||
|
//@formatter:off
|
||||||
float[] vertices = {
|
float[] vertices = {
|
||||||
-0.5f,0.5f,-0.5f,
|
-0.5f,0.5f,-0.5f,
|
||||||
-0.5f,-0.5f,-0.5f,
|
-0.5f,-0.5f,-0.5f,
|
||||||
@ -82,14 +80,16 @@ public class Sample2Application extends Application {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int[] indices = {
|
int[] indices = {
|
||||||
0,1,3, 3,1,2,
|
1,0,3, 1,3,2,
|
||||||
4,5,7, 7,5,6,
|
4,5,7, 7,5,6,
|
||||||
8,9,11, 11,9,10,
|
9,8,11, 9,11,10,
|
||||||
12,13,15, 15,13,14,
|
12,13,15, 15,13,14,
|
||||||
16,17,19, 19,17,18,
|
17,16,19, 17,19,18,
|
||||||
20,21,23, 23,21,22
|
20,21,23, 23,21,22
|
||||||
|
|
||||||
};
|
};
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer
|
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer
|
||||||
this.verticesVBO = ResourceVirtualArrayObject.create(vertices, textureCoords, null, indices);
|
this.verticesVBO = ResourceVirtualArrayObject.create(vertices, textureCoords, null, indices);
|
||||||
// TO facilitate some debugs we add a name of the VBO:
|
// TO facilitate some debugs we add a name of the VBO:
|
||||||
@ -104,8 +104,9 @@ public class Sample2Application extends Application {
|
|||||||
}
|
}
|
||||||
Log.info("==> Init APPL (END)");
|
Log.info("==> Init APPL (END)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Context context) {
|
public void onDraw(final Context context) {
|
||||||
this.angleX += 0.001;
|
this.angleX += 0.001;
|
||||||
this.angleY += 0.005;
|
this.angleY += 0.005;
|
||||||
this.angleZ += 0.01;
|
this.angleZ += 0.01;
|
||||||
@ -113,7 +114,7 @@ public class Sample2Application extends Application {
|
|||||||
Vector2f size = getSize();
|
Vector2f size = getSize();
|
||||||
//Log.info("==> Windows size = " + size);
|
//Log.info("==> Windows size = " + size);
|
||||||
// set the basic openGL view port: (position drawed in the windows)
|
// set the basic openGL view port: (position drawed in the windows)
|
||||||
OpenGL.setViewPort(new Vector2f(0,0), size);
|
OpenGL.setViewPort(new Vector2f(0, 0), size);
|
||||||
// Clear all the stacked matrix ...
|
// Clear all the stacked matrix ...
|
||||||
OpenGL.setBasicMatrix(Matrix4f.IDENTITY);
|
OpenGL.setBasicMatrix(Matrix4f.IDENTITY);
|
||||||
// clear background
|
// clear background
|
||||||
@ -140,11 +141,11 @@ public class Sample2Application extends Application {
|
|||||||
// set Matrix : translation/positionMatrix
|
// set Matrix : translation/positionMatrix
|
||||||
Matrix4f projectionMatrix = tmpProjection; //OpenGL.getMatrix();
|
Matrix4f projectionMatrix = tmpProjection; //OpenGL.getMatrix();
|
||||||
Matrix4f transforamtionMatrix = Matrix4f.IDENTITY;
|
Matrix4f transforamtionMatrix = Matrix4f.IDENTITY;
|
||||||
transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,-1)));
|
transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, -1)));
|
||||||
transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(1,0,0),this.angleX));
|
transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(1, 0, 0), this.angleX));
|
||||||
transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0,1,0),this.angleY));
|
transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0, 1, 0), this.angleY));
|
||||||
transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0,0,1),this.angleZ));
|
transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0, 0, 1), this.angleZ));
|
||||||
Matrix4f viewMatrix = OpenGL.getCameraMatrix().multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,-2)));
|
Matrix4f viewMatrix = OpenGL.getCameraMatrix().multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, -2)));
|
||||||
//Matrix4f tmpMatrix = projMatrix * camMatrix;
|
//Matrix4f tmpMatrix = projMatrix * camMatrix;
|
||||||
this.verticesVBO.bindForRendering();
|
this.verticesVBO.bindForRendering();
|
||||||
this.oGLprogram.uniformMatrix(this.oGLMatrixView, viewMatrix);
|
this.oGLprogram.uniformMatrix(this.oGLMatrixView, viewMatrix);
|
||||||
@ -162,27 +163,22 @@ public class Sample2Application extends Application {
|
|||||||
this.oGLprogram.unUse();
|
this.oGLprogram.unUse();
|
||||||
// Restore context of matrix
|
// Restore context of matrix
|
||||||
OpenGL.pop();
|
OpenGL.pop();
|
||||||
this.markDrawingIsNeeded();
|
markDrawingIsNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPointer(KeySpecial special,
|
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||||
KeyType type,
|
|
||||||
int pointerID,
|
|
||||||
Vector2f pos,
|
|
||||||
KeyStatus state) {
|
|
||||||
// Log.info("input event: type=" + type);
|
|
||||||
// Log.info(" id=" + pointerID);
|
|
||||||
// Log.info(" pos=" + pos);
|
|
||||||
// Log.info(" state=" + state);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onKeyboard( KeySpecial special,
|
|
||||||
KeyKeyboard type,
|
|
||||||
Character value,
|
|
||||||
KeyStatus state) {
|
|
||||||
Log.info("Keyboard event: special=" + special);
|
Log.info("Keyboard event: special=" + special);
|
||||||
Log.info(" type=" + type);
|
Log.info(" type=" + type);
|
||||||
Log.info(" value='" + value + "'");
|
Log.info(" value='" + value + "'");
|
||||||
Log.info(" state=" + state);
|
Log.info(" state=" + state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
|
||||||
|
// Log.info("input event: type=" + type);
|
||||||
|
// Log.info(" id=" + pointerID);
|
||||||
|
// Log.info(" pos=" + pos);
|
||||||
|
// Log.info(" state=" + state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
Loading…
x
Reference in New Issue
Block a user