<p>The transform matrix allows you to translate, rotate or resize your model. From the model's point of view, its vertices always are at the same position. But if you multiply the vertices with, let us say a translation matrix, they all get moved. Seen from the model's origin, they are still at the same position. But in world space, your whole model has moved.
The reason that changing the code did nothing to how the cube was presented to you lies in your transformation matrix not applying any changes to the cube's model data.
If you choose a different transformation matrix, things will look differently.</p>

CC BY-SA 3.0
2016-09-12T07:59:16.487Z
2016-09-12T07:59:16.487Z
Djindjidj
<p>The transform matrix will be a uniform which is easier to update and upload to the gpu (just a single glUniform call) than applying the transform to all vertices on the cpu and uploading the new vertices. Especially with large models.</p>

CC BY-SA 3.0
2016-09-11T20:09:51.170Z
Altough it could be used to other things
joojaa
CC BY-SA 3.0
2016-09-11T19:12:39.433Z
2016-09-11T19:12:39.433Z
ratchet freak
<p>I'm trying to understand OpenGL by using Processing OpenGL ES.</p>

<p>If I have an example Cube to render.</p>

<p>I've read that a vertex shader will be run once for each Vertex. The fragment shader will be run (at least) once for each pixel. </p>

<p>In a vertex shader I have:</p>

<pre><code>#define PROCESSING_COLOR_SHADER


uniform mat4 transform;

attribute vec4 vertex;
attribute vec4 color;

varying vec4 col;


void main(){

    gl_Position = vertex;

    col = color;
}
</code></pre>

<p>In a fragment shader I have:</p>

<pre><code>gl_FragColor = col;
</code></pre>

<p>When ran, it creates a simple painted cube of the colour defined in the Processing sketch. However, if I change the vertex shader to...</p>

<pre><code>gl_Position = vertex
</code></pre>

<p>(instead of transform*vertex) it draws a wireframe cube in exactly the same place. What exactly does the transform matrix do? </p>

<glsl>
OpenGL: Purpose of transform matrix in Vertex shader where transform*vertex
user3168961
# OpenGL: Purpose of transform matrix in Vertex shader where transform*vertex

(Asked by: username_0 on 2016-09-11)

I'm trying to understand OpenGL by using Processing OpenGL ES.

If I have an example Cube to render.

I've read that a vertex shader will be run once for each Vertex. The fragment shader will be run (at least) once for each pixel.

In a vertex shader I have:

```
#define PROCESSING_COLOR_SHADER

uniform mat4 transform;

attribute vec4 vertex;
attribute vec4 color;

varying vec4 col;

void main(){

    gl_Position = vertex;

    col = color;
}

```

In a fragment shader I have:

```
gl_FragColor = col;

```

When ran, it creates a simple painted cube of the colour defined in the Processing sketch. However, if I change the vertex shader to...

```
gl_Position = vertex

```

(instead of transform\*vertex) it draws a wireframe cube in exactly the same place. What exactly does the transform matrix do?

**Tags:** glsl


---

## 2 answers

### Answer by username_1 on 2016-09-12. Score: 2 | Accepted answer

The transform matrix allows you to translate, rotate or resize your model. From the model's point of view, its vertices always are at the same position. But if you multiply the vertices with, let us say a translation matrix, they all get moved. Seen from the model's origin, they are still at the same position. But in world space, your whole model has moved.
The reason that changing the code did nothing to how the cube was presented to you lies in your transformation matrix not applying any changes to the cube's model data.
If you choose a different transformation matrix, things will look differently.


---

### Answer by username_2 on 2016-09-11. Score: 2

The transform matrix will be a uniform which is easier to update and upload to the gpu (just a single glUniform call) than applying the transform to all vertices on the cpu and uploading the new vertices. Especially with large models.

> **Comments:**
> **username_3**: Altough it could be used to other things  

---

