PDA

View Full Version : What is the idea of this code



Cristi
05-19-2017, 04:07 AM
Hey guys,

I have here a very simple code in openGL and i don't understand what does:


void reshape(int x, int y)
{
glViewport(0, 0, x, y);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
}


I have read on the internet about glMatrixMode but i have not understand very well how this works.
Also if i delete


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


The final scene doesn't change.
Thank you in advance.

Dark Photon
05-19-2017, 05:55 AM
Understanding how matrix transforms work and how to use modeling, viewing, projection, and viewport transforms work is pretty key to rendering with OpenGL. You should definitely spend some quality time reading up on this. You'll be glad you did.

The OpenGL Programming Guide (https://www.amazon.com/OpenGL-Programming-Guide-Official-Learning/dp/0134495497) at one time had a very good description of how these transformations work and how to think about them (it may still in recent versions, but I don't know for sure). If you can buy or borrow one, it's worth your time. Failing that, there's some older versions on-line that may be more appropriate for you since you're using the old built-in matrix operations (here's one example (http://www.glprogramming.com/red/chapter03.html).


Also if I delete ... The final scene doesn't change.

Which would suggest either 1) your program isn't using the MODELVIEW transform setting, or 2) the MODELVIEW transform was already set to the identity transform.

OceanJeff40
05-21-2017, 11:56 AM
I bought that book, and gave it initially bad reviews, because it doesn't really walk you through step by step startup in Windows with Visual Studio Community. However, if you are already programming in OpenGL and understand how to compile a simple program, then it's a great read, I've read through it now, and am working on slowly mastering the concepts brought out in each chapter.

Plus, it comes with examples (which weren't updated when the book was initially released, and is another reason for my initial bad review), which they recently updated and released on the web site.

Cheers,
Jeff

P.S. Also in the wake of the things that I needed to get started in OpenGL, it motivated me to start a series of YouTube videos covering startup and a few of the concepts that I've learned so far from the book and other sources.

This is a link to my youtube channel:
https://www.youtube.com/channel/UCzx8alrxVELz5h1dfCdkdfg

And a link to a great online tutorial, which can be downloaded in PDF format:
https://learnopengl.com/

Cristi
05-21-2017, 10:37 PM
Thanks. i will start reading :D