forked from qt-creator/qt-creator
Update Canvas3D project wizard templates
Added new version of three.js that supports Quick items as textures, and unified how three.js and non-three.js examples generated by the wizard look like. Both now display just a plain green cube. Change-Id: Iedc2498853aa078fe072083ab06a27d1ed04d982 Task-number: QTCREATORBUG-14824 Task-number: QTCREATORBUG-14825 Task-number: QTBUG-47961 Reviewed-by: Tomi Korpipää <tomi.korpipaa@theqtcompany.com> Reviewed-by: Pasi Keränen <pasi.keranen@digia.com> Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Draws a cube that has different colors assigned to the vertices.
|
// Draws a plain green cube.
|
||||||
// Each face of the cube has the linear interpolation of the corner colors.
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var gl;
|
var gl;
|
||||||
@@ -8,10 +7,8 @@ var vertexPositionAttrLoc;
|
|||||||
var shaderProgram;
|
var shaderProgram;
|
||||||
var cubeVertexPositionBuffer;
|
var cubeVertexPositionBuffer;
|
||||||
var cubeVertexIndexBuffer;
|
var cubeVertexIndexBuffer;
|
||||||
var cubeVertexColorBuffer;
|
|
||||||
var vertexShader;
|
var vertexShader;
|
||||||
var fragmentShader;
|
var fragmentShader;
|
||||||
var vertexColorAttrLoc;
|
|
||||||
var pMatrixUniformLoc;
|
var pMatrixUniformLoc;
|
||||||
var mvMatrixUniformLoc;
|
var mvMatrixUniformLoc;
|
||||||
|
|
||||||
@@ -26,7 +23,6 @@ function initializeGL(canvas) {
|
|||||||
|
|
||||||
// Setup the OpenGL state
|
// Setup the OpenGL state
|
||||||
gl.enable(gl.DEPTH_TEST);
|
gl.enable(gl.DEPTH_TEST);
|
||||||
gl.enable(gl.DEPTH_WRITE);
|
|
||||||
gl.depthMask(true);
|
gl.depthMask(true);
|
||||||
gl.enable(gl.CULL_FACE);
|
gl.enable(gl.CULL_FACE);
|
||||||
gl.cullFace(gl.BACK);
|
gl.cullFace(gl.BACK);
|
||||||
@@ -35,7 +31,7 @@ function initializeGL(canvas) {
|
|||||||
// Set viewport
|
// Set viewport
|
||||||
gl.viewport(0, 0, canvas.width * canvas.devicePixelRatio, canvas.height * canvas.devicePixelRatio);
|
gl.viewport(0, 0, canvas.width * canvas.devicePixelRatio, canvas.height * canvas.devicePixelRatio);
|
||||||
|
|
||||||
// Initialize vertex and color buffers
|
// Initialize vertex and element array buffers
|
||||||
initBuffers();
|
initBuffers();
|
||||||
|
|
||||||
// Initialize the shader program
|
// Initialize the shader program
|
||||||
@@ -78,17 +74,13 @@ function paintGL(canvas) {
|
|||||||
gl.enableVertexAttribArray(vertexPositionAttrLoc);
|
gl.enableVertexAttribArray(vertexPositionAttrLoc);
|
||||||
gl.vertexAttribPointer(vertexPositionAttrLoc, 3, gl.FLOAT, false, 0, 0);
|
gl.vertexAttribPointer(vertexPositionAttrLoc, 3, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexColorBuffer);
|
|
||||||
gl.enableVertexAttribArray(vertexColorAttrLoc);
|
|
||||||
gl.vertexAttribPointer(vertexColorAttrLoc, 4, gl.FLOAT, false, 0, 0);
|
|
||||||
|
|
||||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
|
||||||
gl.drawElements(gl.TRIANGLES, 36, gl.UNSIGNED_SHORT, 0);
|
gl.drawElements(gl.TRIANGLES, 36, gl.UNSIGNED_SHORT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initBuffers() {
|
function initBuffers() {
|
||||||
// Create a cubeVertexPositionBuffer and put a single clipspace rectangle in
|
// Create a buffer for cube vertices. Since we are not using textures, we don't need unique
|
||||||
// it (2 triangles)
|
// vertices for each face. We can define the cube using 8 vertices.
|
||||||
cubeVertexPositionBuffer = gl.createBuffer();
|
cubeVertexPositionBuffer = gl.createBuffer();
|
||||||
cubeVertexPositionBuffer.name = "cubeVertexPositionBuffer";
|
cubeVertexPositionBuffer.name = "cubeVertexPositionBuffer";
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
|
||||||
@@ -107,6 +99,8 @@ function initBuffers() {
|
|||||||
]),
|
]),
|
||||||
gl.STATIC_DRAW);
|
gl.STATIC_DRAW);
|
||||||
|
|
||||||
|
// Create buffer for element array indices. We define six sides, each composed of two
|
||||||
|
// triangles, using the vertices defined above.
|
||||||
cubeVertexIndexBuffer = gl.createBuffer();
|
cubeVertexIndexBuffer = gl.createBuffer();
|
||||||
cubeVertexIndexBuffer.name = "cubeVertexIndexBuffer";
|
cubeVertexIndexBuffer.name = "cubeVertexIndexBuffer";
|
||||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
|
||||||
@@ -131,36 +125,17 @@ function initBuffers() {
|
|||||||
6, 2, 1
|
6, 2, 1
|
||||||
]),
|
]),
|
||||||
gl.STATIC_DRAW);
|
gl.STATIC_DRAW);
|
||||||
|
|
||||||
cubeVertexColorBuffer = gl.createBuffer();
|
|
||||||
cubeVertexColorBuffer.name = "cubeVertexColorBuffer";
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexColorBuffer);
|
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([// front
|
|
||||||
0.000, 1.000, 0.000,
|
|
||||||
1.000, 0.000, 1.000,
|
|
||||||
1.000, 1.000, 0.000,
|
|
||||||
1.000, 0.000, 0.000,
|
|
||||||
// back
|
|
||||||
0.435, 0.602, 0.223,
|
|
||||||
0.310, 0.747, 0.185,
|
|
||||||
1.000, 1.000, 1.000,
|
|
||||||
0.000, 0.000, 1.000
|
|
||||||
]), gl.STATIC_DRAW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initShaders() {
|
function initShaders() {
|
||||||
vertexShader = getShader(gl, "attribute highp vec3 aVertexPosition; \
|
vertexShader = getShader(gl, "attribute highp vec3 aVertexPosition; \
|
||||||
attribute highp vec4 aVertexColor; \
|
|
||||||
uniform highp mat4 uMVMatrix; \
|
uniform highp mat4 uMVMatrix; \
|
||||||
uniform highp mat4 uPMatrix; \
|
uniform highp mat4 uPMatrix; \
|
||||||
varying highp vec4 vColor; \
|
|
||||||
void main(void) { \
|
void main(void) { \
|
||||||
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \
|
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \
|
||||||
vColor = aVertexColor; \
|
|
||||||
}", gl.VERTEX_SHADER);
|
}", gl.VERTEX_SHADER);
|
||||||
fragmentShader = getShader(gl, "varying highp vec4 vColor; \
|
fragmentShader = getShader(gl, "void main(void) { \
|
||||||
void main(void) { \
|
gl_FragColor = vec4(0.5, 0.76, 0.26, 1.0); \
|
||||||
gl_FragColor = vColor; \
|
|
||||||
}", gl.FRAGMENT_SHADER);
|
}", gl.FRAGMENT_SHADER);
|
||||||
|
|
||||||
shaderProgram = gl.createProgram();
|
shaderProgram = gl.createProgram();
|
||||||
@@ -179,8 +154,6 @@ function initShaders() {
|
|||||||
// look up where the vertex data needs to go.
|
// look up where the vertex data needs to go.
|
||||||
vertexPositionAttrLoc = gl.getAttribLocation(shaderProgram, "aVertexPosition");
|
vertexPositionAttrLoc = gl.getAttribLocation(shaderProgram, "aVertexPosition");
|
||||||
gl.enableVertexAttribArray(vertexPositionAttrLoc);
|
gl.enableVertexAttribArray(vertexPositionAttrLoc);
|
||||||
vertexColorAttrLoc = gl.getAttribLocation(shaderProgram, "aVertexColor");
|
|
||||||
gl.enableVertexAttribArray(vertexColorAttrLoc);
|
|
||||||
|
|
||||||
pMatrixUniformLoc = gl.getUniformLocation(shaderProgram, "uPMatrix");
|
pMatrixUniformLoc = gl.getUniformLocation(shaderProgram, "uPMatrix");
|
||||||
pMatrixUniformLoc.name = "pMatrixUniformLoc";
|
pMatrixUniformLoc.name = "pMatrixUniformLoc";
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,7 @@ function initializeGL(canvas) {
|
|||||||
shading: THREE.SmoothShading });
|
shading: THREE.SmoothShading });
|
||||||
var cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
|
var cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
|
||||||
cube = new THREE.Mesh(cubeGeometry, material);
|
cube = new THREE.Mesh(cubeGeometry, material);
|
||||||
|
cube.rotation.set(0.785, 0.785, 0.0);
|
||||||
scene.add(cube);
|
scene.add(cube);
|
||||||
|
|
||||||
renderer = new THREE.Canvas3DRenderer(
|
renderer = new THREE.Canvas3DRenderer(
|
||||||
@@ -29,8 +30,5 @@ function resizeGL(canvas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function paintGL(canvas) {
|
function paintGL(canvas) {
|
||||||
cube.rotation.x += 0.01;
|
|
||||||
cube.rotation.y += 0.01;
|
|
||||||
|
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user