0

我一直在学习 stage3D,并且正在尝试第一次渲染一些东西。在这个程序的过程中没有出现运行时错误,但我没有看到任何输出......我的代码如下(必要时带有注释)

import flash.events.Event;
import flash.display.*;
import flash.display3D.*;
import flash.display3D.textures.Texture;
import stillicidium.rendering.MeshMaker;
import stillicidium.rendering.AGALMiniAssembler;

stage.scaleMode = 'noBorder';

var context0:Context3D;
var vBuff:VertexBuffer3D;
var iBuff:IndexBuffer3D;
var tex:Texture;

//MeshMaker is designed to make a stage-fitted n-by-n mesh with
//corresponding uv coords - form is like: (x, y, 0 ,u, v)
var mm:MeshMaker = new MeshMaker(this.stage, 20);
var vBuff_vec:Vector.<Number> = mm.GetVertexBuffer();
var iBuff_vec:Vector.<uint> = mm.GetIndexBuffer();
mm = null;

var vShader:AGALMiniAssembler = new AGALMiniAssembler();
var pShader:AGALMiniAssembler = new AGALMiniAssembler();
var program:Program3D;

//Create a shape for drawing
var square:Shape = new Shape();
square.graphics.lineStyle(3,0xffffff,1,true);
square.graphics.beginFill(0xaa00ff,1);
square.graphics.moveTo(100,100);
square.graphics.lineTo(stage.stageWidth-100,100);
square.graphics.lineTo(stage.stageWidth-100,stage.stageHeight-100);
square.graphics.lineTo(100,stage.stageHeight-100);
square.graphics.lineTo(100,100);

//Draw shape as BitmapData to use as texture
var bmpdata:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,true,0);
bmpdata.draw(square);

//Initialize stage3D
stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, initStage3D);
stage.stage3Ds[0].requestContext3D();

function initStage3D(e:Event):void {
    context0 = stage.stage3Ds[0].context3D;
    context0.configureBackBuffer(stage.stageWidth, stage.stageHeight, 4, true);

    vBuff = context0.createVertexBuffer(0.2 * vBuff_vec.length, 5);
    vBuff.uploadFromVector(vBuff_vec, 0, 0.2 * vBuff_vec.length);
    vBuff_vec = null;

    iBuff = context0.createIndexBuffer(iBuff_vec.length);
    iBuff.uploadFromVector(iBuff_vec, 0, iBuff_vec.length);
    iBuff_vec = null;

    tex = context0.createTexture(bmpdata.width,bmpdata.height,'bgra',false);
    tex.uploadFromBitmapData(bmpdata,0);

    //Passes vertex buffer 1 to fragment shader
    //Outputs vertex buffer 0
    vShader.assemble('vertex', 'mov v0 va1 \n'+'mov op va0');
    //Textures using data from vertex shader and sends to temporary register
    //Outputs temporary register
    pShader.assemble('fragment', 'tex ft0 v0 fs0 <2d,linear,nomip> \n'+'mov oc ft0');

    program = context0.createProgram();
    program.upload(vShader.agalcode, pShader.agalcode);

    addEventListener(Event.ENTER_FRAME, render);
}

function render(e:Event):void {
    if (!context0) { return; }
    context0.clear();

    //(x,y,0) to vertex buffer 0, (u,v) to vertex buffer 1
    context0.setVertexBufferAt(0, vBuff, 0, 'float3');
    context0.setVertexBufferAt(1, vBuff, 3, 'float2');
    context0.setTextureAt(0, tex);
    context0.setProgram(program);

    context0.drawTriangles(iBuff);
    context0.present();
}

我已经将此与几个在线示例进行了比较,并且没有发现任何差异。我在想可能有一些我忽略的设置,或者我缺少的要求......不过我迷路了。想法?

4

1 回答 1

0

网格大小不正确 - 我阅读的教程没有提到用作顶点着色器输出的 x、y 和 z 值介于 -1 和 1 之间。有危险猜测:我的网格落在了正在渲染的区域之外,并且所有在裁剪视口的渲染阶段,多边形丢失了。

于 2014-03-18T03:15:16.033 回答