### android

#### How can I draw two squares side by side?

```Following the android OpenGL ES tutorial, I can draw a square to the screen.
I'd like to draw a second square to the screen, beside the initial square, so I've done as follows (only twice):
Matrix.setLookAtM(mViewMatrix, 0, 0, 0, 3.0f, 0, 0, 0, 0, 1.0f, 0);
float[] modelMatrix = new float[16];
Matrix.setIdentityM(modelMatrix, 0);
Matrix.translateM(modelMatrix, 0, 2, 2, 0); //arbitrarily picking 2, the correctly drawn square uses 0's.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, modelMatrix, 0)
Matrix.multiplyMM(mMVPMatrix, 0, mMVPMatrix, 0, mProjMatrix, 0);
and then proceed to draw it (link to google's code)
notably:
private final String vertexShaderCode =
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"void main() {" +
" gl_Position = vPosition * uMVPMatrix;" +
"}";
and
GLES20.glViewport(0, 0, width, height);
float ratio = (float) width / height;
Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
However, my second square is skewed like so:
Why is this the case? How can I simply draw a square beside this one, without modifying the initial coordinates?
My suspicion is it has something to do with Matrix.setLookAtM(), and that the projection is reshaping the square. I'm not sure how to go about fixing this however!
```
```This thread solved my issue.
In the shader, I was multiplying by
vPosition * uMVPMatrix;"
but the multiplications should follow the ordering:
transformed vertex = projMatrix * viewMatrix * modelMatrix * input vertex
note that input vertex comes after the projection, view and model matrix (MVPMatrix)
So switching to
vPosition * uMVPMatrix;
and
float[] pvMatrix = new float[16];
//projection * view
Matrix.multiplyMM(pvMatrix, 0, mProjMatrix, 0, mViewMatrix, 0);
float[] mModelMatrix = new float[16];
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.scaleM(mModelMatrix,0, mScale[0],mScale[1], 1.0f);
Matrix.translateM(mModelMatrix, 0, mPosition[0],mPosition[1], mPosition[2]);
//projection * view * model
Matrix.multiplyMM(mMVPMatrix,0, pvMatrix, 0, mModelMatrix, 0);
Did the trick!```

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App