Created
January 12, 2013 18:32
-
-
Save ryzed/4519796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import flash.display.Stage; | |
import flash.display.Stage3D; | |
import flash.display.StageAlign; | |
import flash.display.StageScaleMode; | |
import flash.display3D.Context3D; | |
import flash.display3D.Context3DCompareMode; | |
import flash.display3D.Context3DTriangleFace; | |
import flash.display3D.IndexBuffer3D; | |
import flash.display3D.VertexBuffer3D; | |
import flash.events.Event; | |
import flash.geom.Vector3D; | |
import flash.Lib; | |
import flash.Vector; | |
import ryz.engine.shaders.ShFSQ; | |
/** | |
* ... | |
* @author ryz | |
*/ | |
class Main | |
{ | |
var stage2d:Stage; | |
var stage3d:Stage3D; | |
var ctx3d:Context3D; | |
var vbuf:VertexBuffer3D; | |
var ibuf:IndexBuffer3D; | |
var shFSQ:ShFSQ; | |
public function new() | |
{ | |
stage2d = Lib.current.stage; | |
stage3d = stage2d.stage3Ds[0]; | |
stage3d.addEventListener( Event.CONTEXT3D_CREATE, onGetContext3d ); | |
stage3d.requestContext3D(); | |
} | |
private function onGetContext3d(e:Event):Void | |
{ | |
trace('got context'); | |
stage3d.removeEventListener( Event.CONTEXT3D_CREATE, onGetContext3d ); | |
ctx3d = stage3d.context3D; | |
ctx3d.enableErrorChecking = true; | |
ctx3d.configureBackBuffer( 640, 480, 0, false ); | |
ctx3d.setDepthTest(false, Context3DCompareMode.NEVER); | |
ctx3d.setCulling(Context3DTriangleFace.NONE); | |
shFSQ = new ShFSQ(ctx3d); | |
var vb = new Vector<Float>(); | |
vb.push(0); vb.push(0); | |
vb.push(0); vb.push(1); | |
vb.push(1); vb.push(0); | |
vbuf = ctx3d.createVertexBuffer(3, 2); | |
vbuf.uploadFromVector(vb, 0, 3); | |
var ib = new Vector<UInt>(); | |
ib.push(0); | |
ib.push(1); | |
ib.push(2); | |
ibuf = ctx3d.createIndexBuffer(3); | |
ibuf.uploadFromVector(ib, 0, 3); | |
stage2d.addEventListener(Event.ENTER_FRAME, onFrame); | |
} | |
private function onFrame(e:Event):Void | |
{ | |
ctx3d.clear(0.1, 0.2, 0.3); | |
var clrRed = new Vector3D(1, 0, 0, 0); | |
shFSQ.init( { dx:0 }, { aclr:clrRed} ); | |
shFSQ.draw(vbuf, ibuf); | |
var clrGreen = new Vector3D(0, 1, 0, 0); | |
shFSQ.init( { dx:-0.1 }, { aclr:clrGreen} ); | |
shFSQ.draw(vbuf, ibuf); | |
ctx3d.present(); | |
} | |
static function main() | |
{ | |
var stage = Lib.current.stage; | |
stage.scaleMode = StageScaleMode.NO_SCALE; | |
stage.align = StageAlign.TOP_LEFT; | |
// entry point | |
new Main(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ryz.engine.shaders; | |
import hxsl.Shader; | |
/** | |
* ... | |
* @author ryz | |
*/ | |
class ShFSQ extends Shader | |
{ | |
21static var SRC = | |
{ | |
var input : | |
{ | |
pos : Float2 | |
}; | |
function vertex(dx:Float) | |
{ | |
out = [pos.x+dx, pos.y, 0, 1]; | |
} | |
function fragment(aclr:Float4) | |
{ | |
out = aclr; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment