gambit20088
gambit20088

Reputation: 321

OpenGL - how does translation work?

It might be a basic question, but i couldn't find an answer anywhere. When i want to translate an object in my scene, what are the coordinates OpenGL uses?

Is it the -1,0 to 1,0 in the X and Y? (so i would have to move my object by using numbers that are between -1 and 1). Does it depend on the window size i set? (so i could use numbers like 100 or 200).

What if i create a window of size 500x500, how do i make sure the object i created is placed at the bottom, for example?

Thanks.

Upvotes: 1

Views: 309

Answers (1)

Wagner Patriota
Wagner Patriota

Reputation: 5674

OpenGL is always going to render at [-1.0, 1.0] interval for both X and Y coordinates. You can create your own abstraction to do coordinate transformations. The transformation can be done in the OpenGL API calls or in the vertex shader. "vertex shader" is MUCH more convenient for this, especially if you are doing 3D rendering.

The "rectangle area" that maps this space is defined as the "View Port" and you can use the OpenGL function glViewport() in order to set the area (in pixels) that will be mapped to your OpenGL space [-1.0, 1.0] x [-1.0, 1.0].

Upvotes: 1

Related Questions