<p>Your screen isn't 3D, so how do you display 3D objects on it? You need to map 3D coordinates into 2D space. This also explains why your OpenGL code is not behaving how you're expecting it to. Sorry if parts of this answer are things you already know (just trying to be comprehensive).</p>

<h1>What do the model view and projection matrices do?</h1>

<p>The <strong>model view</strong> matrix is actually two matrices (multiplied together): the model matrix and the view matrix. This is important to understanding because these are two transformations into different spaces.</p>

<p>The <strong>model</strong> matrix transforms model space into world space. This means that say you have a vertex is at an offset from the center of a model. If you want that vertex to be in world space, it must use the scale, rotation, and position of the model to determine this. The model matrix accomplishes this.</p>

<p>The <strong>view</strong> matrix transforms the world space into the camera space. Does world move or does the camera move in a 3D application? Well, actually the world moves around the camera. The camera is always at the origin, so the view matrix moves the world to this point.</p>

<p>The <strong>projection</strong> matrix might be the trickiest to visualize. Screens are 2D (technicalities aside), so how do we show 3D objects here? A projection matrix converts 3D coordinates into 2D coordinates (with depth, so still technically 3D). You end up with Normalized Device Coordinates (NDCs). Each vertex on screen is represented by three values:
* x (horizontal) ranging from [-1, 1]
* y (vertical) ranging from [-1, 1]
* z (depth) ranging from [-1, 1]</p>

<h1>Why don't you need model-view and projection matrices?</h1>

<p>It's not that you don't need them, it's just that you are using as explained in the last step above. Otherwise, you are effectively just rendering 2D graphics. Right now you are drawing a quad.</p>

<p>Look at the coordinates that you are providing. You are basically treating the vertices as 2D vertices for 2D graphics since you are directly specifying their coordinates in NDC space. Remember, the coordinates you picked are between -1 and 1 for x and y, so you are effectively treating them as NDCs. You directly send them to the rasterizer in your example.</p>

<h1>Further Reading</h1>

<ul>
<li><a href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/" rel="nofollow noreferrer">Tutorial 3 : Matrices | opengl-tutorial.org</a></li>
<li><a href="http://learnopengl.com/#!Getting-started/Coordinate-Systems" rel="nofollow noreferrer">Coordinate Systems | LearnOpenGL.com</a></li>
<li><a href="http://www.songho.ca/opengl/gl_projectionmatrix.html" rel="nofollow noreferrer">OpenGL Projection Matrix | songho.ca</a></li>
</ul>

CC BY-SA 3.0
2016-09-28T01:07:49.037Z
2018-04-19T07:52:09.913Z
2018-04-19T07:52:09.913Z
aces
<p>So I've been learning opengl for some weeks now and managed to understand all the viewing pipelines. As far my understanding goes we need to bring the object to world space and then the world space to view space. After that the clipping is done by any of the two projections as we want. The clipping volume is then sent to the viewport which is mapped to the screen coordinates.</p>

<p>Now when I write this simple basic code below I don't use any of the matrixmode
(GL_MODElVIEW or  GL_PROJECTION) but still the primitive is displayed on the screen. So what am I missing here? </p>

<p>and also an extension to this question I would also like to know what exactly means to bring the object to world coordinates in theory. Does it means overlapping the axes of the object coordinates with the world coordinates.  </p>

<p>With lot of opengl discussions out there I don't know where to look. Would be extra nice if someone refer me to some good articles. </p>

<pre><code>void Di()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_QUADS) ;           
       glColor3f ( 1.0, 0.3, 0.2);     
        glVertex2f( -0.1, -0.1 );       
        glVertex2f(  0.1, -0.1 );       
        glVertex2f(  0.1,  0.1 ); 
        glVertex2f( -0.1,  0.1 ); 
       glEnd();
    glFlush();
}

int main( int argc, char** argv)
{
    glutInit( &amp;argc, argv);

    glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);

    glutInitWindowSize(500,500);

    glutInitWindowPosition(0,0);

    glutCreateWindow("First Program");

    glutDisplayFunc(Di);
    glutMainLoop();
}
</code></pre>

CC BY-SA 3.0
2016-09-28T14:48:12.493Z
Also just for your information you are learning [legacy OpenGL](https://www.opengl.org/wiki/Legacy_OpenGL) which is obsolete since 2008. Since your spending effort in learning atleast go and learn relevant OpenGL. No you do not nedd matrices but the alternative is more painful.
joojaa
CC BY-SA 3.0
2016-09-29T06:03:09.253Z
I didn't know that but anyway the legacy OpenGL is a manadatory course for me. But I will most certainly learn the new one.
Broskiee
CC BY-SA 3.0
2016-09-29T06:26:45.230Z
Sounds weird, there are lot of devices that will never support legacy openGL. Like your mobile phone, and even desktops will see a gradual phasing out of legacy OpenGL. So no new code should be made with legacy openGL for any reason, including teaching.
joojaa
CC BY-SA 3.0
2016-09-29T07:09:23.670Z
Like I said I've been learning opengl for a few weeks now and since it is a one year course I definately believe I will get to opengl4.5  later . And It is not weird at all because University education also  focus on teaching older stuff along with the newer stuff.
Broskiee
CC BY-SA 3.0
2016-09-29T07:21:06.540Z
No, it's definitely not ok. There is no concepts that the old way does that the new way does not do. Theres absolutely no need for you to learn how to send data and use fixed pipeline programming, it does not even change all that much. In fact if you were not using the fixed pipeline you wouldn't have this question. All your doing is learning an API that nolonger should be used, i mean ist fine if you learned how to blit colors on a c64 also in the course bit other than that no benefit, other than perhaps knowing the difference.
joojaa
CC BY-SA 3.0
2016-09-29T07:26:51.037Z
you know what I'm gonna leave you to  argue that with the education board.
Broskiee
CC BY-SA 3.0
2016-09-29T07:27:03.957Z
Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/46057/discussion-between-joojaa-and-neolardo-va-dinci).
joojaa
<opengl><3d><2d-graphics><legacy-opengl>
What if we don't mention Modelview and projection matrix?
Broskiee
# What if we don't mention Modelview and projection matrix?

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

So I've been learning opengl for some weeks now and managed to understand all the viewing pipelines. As far my understanding goes we need to bring the object to world space and then the world space to view space. After that the clipping is done by any of the two projections as we want. The clipping volume is then sent to the viewport which is mapped to the screen coordinates.

Now when I write this simple basic code below I don't use any of the matrixmode
(GL\_MODElVIEW or GL\_PROJECTION) but still the primitive is displayed on the screen. So what am I missing here?

and also an extension to this question I would also like to know what exactly means to bring the object to world coordinates in theory. Does it means overlapping the axes of the object coordinates with the world coordinates.

With lot of opengl discussions out there I don't know where to look. Would be extra nice if someone refer me to some good articles.

```
void Di()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_QUADS) ;           
       glColor3f ( 1.0, 0.3, 0.2);     
        glVertex2f( -0.1, -0.1 );       
        glVertex2f(  0.1, -0.1 );       
        glVertex2f(  0.1,  0.1 ); 
        glVertex2f( -0.1,  0.1 ); 
       glEnd();
    glFlush();
}

int main( int argc, char** argv)
{
    glutInit( &argc, argv);

    glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);

    glutInitWindowSize(500,500);

    glutInitWindowPosition(0,0);

    glutCreateWindow("First Program");

    glutDisplayFunc(Di);
    glutMainLoop();
}

```

**Tags:** opengl, 3d, 2d-graphics, legacy-opengl

> **Comments:**
> **username_1**: Also just for your information you are learning [legacy OpenGL](https://www.opengl.org/wiki/Legacy_OpenGL) which is obsolete since 2008. Since your spending effort in learning atleast go and learn relevant OpenGL. No you do not nedd matrices but the alternative is more painful.  
> **username_0**: I didn't know that but anyway the legacy OpenGL is a manadatory course for me. But I will most certainly learn the new one.  
> **username_1**: Sounds weird, there are lot of devices that will never support legacy openGL. Like your mobile phone, and even desktops will see a gradual phasing out of legacy OpenGL. So no new code should be made with legacy openGL for any reason, including teaching.  
> **username_0**: Like I said I've been learning opengl for a few weeks now and since it is a one year course I definately believe I will get to opengl4.5  later . And It is not weird at all because University education also  focus on teaching older stuff along with the newer stuff.  
> **username_1**: No, it's definitely not ok. There is no concepts that the old way does that the new way does not do. Theres absolutely no need for you to learn how to send data and use fixed pipeline programming, it does not even change all that much. In fact if you were not using the fixed pipeline you wouldn't have this question. All your doing is learning an API that nolonger should be used, i mean ist fine if you learned how to blit colors on a c64 also in the course bit other than that no benefit, other than perhaps knowing the difference.  
> **username_0**: you know what I'm gonna leave you to  argue that with the education board.  
> **username_1**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/46057/discussion-between-username_1-and-neolardo-va-dinci).  

---

## 1 answers

### Answer by username_2 on 2016-09-28. Score: 6 | Accepted answer

Your screen isn't 3D, so how do you display 3D objects on it? You need to map 3D coordinates into 2D space. This also explains why your OpenGL code is not behaving how you're expecting it to. Sorry if parts of this answer are things you already know (just trying to be comprehensive).

# What do the model view and projection matrices do?

The **model view** matrix is actually two matrices (multiplied together): the model matrix and the view matrix. This is important to understanding because these are two transformations into different spaces.

The **model** matrix transforms model space into world space. This means that say you have a vertex is at an offset from the center of a model. If you want that vertex to be in world space, it must use the scale, rotation, and position of the model to determine this. The model matrix accomplishes this.

The **view** matrix transforms the world space into the camera space. Does world move or does the camera move in a 3D application? Well, actually the world moves around the camera. The camera is always at the origin, so the view matrix moves the world to this point.

The **projection** matrix might be the trickiest to visualize. Screens are 2D (technicalities aside), so how do we show 3D objects here? A projection matrix converts 3D coordinates into 2D coordinates (with depth, so still technically 3D). You end up with Normalized Device Coordinates (NDCs). Each vertex on screen is represented by three values:
\* x (horizontal) ranging from [-1, 1]
\* y (vertical) ranging from [-1, 1]
\* z (depth) ranging from [-1, 1]

# Why don't you need model-view and projection matrices?

It's not that you don't need them, it's just that you are using as explained in the last step above. Otherwise, you are effectively just rendering 2D graphics. Right now you are drawing a quad.

Look at the coordinates that you are providing. You are basically treating the vertices as 2D vertices for 2D graphics since you are directly specifying their coordinates in NDC space. Remember, the coordinates you picked are between -1 and 1 for x and y, so you are effectively treating them as NDCs. You directly send them to the rasterizer in your example.

# Further Reading

* [Tutorial 3 : Matrices | opengl-tutorial.org](http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/)
* [Coordinate Systems | LearnOpenGL.com](http://learnopengl.com/#!Getting-started/Coordinate-Systems)
* [OpenGL Projection Matrix | songho.ca](http://www.songho.ca/opengl/gl_projectionmatrix.html)


---

