Hello, I’m trying to learn how to use cesium rendering.
I’ve been trying to create a vary simple primitive that will just draw a simple line and go from there.
I’ve created an update method that creates a vertexArray with 2 points, then I create a simple Vshader and a Fshader and a draw command.
I get no errors and cesium continues normally but I dont see the line anywhere, can anyone please try and help me?
update(frameState) {
if (!this._show) {
return;
}
let context = frameState.context;
let vertexArray = this.createVertexArray(context);
this._shaderProgram = Cesium.ShaderProgram.replaceCache({
context: context,
shaderProgram: this._shaderProgram,
vertexShaderSource: `
attribute vec3 position;
void main() {
gl_Position = czm_modelViewProjection * vec4(position, 1.0);
}
`,
fragmentShaderSource: `
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}`
});
this._renderState = Cesium.RenderState.fromCache({
cull: {
enabled: true,
face: Cesium.CullFace.FRONT
},
depthTest: {
enabled: false
},
depthMask: true,
blending: undefined
});
this._drawCommand.modelMatrix = this._computedModelMatrix;
this._drawCommand.renderState = this._renderState;
this._drawCommand.shaderProgram = this._shaderProgram;
this._drawCommand.vertexArray = vertexArray;
this._drawCommand.pass = Cesium.Pass.OVERLAY;
let commandList = frameState.commandList;
commandList.push(this._drawCommand);
}
private createVertexArray(context: any) {
var vertexBuffer = Cesium.Buffer.createVertexBuffer({
context: context,
typedArray:new Float32Array([3648448.5117112226, 997327.3223067619, 5118713.136337872, 0.0332181295, 0.284035355, 0.431658396]),
usage: Cesium.BufferUsage.STATIC_DRAW
});
var indexBuffer = Cesium.Buffer.createIndexBuffer({
context: context,
typedArray: new Uint16Array([0,1]),
usage: Cesium.BufferUsage.STATIC_DRAW,
indexDatatype: Cesium.IndexDatatype.UNSIGNED_SHORT
});
let attributes = [
{
index: 0,
enabled: true,
vertexBuffer: vertexBuffer,
componentsPerAttribute: 3,
componentDatatype : Cesium.ComponentDatatype.FLOAT,
normalize: false,
offsetInBytes: 0,
strideInBytes: 0
}
];
return new Cesium.VertexArray({context:context, attributes:attributes, indexBuffer:indexBuffer});
}