diff --git a/lime/audio/ALAudioContext.hx b/lime/audio/ALAudioContext.hx index b79d927c1..3e181e4e4 100644 --- a/lime/audio/ALAudioContext.hx +++ b/lime/audio/ALAudioContext.hx @@ -2,7 +2,7 @@ package lime.audio; import lime.audio.openal.AL; -import lime.utils.Float32Array; +import lime.utils.ByteArray; class ALAudioContext { @@ -79,7 +79,7 @@ class ALAudioContext { } - public function bufferData (buffer:Int, format:Int, data:Float32Array, size:Int, freq:Int):Void { + public function bufferData (buffer:Int, format:Int, data:ByteArray, size:Int, freq:Int):Void { AL.bufferData (buffer, format, data, size, freq); diff --git a/lime/audio/AudioBuffer.hx b/lime/audio/AudioBuffer.hx index 1e2099f6a..5dd8ac7a1 100644 --- a/lime/audio/AudioBuffer.hx +++ b/lime/audio/AudioBuffer.hx @@ -18,7 +18,7 @@ class AudioBuffer { public var bitsPerSample:Int; public var channels:Int; - public var data:Float32Array; + public var data:ByteArray; public var id:UInt; public var sampleRate:Int; @@ -53,7 +53,7 @@ class AudioBuffer { var audioBuffer = new AudioBuffer (); audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.channels = data.channels; - audioBuffer.data = new Float32Array (data.data); + audioBuffer.data = data.data; audioBuffer.sampleRate = data.sampleRate; return audioBuffer; @@ -74,7 +74,7 @@ class AudioBuffer { var audioBuffer = new AudioBuffer (); audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.channels = data.channels; - audioBuffer.data = new Float32Array (data.data); + audioBuffer.data = data.data; audioBuffer.sampleRate = data.sampleRate; return audioBuffer; diff --git a/lime/audio/AudioSource.hx b/lime/audio/AudioSource.hx index 9fc749d04..330a46e82 100644 --- a/lime/audio/AudioSource.hx +++ b/lime/audio/AudioSource.hx @@ -4,6 +4,10 @@ package lime.audio; import lime.app.Event; import lime.audio.openal.AL; +#if flash +import flash.media.SoundChannel; +#end + class AudioSource { @@ -15,12 +19,18 @@ class AudioSource { public var timeOffset (get, set):Int; private var id:UInt; + private var pauseTime:Int; + + #if flash + private var channel:SoundChannel; + #end public function new (buffer:AudioBuffer = null) { this.buffer = buffer; id = 0; + pauseTime = 0; if (buffer != null) { @@ -69,7 +79,7 @@ class AudioSource { } - al.bufferData (buffer.id, format, buffer.data, buffer.data.length << 2, buffer.sampleRate); + al.bufferData (buffer.id, format, buffer.data, buffer.data.length, buffer.sampleRate); } @@ -87,7 +97,8 @@ class AudioSource { #if js #elseif flash - buffer.src.play (); + if (channel != null) channel.stop (); + var channel = buffer.src.play (pauseTime / 1000); #else AL.sourcePlay (id); #end @@ -99,7 +110,12 @@ class AudioSource { #if js #elseif flash - buffer.src.pause (); + if (channel != null) { + + pauseTime = Std.int (channel.position * 1000); + channel.stop (); + + } #else AL.sourcePause (id); #end @@ -111,7 +127,8 @@ class AudioSource { #if js #elseif flash - buffer.src.stop (); + pauseTime = 0; + if (channel != null) channel.stop (); #else AL.sourceStop (id); #end diff --git a/lime/audio/openal/AL.hx b/lime/audio/openal/AL.hx index 112a24637..d815ff21a 100644 --- a/lime/audio/openal/AL.hx +++ b/lime/audio/openal/AL.hx @@ -2,7 +2,7 @@ package lime.audio.openal; import lime.system.System; -import lime.utils.Float32Array; +import lime.utils.ByteArray; class AL { @@ -72,7 +72,7 @@ class AL { public static inline var EXPONENT_DISTANCE_CLAMPED:Int = 0xD006; - public static function bufferData (buffer:Int, format:Int, data:Float32Array, size:Int, freq:Int):Void { + public static function bufferData (buffer:Int, format:Int, data:ByteArray, size:Int, freq:Int):Void { #if (cpp || neko) lime_al_buffer_data (buffer, format, data.getByteBuffer (), size, freq); diff --git a/samples/HelloWorld/project.xml b/samples/HelloWorld/project.xml index d95e0b946..284979743 100644 --- a/samples/HelloWorld/project.xml +++ b/samples/HelloWorld/project.xml @@ -1,7 +1,7 @@ - + diff --git a/samples/HerokuShaders/HerokuShaders.hxproj b/samples/HerokuShaders/HerokuShaders.hxproj index 2000dc231..3c5128197 100644 --- a/samples/HerokuShaders/HerokuShaders.hxproj +++ b/samples/HerokuShaders/HerokuShaders.hxproj @@ -4,30 +4,33 @@ - + - + + + - - + @@ -39,7 +42,7 @@ - + @@ -53,4 +56,4 @@ - + \ No newline at end of file diff --git a/samples/HerokuShaders/Source/Main.hx b/samples/HerokuShaders/Source/Main.hx index 4f44f9a51..529ead755 100644 --- a/samples/HerokuShaders/Source/Main.hx +++ b/samples/HerokuShaders/Source/Main.hx @@ -2,18 +2,18 @@ package; import haxe.Timer; -import lime.gl.GL; -import lime.gl.GLBuffer; -import lime.gl.GLProgram; -import lime.gl.GLShader; -import lime.gl.GLUniformLocation; -import lime.utils.Matrix3D; +import lime.app.Application; +import lime.graphics.opengl.GL; +import lime.graphics.opengl.GLBuffer; +import lime.graphics.opengl.GLProgram; +import lime.graphics.opengl.GLShader; +import lime.graphics.opengl.GLUniformLocation; +import lime.graphics.RenderContext; import lime.utils.Float32Array; -import lime.utils.Assets; -import lime.Lime; +import lime.Assets; -class Main { +class Main extends Application { private static var fragmentShaders = [ #if mobile "6284.1", "6238", "6147.1", "5891.5", "5805.18", "5492", "5398.8" #else "6286", "6288.1", "6284.1", "6238", "6223.2", "6175", "6162", "6147.1", "6049", "6043.1", "6022", "5891.5", "5805.18", "5812", "5733", "5454.21", "5492", "5359.8", "5398.8", "4278.1" #end ]; @@ -24,7 +24,6 @@ class Main { private var currentIndex:Int; private var currentProgram:GLProgram; private var currentTime:Float; - private var lime:Lime; private var mouseUniform:GLUniformLocation; private var positionAttribute:Int; private var resolutionUniform:GLUniformLocation; @@ -34,7 +33,11 @@ class Main { private var vertexPosition:Int; - public function new () {} + public function new () { + + super (); + + } private function compile ():Void { @@ -116,6 +119,31 @@ class Main { } + public override function init (context:RenderContext):Void { + + switch (context) { + + case OPENGL (gl): + + fragmentShaders = randomizeArray (fragmentShaders); + currentIndex = 0; + + buffer = gl.createBuffer (); + gl.bindBuffer (gl.ARRAY_BUFFER, buffer); + gl.bufferData (gl.ARRAY_BUFFER, new Float32Array ([ -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0 ]), gl.STATIC_DRAW); + gl.bindBuffer (gl.ARRAY_BUFFER, null); + + compile (); + + default: + + // not implemented + + } + + } + + private function randomizeArray (array:Array):Array { var arrayCopy = array.copy (); @@ -133,51 +161,46 @@ class Main { } - public function ready (lime:Lime) { + public override function render (context:RenderContext):Void { - this.lime = lime; + switch (context) { + + case OPENGL (gl): + + if (currentProgram == null) return; + + currentTime = Timer.stamp () - startTime; + + gl.viewport (0, 0, window.width, window.height); + gl.useProgram (currentProgram); + + gl.uniform1f (timeUniform, currentTime); + gl.uniform2f (mouseUniform, 0.1, 0.1); //GL.uniform2f (mouseUniform, (stage.mouseX / stage.stageWidth) * 2 - 1, (stage.mouseY / stage.stageHeight) * 2 - 1); + gl.uniform2f (resolutionUniform, window.width, window.height); + gl.uniform1i (backbufferUniform, 0 ); + gl.uniform2f (surfaceSizeUniform, window.width, window.height); + + gl.bindBuffer (gl.ARRAY_BUFFER, buffer); + gl.vertexAttribPointer (positionAttribute, 2, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer (vertexPosition, 2, gl.FLOAT, false, 0, 0); + + gl.clearColor (0, 0, 0, 1); + gl.clear (gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT ); + gl.drawArrays (gl.TRIANGLES, 0, 6); + gl.bindBuffer (gl.ARRAY_BUFFER, null); + + default: + + // not implemented + + } - fragmentShaders = randomizeArray (fragmentShaders); - currentIndex = 0; - buffer = GL.createBuffer (); - GL.bindBuffer (GL.ARRAY_BUFFER, buffer); - GL.bufferData (GL.ARRAY_BUFFER, new Float32Array ([ -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0 ]), GL.STATIC_DRAW); - GL.bindBuffer (GL.ARRAY_BUFFER, null); - - compile (); } - public function render ():Void { - - if (currentProgram == null) return; - - currentTime = Timer.stamp () - startTime; - - GL.viewport (0, 0, lime.config.width, lime.config.height); - GL.useProgram (currentProgram); - - GL.uniform1f (timeUniform, currentTime); - GL.uniform2f (mouseUniform, 0.1, 0.1); //GL.uniform2f (mouseUniform, (stage.mouseX / stage.stageWidth) * 2 - 1, (stage.mouseY / stage.stageHeight) * 2 - 1); - GL.uniform2f (resolutionUniform, lime.config.width, lime.config.height); - GL.uniform1i (backbufferUniform, 0 ); - GL.uniform2f (surfaceSizeUniform, lime.config.width, lime.config.height); - - GL.bindBuffer (GL.ARRAY_BUFFER, buffer); - GL.vertexAttribPointer (positionAttribute, 2, GL.FLOAT, false, 0, 0); - GL.vertexAttribPointer (vertexPosition, 2, GL.FLOAT, false, 0, 0); - - GL.clearColor (0, 0, 0, 1); - GL.clear (GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT ); - GL.drawArrays (GL.TRIANGLES, 0, 6); - GL.bindBuffer (GL.ARRAY_BUFFER, null); - - } - - - public function update ():Void { + public override function update (deltaTime:Int):Void { if (currentTime > maxTime && fragmentShaders.length > 1) { diff --git a/samples/HerokuShaders/project.lime b/samples/HerokuShaders/project.lime deleted file mode 100644 index 3d89f41cd..000000000 --- a/samples/HerokuShaders/project.lime +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/samples/HerokuShaders/project.xml b/samples/HerokuShaders/project.xml new file mode 100644 index 000000000..ed13c45f6 --- /dev/null +++ b/samples/HerokuShaders/project.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/SimpleAudioExample/Assets/ambience.ogg b/samples/SimpleAudio/Assets/ambience.ogg similarity index 100% rename from samples/SimpleAudioExample/Assets/ambience.ogg rename to samples/SimpleAudio/Assets/ambience.ogg diff --git a/samples/SimpleAudioExample/Assets/sound_licenses.txt b/samples/SimpleAudio/Assets/license.txt similarity index 100% rename from samples/SimpleAudioExample/Assets/sound_licenses.txt rename to samples/SimpleAudio/Assets/license.txt diff --git a/samples/SimpleAudioExample/Assets/sound.ogg b/samples/SimpleAudio/Assets/sound.ogg similarity index 100% rename from samples/SimpleAudioExample/Assets/sound.ogg rename to samples/SimpleAudio/Assets/sound.ogg diff --git a/samples/SimpleAudioExample/Assets/sound.wav b/samples/SimpleAudio/Assets/sound.wav similarity index 100% rename from samples/SimpleAudioExample/Assets/sound.wav rename to samples/SimpleAudio/Assets/sound.wav diff --git a/samples/SimpleOpenGL/SimpleOpenGLView.hxproj b/samples/SimpleAudio/SimpleAudio.hxproj similarity index 74% rename from samples/SimpleOpenGL/SimpleOpenGLView.hxproj rename to samples/SimpleAudio/SimpleAudio.hxproj index 789136620..7c57645fe 100644 --- a/samples/SimpleOpenGL/SimpleOpenGLView.hxproj +++ b/samples/SimpleAudio/SimpleAudio.hxproj @@ -4,30 +4,33 @@ - + - + + + - - + @@ -39,7 +42,7 @@ - + diff --git a/samples/SimpleAudio/Source/Main.hx b/samples/SimpleAudio/Source/Main.hx new file mode 100644 index 000000000..7cd25784f --- /dev/null +++ b/samples/SimpleAudio/Source/Main.hx @@ -0,0 +1,74 @@ +package; + + +import lime.app.Application; +import lime.audio.AudioSource; +import lime.graphics.RenderContext; +import lime.Assets; + + +class Main extends Application { + + + private var ambience:AudioSource; + private var sound:AudioSource; + + + public function new () { + + super (); + + } + + + public override function init (_):Void { + + #if !flash + ambience = new AudioSource (Assets.getAudioBuffer ("assets/ambience.ogg")); + ambience.play (); + #end + + sound = new AudioSource (Assets.getAudioBuffer ("assets/sound.wav")); + + } + + + public override function onMouseDown (_, _, _):Void { + + sound.play (); + + } + + + public override function render (context:RenderContext):Void { + + switch (context) { + + case CANVAS (context): + + context.fillStyle = "#3CB878"; + context.fillRect (0, 0, window.width, window.height); + + case DOM (element): + + element.style.backgroundColor = "#3CB878"; + + case FLASH (sprite): + + sprite.graphics.beginFill (0x3CB878); + sprite.graphics.drawRect (0, 0, window.width, window.height); + + case OPENGL (gl): + + gl.viewport (0, 0, window.width, window.height); + gl.clearColor (60 / 255, 184 / 255, 7 / 255, 1); + gl.clear (gl.COLOR_BUFFER_BIT); + + default: + + } + + } + + +} \ No newline at end of file diff --git a/samples/SimpleAudio/project.xml b/samples/SimpleAudio/project.xml new file mode 100644 index 000000000..5a597b586 --- /dev/null +++ b/samples/SimpleAudio/project.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/SimpleAudioExample/Assets/.keep b/samples/SimpleAudioExample/Assets/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/samples/SimpleAudioExample/project.lime.xml b/samples/SimpleAudioExample/project.lime.xml deleted file mode 100644 index ec91cd58e..000000000 --- a/samples/SimpleAudioExample/project.lime.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/SimpleAudioExample/src/Main.hx b/samples/SimpleAudioExample/src/Main.hx deleted file mode 100644 index 34f0948f2..000000000 --- a/samples/SimpleAudioExample/src/Main.hx +++ /dev/null @@ -1,106 +0,0 @@ - - //Ported and modified from OpenFL samples - //underscorediscovery - -import lime.helpers.AudioHelper.Sound; -import lime.utils.Assets; -import lime.Lime; - - //Import GL stuff from lime -import lime.gl.GL; - -//Press any key to reset the music -//Click to play a sound - -class Main { - - public var lib : Lime; - - //Some value to mess with the clear color - private var red_value : Float = 1.0; - private var red_direction : Int = 1; - private var dt : Float = 0.016; - private var end_dt : Float = 0; - - public function new() { } - - public function ready( _lime : Lime ) { - - //Store a reference - lib = _lime; - - // Init the shaders and view - init(); - - } //ready - - - public function init() { - - lib.audio.create('music', 'assets/ambience.ogg', true ); - lib.audio.create('sound', 'assets/sound.ogg', false); - lib.audio.create('sound_wav', 'assets/sound.wav', false); - - lib.audio.play('music', 5); - lib.audio.sound('music').on_complete( function(sound:Sound){ - trace("music complete!"); - }); - - } //init - - //Called each frame by lime for logic (called before render) - public function update() { - - dt = haxe.Timer.stamp() - end_dt; - end_dt = haxe.Timer.stamp(); - - //an awful magic number to change the value slowly - red_value += (red_direction * 0.3) * dt; - - if(red_value >= 1) { - red_value = 1; - red_direction = -red_direction; - } else if(red_value <= 0) { - red_value = 0; - red_direction = -red_direction; - } - - } //update - - //Called by lime - public function onmousemove(_event:Dynamic) { - } - //Called by lime - public function onmousedown(_event:Dynamic) { - lib.audio.play('sound', 0.0); - } - //Called by lime - public function onmouseup(_event:Dynamic) { - } - //Called by lime - public function onkeydown(_event:Dynamic) { - lib.audio.position('music', 0.0); - } - //Called by lime - public function onkeyup(_event:Dynamic) { - } - - - //Called by lime - public function render() { - - //Set the viewport for GL - GL.viewport( 0, 0, lib.config.width, lib.config.height ); - - //Set the clear color to a weird color that bounces around - GL.clearColor( red_value, red_value*0.5, red_value*0.3, 1); - //Clear the buffers - GL.clear( GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT ); - - - } //render - - -} //Main - - diff --git a/samples/SimpleOpenGL/Assets/lime.png b/samples/SimpleOpenGL/Assets/lime.png deleted file mode 100644 index 5afb8060b..000000000 Binary files a/samples/SimpleOpenGL/Assets/lime.png and /dev/null differ diff --git a/samples/SimpleOpenGL/Assets/lime.svg b/samples/SimpleOpenGL/Assets/lime.svg deleted file mode 100644 index 0e20a1c77..000000000 --- a/samples/SimpleOpenGL/Assets/lime.svg +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - -]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/SimpleOpenGL/Source/Main.hx b/samples/SimpleOpenGL/Source/Main.hx deleted file mode 100644 index 9779f0435..000000000 --- a/samples/SimpleOpenGL/Source/Main.hx +++ /dev/null @@ -1,320 +0,0 @@ -package; - - -import format.png.Reader; -import format.png.Tools; -import haxe.io.Bytes; -import haxe.io.BytesData; -import haxe.io.BytesInput; -import lime.gl.GL; -import lime.gl.GLBuffer; -import lime.gl.GLProgram; -import lime.gl.GLTexture; -import lime.gl.GLUniformLocation; -import lime.utils.ByteArray; -import lime.utils.Matrix3D; -import lime.utils.Assets; -import lime.utils.Float32Array; -import lime.utils.UInt8Array; -import lime.Lime; - - -class Main { - - - private var imageData:UInt8Array; - private var imageHeight:Int; - private var imageWidth:Int; - private var imageUniform:GLUniformLocation; - private var lime:Lime; - private var modelViewMatrixUniform:GLUniformLocation; - private var projectionMatrixUniform:GLUniformLocation; - private var shaderProgram:GLProgram; - private var texCoordAttribute:Int; - private var texCoordBuffer:GLBuffer; - private var texture:GLTexture; - private var vertexAttribute:Int; - private var vertexBuffer:GLBuffer; - - - public function new () {} - - - private function createBuffers ():Void { - - var vertices = [ - - imageWidth, imageHeight, 0, - 0, imageHeight, 0, - imageWidth, 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); - - } - - - private function createTexture ():Void { - - texture = GL.createTexture (); - GL.bindTexture (GL.TEXTURE_2D, texture); - GL.texImage2D (GL.TEXTURE_2D, 0, GL.RGBA, imageHeight, imageHeight, 0, GL.RGBA, GL.UNSIGNED_BYTE, imageData); - 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); - - } - - - private function initializeShaders ():Void { - - var vertexShaderSource = ""; - - #if lime_html5 - vertexShaderSource += "precision mediump float;"; - #end - - 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 lime_html5 - fragmentShaderSource += "precision mediump float;"; - #end - - fragmentShaderSource += - "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."; - - } - - vertexAttribute = GL.getAttribLocation (shaderProgram, "aVertexPosition"); - texCoordAttribute = GL.getAttribLocation (shaderProgram, "aTexCoord"); - projectionMatrixUniform = GL.getUniformLocation (shaderProgram, "uProjectionMatrix"); - modelViewMatrixUniform = GL.getUniformLocation (shaderProgram, "uModelViewMatrix"); - imageUniform = GL.getUniformLocation (shaderProgram, "uImage0"); - - } - - -#if lime_html5 - - function load_image(_id:String, onload:Void->Void) { - - var image: js.html.ImageElement = js.Browser.document.createImageElement(); - - image.onload = function(a) { - - try { - - var tmp_canvas = js.Browser.document.createCanvasElement(); - tmp_canvas.width = image.width; - tmp_canvas.height = image.height; - - var tmp_context = tmp_canvas.getContext2d(); - tmp_context.clearRect( 0,0, tmp_canvas.width, tmp_canvas.height ); - tmp_context.drawImage( image, 0, 0, image.width, image.height ); - - var image_bytes = tmp_context.getImageData( 0, 0, tmp_canvas.width, tmp_canvas.height ); - var haxe_bytes = new lime.utils.UInt8Array( image_bytes.data ); - - imageData = haxe_bytes; - imageHeight = image.width; - imageWidth = image.height; - - tmp_canvas = null; - tmp_context = null; - haxe_bytes = null; - image_bytes = null; - - onload(); - - } catch(e:Dynamic) { - - trace(e); - var tips = '- textures might require power of two sizes\n'; - tips += '- textures served from file:/// throw security errors\n'; - tips += '- textures served over http:// work for cross origin'; - - trace(tips); - throw e; - - } - - } //image.onload - - //source comes after the onload being set, for race conditions - image.src = _id; - - } //load_html5_image - -#else - - function load_image(_id:String, onload:Void->Void) { - - var bytes : ByteArray = Assets.getBytes (_id); - var byteInput = new BytesInput ( bytes, 0, bytes.length); - var png = new Reader (byteInput).read (); - var data = Tools.extract32 (png); - var header = Tools.getHeader (png); - - imageWidth = header.width; - imageHeight = header.height; - imageData = new UInt8Array (data.getData ()); - - var image_length = imageWidth * imageHeight; - - //bytes are returned in a different order, bgra - //so we swap back to rgba - for(i in 0 ... image_length) { - - var b = imageData[i*4+0]; - var g = imageData[i*4+1]; - var r = imageData[i*4+2]; - var a = imageData[i*4+3]; - - imageData[i*4+0] = r; - imageData[i*4+1] = g; - imageData[i*4+2] = b; - imageData[i*4+3] = a; - - } - - onload(); - - } - -#end //!lime_html5 - - var loaded = false; - - public function ready (lime:Lime):Void { - - this.lime = lime; - - //we load the image with a callback, - //because on html5 it is asynchronous and we want - //to only try and use it when it's done loading - load_image("assets/lime.png", function(){ - - initializeShaders (); - - createBuffers (); - createTexture (); - - loaded = true; - - }); - - } - - - private function render ():Void { - - if(!loaded) { - return; - } - - GL.viewport (0, 0, lime.config.width, lime.config.height); - - GL.clearColor (1.0, 1.0, 1.0, 1.0); - GL.clear (GL.COLOR_BUFFER_BIT); - - var positionX = (lime.config.width - imageWidth) / 2; - var positionY = (lime.config.height - imageHeight) / 2; - - var projectionMatrix = Matrix3D.createOrtho (0, lime.config.width, lime.config.height, 0, 1000, -1000); - var modelViewMatrix = Matrix3D.create2D (positionX, positionY, 1, 0); - - GL.useProgram (shaderProgram); - GL.enableVertexAttribArray (vertexAttribute); - GL.enableVertexAttribArray (texCoordAttribute); - - GL.activeTexture (GL.TEXTURE0); - GL.bindTexture (GL.TEXTURE_2D, texture); - - 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.uniformMatrix3D (projectionMatrixUniform, false, projectionMatrix); - GL.uniformMatrix3D (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); - - GL.disableVertexAttribArray (vertexAttribute); - GL.disableVertexAttribArray (texCoordAttribute); - GL.useProgram (null); - - } - - -} diff --git a/samples/SimpleOpenGL/project.lime b/samples/SimpleOpenGL/project.lime deleted file mode 100644 index 10e2b868e..000000000 --- a/samples/SimpleOpenGL/project.lime +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - -