# Is there a difference between window and screen in computer graphics?

I've been reading some code which setups a ray tracer and I've realized I've a doubt regarding what's a screen and what's a window in this context. Here's the relevant code using Qt:

...

void CCanvas::paint()
{
// check if we have something to draw on
if (!image) return;

// camera position
Point3d camera (0.0, 0.0, 0.0);

// screen resolution
int w = image->width();
int h = image->height();

// horizontal opening angle
double alpha = PI/2.0;

// horizontal window dimension [-X,X]
double X = tan(alpha/2.0);

// pixel size
double s = 2.0 * X / (double)w;

// vertical window dimension [-Y,Y]
double Y = s * h / 2.0;
...


I think I know what's the screen resolution: if we think of the screen as a matrix, w and h would be respectively the number of columns and rows in this "matrix".

After obtaining the resolution of the image, we define an opening angle $\alpha$. I interpreted this opening angle as the opening angle of the camera, i.e., it defines basically what's visible from the camera.

Then we compute X, which is half of the horizontal window (according to the comments in the code). (Note this X is not the same X representing the x axis in the picture below. Yes, whoever wrote this code had no common sense!)

Now, mathematically I understood these calculations, what I don't understand is the difference between $2X$ and $w$.

Is the "window" here the same thing as "screen"?

I've this picture here

I've added the $X=\tan \left( \frac{\alpha}{2}\right)$ to the picture according to what I think $X$ is from the code above.

If the window is the same thing as the screen, I wonder why do we need $w$. I mean, couldn't we just decide how many rows and columns we have in the visible area?

Again, it's not clear if the visible area of the camera is the same thing as the screen or window...

In this code, the "screen resolution" means the number of pixels in the output image (which happens to be a window in the windowing system), while the "window dimension" means the corresponding size in the 3D scene. Computing s tells you the ratio between one unit of 3D space in your scene and one pixel of output image. You need to do this in order to know how far apart in world-space to cast your primary rays.

These uses of "screen" and "window" aren't standard; they're specific to this code. No wonder you're confused.

• So, essentially, the screen is the real $2D$ screen (or image on the screen) whereas $X$ would be half of the opening width of the virtual "panel" or "board" created by the opening angle of the camera in the $3D$ world (coordinate system)? So, clearly, this virtual "panel" or "board" maybe not cover the whole screen, right? – nbro Jan 14 '17 at 13:48
• @nbro With the maths here, the "board" has to cover the whole screen, but in general, yes, they don't have to be the same. It's more usual to call this the image plane: the plane onto which the 3D scene is projected to create the image. – Dan Hulme Jan 14 '17 at 15:27
• The image plane can be thought as a plane in the $3D$ world, right? – nbro Jan 14 '17 at 15:29
• @nbro Yes, that's right. – Dan Hulme Jan 14 '17 at 15:31
• Sorry for asking too many question, but I would like to make this thing clear, and books or articles around do not make it clear, IMHO. How would the math work if for example the image plane was smaller than the screen? Another question. Is the image plane in the "world space" or in the "camera space" (if this question even makes sense)? I mean, the image plane coordinates are usually represented using a triple of coordinates, so I suppose they are represented in the world coordinate system... – nbro Jan 14 '17 at 15:34

You have two issues at stake here:

1. What conventions are used in the particular program you use (or use as a template). The meaning that people gave to certain words within the context of your program.

2. The meaning of the terms 'screen coordinates' and 'window coordinates' in the Computer Graphics world. In the CG world, these terms have very precise meaning which do not necessarily correspond to the meaning they have in the context of your program.

So does your question relate to "what do these terms mean in the context of my program" or "what do they mean in CG"? It seems like you're more interested in the former.

Let's try to reconcile the two questions:

1. When you render a CG image you use a virtual camera. The image plane of that camera exists in the virtual world (think of it as a rectangle if the image resolution width != the image resolution height what we call the image aspect ratio), and has the same coordinates as all the objects that are in your scene. Think of this camera as a pyramid whose apex is the eye position and the base of the pyramid the image plane.

Imagine that the image plane (the base of the pyramid) is 1 unit away from the apex. By changing the size of this image plane which you do by changing the field-of-view angle as shown in the image above, you can control how much of the scene you see (this is equivalent in photography to zooming in or out).

Points that lie on these planes, are said to be in screen coordinates. Though at some point you need to transform these coordinates to pixel coordinates that we call raster coordinates (which I believe in OpenGL are also called somehow window coordinates). There are no conventions for what range the screen coordinates should lie in because it depends entirely on the way you actually build your camera model, but they go from -something to +something in height and -something * imageAspectRatio and +something * imageAspectRatio in width. Your raster coordinates always go from [0:height] for the y-coordinate and [0:width] for the x-coordinate. Screen coordinates are floats, raster/window coordinates are integers (they correspond to pixel position in the digital image representation, the stuff you save to disk or display to the screen).

Understand that all these concepts might take time and can't be properly explained in just a few lines. I would recommend additional sources for you to look at and really understand and learn about the different coordinate systems that are used and involved in the process of simulating physical cameras in computer graphics.

Just leaving my opinion here in case someone else comes searching for the answer.

Different rendering systems have different definitions for screen space i guess. According to Renderman Screen Space means coordinates in the range [-1,1] where as other systems such as OpenGL thinks of it as Pixel coordinates ranging from 0 or 1 to the width/height of the actual screen.

In CG, before converting all the points to the actual pixel coordinates i.e where they are projected on the screen, we usually normalize all the points in the range [0,1] or [-1,1]. This is known as the Normalized device coordinates. It's done because it's easier to scale it back to screen size that may vary and it's usually easier to perform other calculation in this range.

I think the coder there was just trying to do that.

  // horizontal window dimension [-X,X]
double X = tan(alpha/2.0);


according to him the horizontal window ranges from -X to X. Since alpha was PI/2 or 90 degrees. tan(alpha/2) comes out 1. So X is in the range -1,1.

 // pixel size
double s = 2.0 * X / (double)w;

// vertical window dimension [-Y,Y]
double Y = s * h / 2.0;
...


Dunno about the fancy stuff but here the Y range has been mapped to [-a,a] where a is the aspect ratio. which is width/height or height/width. You can see that clearly if you substitue the value of "s" in the final equation. You'll get

double Y = 2 * X * h / (2 * w)
Y = h/w    // X = 1


The mapping to [-a,a] is done because our screen is not always a square. Its usually a rectangle. You can fix the Y values in [-1,1] and let X be in the range [-a, a] as well.