WYS
WYS

Reputation: 1647

OpenGL Viewport Transformation

I was wondering how OpenGL handles viewport transformation to the window.

As I understand viewport transformation is that it strethes the scene onto the OpenGL window by applying the viewport transformation to that scene.

Please correct me if I'm wrong.

Upvotes: 1

Views: 11954

Answers (2)

wcochran
wcochran

Reputation: 10896

After clipping and perspective divide, all remaining (visible) vertex coordinates x,y,z are between -1 and +1 -- these are called normalized device coordinates. These are mapped to device coordinates by the appropriate scale and shift -- i.e, the viewport transformation.

For example, if the viewport has size 1024x768 with a 16-bit depth buffer and the origin is (0,0), then the points will be scaled by (512,384,2^14) and shifted by (512,384,2^14) yielding the appropriate pixel and depth values for the device.

Upvotes: 6

flix
flix

Reputation: 609

http://www.songho.ca/opengl/gl_transform.html:

Window Coordinates (Screen Coordinates)

It is yielded by applying normalized device coordinates (NDC) to viewport transformation. The NDC are scaled and translated in order to fit into the rendering screen. The window coordinates finally are passed to the raterization process of OpenGL pipeline to become a fragment. glViewport() command is used to define the rectangle of the rendering area where the final image is mapped. And, glDepthRange() is used to determine the z value of the window coordinates. The window coordinates are computed with the given parameters of the above 2 functions;

Follow the link to see the math details.

Upvotes: 3

Related Questions