Two Dimension Viewing Function
Last Updated :
26 Apr, 2025
Two-dimension viewing in Computer graphics is a technique to map the world coordinates system (actual coordinates of the object in the real world) to device coordinates (actual coordinates of the object on the output screen like a monitor).
2D Viewing Function
In Computer graphics to perform viewing transformations, we need a tool called OpenGL. The basic OpenGL libraries do not support functions for 2D viewing transformations as they are made especially for 3D viewing transformations. But we can apply 3D viewing routines to 2D viewing scenes. We can use two-dimensional routines along with the OpenGL viewport function.
Two Dimensional routines that can be used are:
- GLU library functions
- GLUT library functions
Some functions are:
1. GLU Clipping-Window Function: This function is used to define a two-dimensional clipping window,
gluOrtho2D (xwmin, xwmax, ywmin, ywmax);
//xwmin for left width, xwmax for right width,
ywmin for bottom width, ywmax for top width
2. GLUT Display Window: This function is used to initialize GLUT,
glutInit (&argc, argv);
For choosing GLUT function dimensions and position:
glutCreateWindow ("Title of Display Window");
glutInitWindowPosition (xTopLeft, yTopLeft);
glutInitWindowSize (dwWidth, dwHeight);
Function to expand the current display window to fill the screen:
glutFullScreen ( );
Function to reset the screen location for the current display window:
glutPositionWindow (xNewTopLeft, yNewTopLeft);
Function to convert the current display window to an icon in the form of some small symbol or picture that represents the window:
glutIconifyWindow ( );
We can change the label of the icon with the following command:
glutSetIconTitle ("icon_name");
This function invokes the particular function that the user want to display at the current display window, if there are more than one display window:
glutDisplayFunc (callback_func);
//This routine, called callback_func is an example,
is referred to as a callback function because it is the routine that
// is executed when GLUT determines that display
window has contents to be updated.
Finally we have the final GLUT command that directs the execution of the program:
glutMainLoop ( );
After this command gets executed display windows and their graphic contents are sent to the screen. Then the program continually checks for new “events, ” such as input from a mouse, keyboard or graphics tablet after entering to GLUT processing loop.
To show two views of a triangle using 2D viewing functions.
Example 1:
C++
void displayTriangle()
{
// defining initial position of triangle
wcPt2D vertices[3] = { { -40.0, -20.0 },
{ 40.0, -20.0 },
{ 0.0, 40.0 } };
glClear(GL_COLOR_BUFFER_BIT);
// clear display window
glColor3f(1, 1, 0);
// to fill yellow color to the triangle
glViewport(0, 0, 200, 200);
// to set position of the yellow triangle
triangle(vertices);
// to display yellow rotated triangle
// to rotate triangle and display at
// right half of display window
glColor3f(0.0f, 0.0f, 1.0f);
// change triangle color to blue
glViewport(300, 0, 300, 300);
// to set position of the blue triangle
glRotatef(90.0, 0.0, 0.0, 1.0);
// to rotate the triangle about z axis.
triangle(vertices);
// to display green rotated triangle
glFlush();
// to execute all functions
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(60, 60);
glutInitWindowSize(500, 250);
glutCreateWindow("2D viewing function Example");
init();
glutDisplayFunc(displayTriangle);
glutMainLoop();
}
Output:
Similar Reads
Compressions And Stretches of Functions
Compressions and stretches are fundamental concepts in mathematics that involve transforming the graphs of the functions. Understanding these transformations is essential for students as it enhances their ability to analyze and interpret various mathematical relationships. This article aims to provi
7 min read
Layout and Views in Presentation Tool
Microsoft PowerPoint provides different types of tools to make presentations presentable and interactive for different purposes like for business, for class, for projects, etc. Layout and Views tools are one of the presentation tools. The View in power points is the look of the working space that he
5 min read
Functions that Describe Situations
Functions in mathematics are used in the description of the relationship between one or more variables. Thus, functions can help understand how one quantity depends on another and, therefore, model various practical situations. This article should introduce the different types of functions and analy
7 min read
Biconvex Lens â Definition & Meaning
Double convex or biconvex lens is a basic lens which has two convex surfaces. In general, the radius of curvature of both the surfaces of the biconvex lens are the same. Biconvex lenses are called convex-convex lenses. In this article, we will learn about the Definition of a Lens, the Definition of
8 min read
Postgre Window Functions
PostgreSQL is an advanced relational database management system, popular for its ability to handle both SQL (structured) and JSON (non-relational) queries. One of its most powerful features is window functions, which allow for complex data analysis across rows without collapsing data into a single r
6 min read
Real Life Applications of Functions
Functions are mathematical constructs that model relationships between inputs and outputs. In math, a function is like a machine that takes an input (usually a number) and produces a corresponding output. Each input value is associated with exactly one output value. You can think of it as a rule or
8 min read
Getting Started with View Engine
A view engine is a tool used in web development to create dynamic HTML content based on data from the server. It acts as a template processor, allowing developers to integrate data with predefined HTML templates easily. View engines are commonly used in frameworks like Express.js for Node.js, Django
4 min read
Graphing Function
Graphing Function is the process of illustrating the graph (the curve) for the function that corresponds to it. Plotting simple functions like linear, quadratic, cubic, et al. examples doesnât pose a challenge; depicting functions of a more complex nature like rational, logarithmic, and others requi
13 min read
Analyzing the Graphs of Functions
Graphs of functions are visual representations of how one quantity depends on another. In simple terms, a graph shows the relationship between two variables: one variable is usually on the horizontal axis (called the x-axis), and the other is on the vertical axis (called the y-axis). For example, if
7 min read
Difference between Relation and Function
A relation in mathematics is simply a connection or a rule that links one set of things (called the domain) to another set of things (called the range). You can think of it as a collection of pairs that shows how items from one group are connected to items in another group. For example, Imagine you
6 min read