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:


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?


2 Answers 2


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.


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.

  • $\begingroup$ Altough it could be used to other things $\endgroup$
    – joojaa
    Sep 11, 2016 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.