-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
145 lines (113 loc) · 3.49 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require.config({
paths:{
jquery : './thirdparty/jquery-1.11.0'
},
baseUrl:'Source'
});
require(
[
'jquery',
'Core/Vector3D',
'Core/Geodetic2D',
'Core/Geodetic3D',
'Core/Ellipsoid',
'Core/PrimitiveType',
'Renderer/Camera',
'Renderer/Color',
'Renderer/BufferHint',
'Renderer/RenderState',
'Renderer/SceneState',
'Renderer/ClearState',
'Renderer/Device',
'Renderer/Mesh',
'Renderer/VertexAttribute',
'Renderer/Indices',
'Renderer/DrawState',
'Renderer/Input/Mouse'
],
function
(
$,
Vector3D,
Geodetic2D,
Geodetic3D,
Ellipsoid,
PrimitiveType,
Camera,
Color,
BufferHint,
RenderState,
SceneState,
ClearState,
Device,
Mesh,
VertexAttribute,
Indices,
DrawState,
Mouse
)
{
var Triangle = function(){
this._flag = false;
this._name = 'test Trianlge';
this._device = new Device("canvas");
this._window = this._device.CreateWindow(680,680,'tttt');
var shaderProgram = this._device.CreateProgramFromID("shader-vs","shader-fs");
this._sceneState = new SceneState();
this._clearState = new ClearState();
this._clearState.Color = Color.FromRgba(0.0,0.0,0.0,1.0);
//this._mouse = new Mouse(this._device._canvas);
this._window.RenderFrameHandler = (function(that){
var triangle = that;
return function(){
triangle.OnRenderFrame();
};
})(this);
/////////////////////////////////////////////////
var mesh = new Mesh();
var positionAttribute = new VertexAttribute('aVertexPosition');
//mesh.Attributes.push(positionAttribute);
mesh.Attributes['aVertexPosition'] = positionAttribute;
var indices = new Indices();
mesh.Indices = indices;
var positions = positionAttribute.Values;
positions.push(new Vector3D(0,0,0));
positions.push(new Vector3D(1,0,0));
positions.push(new Vector3D(0,1,0));
positions.push(new Vector3D(0,0,0));
positions.push(new Vector3D(-1,0,0));
positions.push(new Vector3D(0,-1,0));
indices.AddTriangle(0,1,2);
indices.AddTriangle(3,4,5);
var va = this._window.Context.CreateVertexArray(mesh,shaderProgram.VertexAttributes,BufferHint.StaticDraw);
var image = new Image();
var texture = null;
var that = this;
image.onload = function(){
texture = that._device.CreateTexture2D(image);
that._window.Context.TextureUnits.GetTextureUnitByIndex(0).Texture = texture;
that._flag = true;
};
image.src = 'Examples/img/crate.gif';
/////////////////////////////////////////////////////
var renderState = new RenderState();
renderState.FacetCulling.Enabled = false;
renderState.DepthTest.Enabled = false;
this._drawState = new DrawState(this._renderState,shaderProgram,va);
this._sceneState.Camera.zoomToTarget(1);
};
Triangle.prototype.OnRenderFrame = function(){
var context = this._window.Context;
context.Clear(this._clearState);
if(this._flag){
context.Draw(PrimitiveType.Triangles,this._drawState,this._sceneState);
}
console.log(this._name);
};
Triangle.prototype.Run = function(updateRate){
this._window.Run(updateRate);
};
var example = new Triangle();
example.Run(60);
console.log('ok.');
});