Add simple image sample for now
This commit is contained in:
BIN
samples/SimpleImage/Assets/lime.png
Normal file
BIN
samples/SimpleImage/Assets/lime.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
54
samples/SimpleImage/Assets/lime.svg
Normal file
54
samples/SimpleImage/Assets/lime.svg
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
|
||||
<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
|
||||
<!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/">
|
||||
<!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
|
||||
<!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
|
||||
<!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
|
||||
<!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
|
||||
<!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
|
||||
<!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">
|
||||
]>
|
||||
<svg version="1.1" xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;"
|
||||
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1371.6px"
|
||||
height="1371.6px" viewBox="0 0 1371.6 1371.6" enable-background="new 0 0 1371.6 1371.6" xml:space="preserve">
|
||||
<metadata>
|
||||
<sfw xmlns="&ns_sfw;">
|
||||
<slices></slices>
|
||||
<sliceSourceBounds width="1079.91" height="1367.408" bottomLeftOrigin="true" x="-234.016" y="-286.092"></sliceSourceBounds>
|
||||
</sfw>
|
||||
</metadata>
|
||||
<g id="Shape_19_1_" enable-background="new ">
|
||||
<g id="Shape_19">
|
||||
<g>
|
||||
<polygon fill-rule="evenodd" clip-rule="evenodd" fill="#8C9C42" points="1195.316,936.171 1190.961,422.366 711.929,152.4
|
||||
711.929,56.606 176.284,409.303 184.994,962.297 646.607,1227.909 646.607,1310.64 "/>
|
||||
</g>
|
||||
<g>
|
||||
<polygon fill="none" stroke="#71AD1B" stroke-width="60.4839" stroke-miterlimit="100" points="1195.316,936.171
|
||||
1190.961,422.366 711.929,152.4 711.929,56.606 176.284,409.303 184.994,962.297 646.607,1227.909 646.607,1310.64 "/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="Shape_18_copy_1_" opacity="0.502" enable-background="new ">
|
||||
<g id="Shape_18_copy">
|
||||
<g>
|
||||
<polygon fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" points="703.219,683.623 698.155,695.438 698.865,182.88
|
||||
664.026,148.046 663.338,680.291 212.916,938 230.336,968.167 685.8,705.394 684.814,703.093 694.922,702.98 690.155,714.103
|
||||
1143.058,949.234 1164.832,923.109 "/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="Shape_20_copy_1_" enable-background="new ">
|
||||
<g id="Shape_20_copy">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M1172.718,936.171h0.824l2.218-498.411l-7.035-4.166
|
||||
l0.189-0.341l-470.05-273.635V91.44L250.903,386.114l-57.2,31.898l4.355,531.223l1.297-0.324l-1.348,2.316l466.018,271.956
|
||||
v61.332l501.303-341.361l8.505-5.133L1172.718,936.171z M665.741,194.562l447.104,247.473L684.288,675.308L244.653,428.044
|
||||
L665.741,194.562z M698.865,707.025l439.818-239.87l0.02,451.38l-439.838,265.454V707.025z M232.897,931.221V461.399
|
||||
l431.129,242.479v478.15L232.897,931.221z"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
56
samples/SimpleImage/SimpleImage.hxproj
Normal file
56
samples/SimpleImage/SimpleImage.hxproj
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project version="2">
|
||||
<!-- Output SWF options -->
|
||||
<output>
|
||||
<movie outputType="Application" />
|
||||
<movie input="" />
|
||||
<movie path="project.xml" />
|
||||
<movie fps="30" />
|
||||
<movie width="800" />
|
||||
<movie height="600" />
|
||||
<movie version="3" />
|
||||
<movie minorVersion="0" />
|
||||
<movie platform="NME" />
|
||||
<movie background="#FFFFFF" />
|
||||
</output>
|
||||
<!-- Other classes to be compiled into your SWF -->
|
||||
<classpaths>
|
||||
<class path="Source" />
|
||||
</classpaths>
|
||||
<!-- Build options -->
|
||||
<build>
|
||||
<option directives="" />
|
||||
<option flashStrict="False" />
|
||||
<option mainClass="Main" />
|
||||
<option enabledebug="False" />
|
||||
<option additional="" />
|
||||
</build>
|
||||
<!-- haxelib libraries -->
|
||||
<haxelib>
|
||||
<library name="lime" />
|
||||
</haxelib>
|
||||
<!-- Class files to compile (other referenced classes will automatically be included) -->
|
||||
<compileTargets>
|
||||
<!-- example: <compile path="..." /> -->
|
||||
</compileTargets>
|
||||
<!-- Assets to embed into the output SWF -->
|
||||
<library>
|
||||
<!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
|
||||
</library>
|
||||
<!-- Paths to exclude from the Project Explorer tree -->
|
||||
<hiddenPaths>
|
||||
<!-- example: <hidden path="..." /> -->
|
||||
</hiddenPaths>
|
||||
<!-- Executed before build -->
|
||||
<preBuildCommand />
|
||||
<!-- Executed after build -->
|
||||
<postBuildCommand alwaysRun="False" />
|
||||
<!-- Other project options -->
|
||||
<options>
|
||||
<option showHiddenPaths="False" />
|
||||
<option testMovie="Custom" />
|
||||
<option testMovieCommand="" />
|
||||
</options>
|
||||
<!-- Plugin storage -->
|
||||
<storage />
|
||||
</project>
|
||||
255
samples/SimpleImage/Source/Main.hx
Normal file
255
samples/SimpleImage/Source/Main.hx
Normal file
@@ -0,0 +1,255 @@
|
||||
package;
|
||||
|
||||
|
||||
import lime.app.Application;
|
||||
import lime.graphics.opengl.GLBuffer;
|
||||
import lime.graphics.opengl.GLProgram;
|
||||
import lime.graphics.opengl.GLTexture;
|
||||
import lime.graphics.ImageData;
|
||||
import lime.graphics.GLRenderContext;
|
||||
import lime.graphics.RenderContext;
|
||||
import lime.utils.Float32Array;
|
||||
import lime.Assets;
|
||||
|
||||
|
||||
#if html5
|
||||
@:access(lime.graphics.opengl.GL)
|
||||
#end
|
||||
class Main extends Application {
|
||||
|
||||
|
||||
private var image:ImageData;
|
||||
private var initialized:Bool;
|
||||
|
||||
private var shaderProgram:GLProgram;
|
||||
private var texCoordBuffer:GLBuffer;
|
||||
private var texture:GLTexture;
|
||||
private var vertexBuffer:GLBuffer;
|
||||
|
||||
|
||||
public function new () {
|
||||
|
||||
super ();
|
||||
|
||||
image = Assets.getImageData ("assets/lime.png");
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function initialize (context:RenderContext):Void {
|
||||
|
||||
switch (context) {
|
||||
|
||||
case DOM (element):
|
||||
|
||||
var div = element.ownerDocument.createElement ("div");
|
||||
div.style.width = image.width + "px";
|
||||
div.style.height = image.height + "px";
|
||||
div.style.backgroundImage = "url('" + Assets.getPath ("assets/lime.png") + ")";
|
||||
element.appendChild (image.data);
|
||||
|
||||
case OPENGL (gl):
|
||||
|
||||
// Initialize shaders
|
||||
|
||||
var vertexShaderSource =
|
||||
|
||||
"attribute vec3 aVertexPosition;
|
||||
attribute vec2 aTexCoord;
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
uniform mat4 uModelViewMatrix;
|
||||
uniform mat4 uProjectionMatrix;
|
||||
|
||||
void main(void) {
|
||||
vTexCoord = aTexCoord;
|
||||
gl_Position = uProjectionMatrix * uModelViewMatrix * vec4 (aVertexPosition, 1.0);
|
||||
}";
|
||||
|
||||
var vertexShader = gl.createShader (gl.VERTEX_SHADER);
|
||||
gl.shaderSource (vertexShader, vertexShaderSource);
|
||||
gl.compileShader (vertexShader);
|
||||
|
||||
if (gl.getShaderParameter (vertexShader, gl.COMPILE_STATUS) == 0) {
|
||||
|
||||
throw "Error compiling vertex shader";
|
||||
|
||||
}
|
||||
|
||||
var fragmentShaderSource =
|
||||
|
||||
#if !desktop
|
||||
"precision mediump float;" +
|
||||
#end
|
||||
"varying vec2 vTexCoord;
|
||||
uniform sampler2D uImage0;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_FragColor = texture2D (uImage0, vTexCoord);
|
||||
}";
|
||||
|
||||
var fragmentShader = gl.createShader (gl.FRAGMENT_SHADER);
|
||||
gl.shaderSource (fragmentShader, fragmentShaderSource);
|
||||
gl.compileShader (fragmentShader);
|
||||
|
||||
if (gl.getShaderParameter (fragmentShader, gl.COMPILE_STATUS) == 0) {
|
||||
|
||||
throw "Error compiling fragment shader";
|
||||
|
||||
}
|
||||
|
||||
shaderProgram = gl.createProgram ();
|
||||
gl.attachShader (shaderProgram, vertexShader);
|
||||
gl.attachShader (shaderProgram, fragmentShader);
|
||||
gl.linkProgram (shaderProgram);
|
||||
|
||||
if (gl.getProgramParameter (shaderProgram, gl.LINK_STATUS) == 0) {
|
||||
|
||||
throw "Unable to initialize the shader program.";
|
||||
|
||||
}
|
||||
|
||||
// Create buffers
|
||||
|
||||
var vertices = [
|
||||
|
||||
image.width, image.height, 0,
|
||||
0, image.height, 0,
|
||||
image.width, 0, 0,
|
||||
0, 0, 0
|
||||
|
||||
];
|
||||
|
||||
vertexBuffer = gl.createBuffer ();
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, vertexBuffer);
|
||||
gl.bufferData (gl.ARRAY_BUFFER, new Float32Array (cast vertices), gl.STATIC_DRAW);
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, null);
|
||||
|
||||
var texCoords = [
|
||||
|
||||
1, 1,
|
||||
0, 1,
|
||||
1, 0,
|
||||
0, 0,
|
||||
|
||||
];
|
||||
|
||||
texCoordBuffer = gl.createBuffer ();
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, texCoordBuffer);
|
||||
gl.bufferData (gl.ARRAY_BUFFER, new Float32Array (cast texCoords), gl.STATIC_DRAW);
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, null);
|
||||
|
||||
// Create texture
|
||||
|
||||
texture = gl.createTexture ();
|
||||
gl.bindTexture (gl.TEXTURE_2D, texture);
|
||||
gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
#if html5
|
||||
lime.graphics.opengl.GL.context.texImage2D (gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image.data);
|
||||
#else
|
||||
gl.texImage2D (gl.TEXTURE_2D, 0, gl.RGBA, image.width, image.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, image.data);
|
||||
#end
|
||||
gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.bindTexture (gl.TEXTURE_2D, null);
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function render (context:RenderContext):Void {
|
||||
|
||||
if (!initialized) {
|
||||
|
||||
initialize (context);
|
||||
initialized = true;
|
||||
|
||||
}
|
||||
|
||||
switch (context) {
|
||||
|
||||
case CANVAS (context):
|
||||
|
||||
context.drawImage (image.data, 0, 0, image.width, image.height);
|
||||
|
||||
case DOM (element):
|
||||
|
||||
// still visible
|
||||
|
||||
case FLASH (sprite):
|
||||
|
||||
sprite.graphics.beginBitmapFill (image.data);
|
||||
sprite.graphics.drawRect (0, 0, image.width, image.height);
|
||||
|
||||
case OPENGL (gl):
|
||||
|
||||
gl.clearColor (1.0, 1.0, 1.0, 1.0);
|
||||
gl.clear (gl.COLOR_BUFFER_BIT);
|
||||
|
||||
var vertexAttribute = gl.getAttribLocation (shaderProgram, "aVertexPosition");
|
||||
var texCoordAttribute = gl.getAttribLocation (shaderProgram, "aTexCoord");
|
||||
var projectionMatrixUniform = gl.getUniformLocation (shaderProgram, "uProjectionMatrix");
|
||||
var modelViewMatrixUniform = gl.getUniformLocation (shaderProgram, "uModelViewMatrix");
|
||||
var imageUniform = gl.getUniformLocation (shaderProgram, "uImage0");
|
||||
|
||||
var positionX = 0;
|
||||
var positionY = 0;
|
||||
var width = config.width;
|
||||
var height = config.height;
|
||||
|
||||
var projectionMatrix = new Float32Array ([ 2 / width, 0, 0, 0, 0, 2 / height, 0, 0, 0, 0, -0.0001, 0, -1, -1, 1, 1 ]);
|
||||
|
||||
var rotation = 0;
|
||||
var scale = 1;
|
||||
var theta = rotation * Math.PI / 180;
|
||||
var c = Math.cos (theta);
|
||||
var s = Math.sin (theta);
|
||||
|
||||
var modelViewMatrix = new Float32Array ([ c * scale, -s * scale, 0, 0, s * scale, c * scale, 0, 0, 0, 0, 1, 0, positionX, positionY, 0, 1 ]);
|
||||
|
||||
gl.useProgram (shaderProgram);
|
||||
gl.enableVertexAttribArray (vertexAttribute);
|
||||
gl.enableVertexAttribArray (texCoordAttribute);
|
||||
|
||||
gl.activeTexture (gl.TEXTURE0);
|
||||
gl.bindTexture (gl.TEXTURE_2D, texture);
|
||||
|
||||
#if desktop
|
||||
gl.enable (gl.TEXTURE_2D);
|
||||
#end
|
||||
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, vertexBuffer);
|
||||
gl.vertexAttribPointer (vertexAttribute, 3, gl.FLOAT, false, 0, 0);
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, texCoordBuffer);
|
||||
gl.vertexAttribPointer (texCoordAttribute, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.uniformMatrix4fv (projectionMatrixUniform, false, projectionMatrix);
|
||||
gl.uniformMatrix4fv (modelViewMatrixUniform, false, modelViewMatrix);
|
||||
gl.uniform1i (imageUniform, 0);
|
||||
|
||||
gl.drawArrays (gl.TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, null);
|
||||
gl.bindTexture (gl.TEXTURE_2D, null);
|
||||
|
||||
#if desktop
|
||||
gl.disable (gl.TEXTURE_2D);
|
||||
#end
|
||||
|
||||
gl.disableVertexAttribArray (vertexAttribute);
|
||||
gl.disableVertexAttribArray (texCoordAttribute);
|
||||
gl.useProgram (null);
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
14
samples/SimpleImage/project.xml
Normal file
14
samples/SimpleImage/project.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
|
||||
<meta title="Simple Image" package="org.openfl.lime.samples.simpleimage" version="1.0.0" company="OpenFL Technologies" />
|
||||
<app main="Main" path="Export" file="SimpleImage" />
|
||||
|
||||
<source path="Source" />
|
||||
|
||||
<haxelib name="lime" />
|
||||
|
||||
<assets path="Assets" rename="assets" exclude="*.svg" />
|
||||
<icon path="Assets/lime.svg" />
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user