OpenGL is an API for accessing graphics hardware functionality. It was first developed in 1994 and is independent of operating systems. The basic structure of OpenGL programs initialize rendering state, specify objects to render, and render those objects. Models in OpenGL are constructed from geometric primitives like points, lines, and triangles defined by vertices. OpenGL uses shaders to process vertex and fragment data, with the final image consisting of pixels drawn to the framebuffer.
Takes the reader through the various components of windowing systems, and how to develop and benchmark various Graphics applications using OpenGL and other toolsets. Also includes a Cheatsheet that covers various terminologies used in the Graphics world.
Cohen sutherland line clipping algorithmTawfiq Ahmed
Here I have uploaded the Cohen Sutherland line clipping algorithm. Hopefully, it will help those who are trying to understand in the simplest way and need a presentation slide.
-Thanks
Tawfiq Ahmed
WEBINAR ON FUNDAMENTALS OF DIGITAL IMAGE PROCESSING DURING COVID LOCK DOWN by by K.Vijay Anand , Associate Professor, Department of Electronics and Instrumentation Engineering , R.M.K Engineering College, Tamil Nadu , India
Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.
It gives the detailed information about Three Dimensional Display Methods, Three dimensional Graphics Package, Interactive Input Methods and Graphical User Interface, Input of Graphical Data, Graphical Data: Input Functions, Interactive Picture-Construction
Mini Project final report on " LEAKY BUCKET ALGORITHM "Nikhil Jain
The project “Leaky Bucket Algorithm” is based on computer networks.The leaky bucket algorithm is a general algorithm that can be effectively used to police real time traffic. Both Frame Relay and Aysnchronous Transfer Mode (ATM) networks use a form of the leaky bucket algorithm for traffic management.
For designing this graphical project we require the knowledge of both computer graphics and the language in which it is to be coded.The use of the language helps in designing a package more user friendly since for a general user high end languages creates complexities in understanding and usage.OpenGL provides us with all the inbuilt functions which makes us easy to understand graphics.
Lab Practices and Works Documentation / Report on Computer GraphicsRup Chowdhury
This is a report that I have prepared during my Computer Graphics Lab course. This contains the theoretical information that we learned in our introduction class. It also contains information on different computer graphics tools and software. It contains codes to create different and also the procedure.
1. Information on GLUT
2. Flag drawing with GLUT
3. DDA Algorithm
4. Midpoint Line Drawing Algorithm
5. Tansformation
Takes the reader through the various components of windowing systems, and how to develop and benchmark various Graphics applications using OpenGL and other toolsets. Also includes a Cheatsheet that covers various terminologies used in the Graphics world.
Cohen sutherland line clipping algorithmTawfiq Ahmed
Here I have uploaded the Cohen Sutherland line clipping algorithm. Hopefully, it will help those who are trying to understand in the simplest way and need a presentation slide.
-Thanks
Tawfiq Ahmed
WEBINAR ON FUNDAMENTALS OF DIGITAL IMAGE PROCESSING DURING COVID LOCK DOWN by by K.Vijay Anand , Associate Professor, Department of Electronics and Instrumentation Engineering , R.M.K Engineering College, Tamil Nadu , India
Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.
It gives the detailed information about Three Dimensional Display Methods, Three dimensional Graphics Package, Interactive Input Methods and Graphical User Interface, Input of Graphical Data, Graphical Data: Input Functions, Interactive Picture-Construction
Mini Project final report on " LEAKY BUCKET ALGORITHM "Nikhil Jain
The project “Leaky Bucket Algorithm” is based on computer networks.The leaky bucket algorithm is a general algorithm that can be effectively used to police real time traffic. Both Frame Relay and Aysnchronous Transfer Mode (ATM) networks use a form of the leaky bucket algorithm for traffic management.
For designing this graphical project we require the knowledge of both computer graphics and the language in which it is to be coded.The use of the language helps in designing a package more user friendly since for a general user high end languages creates complexities in understanding and usage.OpenGL provides us with all the inbuilt functions which makes us easy to understand graphics.
Lab Practices and Works Documentation / Report on Computer GraphicsRup Chowdhury
This is a report that I have prepared during my Computer Graphics Lab course. This contains the theoretical information that we learned in our introduction class. It also contains information on different computer graphics tools and software. It contains codes to create different and also the procedure.
1. Information on GLUT
2. Flag drawing with GLUT
3. DDA Algorithm
4. Midpoint Line Drawing Algorithm
5. Tansformation
This presentation gives an introduction to Java applets. Simple applet program, how to compile and run applet program. It also discuss about the applet life cycle.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
1. OpenGL
OpenGL is an application programming interface---‘‘API’’ for short---which is
merely a software library for accessing features in graphics hardware.
It was first developed at Silicon Graphics Computer Systems with Version 1.0
released in July of 1994.
Properties
• Independent of a computer’s operating or windowing system
• OpenGL doesn’t provide any functionality for describing models of three-
dimensional objects, or operations for reading image files
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 1
2. Basic OpenGL Program Structure
The basic structure of all OpenGL applications is as follows:
• Initialize the state associated with how objects should be rendered.
• Specify those objects to be rendered.
Rendering is the process by which a computer creates an image from models. OpenGL is
just one example of a rendering system.
Models( or objects) are constructed from geometric primitives such as points, lines, and
triangles that are specified by their vertices.
OpenGL uses Shaders (or little programs that are specifically compiled for your graphics
processing unit) which are special functions that the graphics hardware executes.
In OpenGL, there are four shader stages that you can use. The most common are vertex
shaders, which process vertex data, and fragment shaders, which operate on the fragments
generated by the rasterizer. Both vertex and fragment shaders are required in every
OpenGL program.
The final generated image consists of Pixels drawn on the screen; a pixel is the smallest
visible element on your display. The pixels in your system are stored in a framebuffer.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 2
3. Basic OpenGL Program Structure
In the preamble of the program, we include the appropriate header files and
declare global variables1 and other useful programming constructs.
The init() routine is used to set up data for use later in the program. This
may be vertex information for later use when rendering.
The display() routine is what really does the rendering. Almost all
display() routines will do the same three steps
1. Clear the window by calling glClear().
2. Issue the OpenGL calls required to render your object.
3. Request that the image is presented to the screen.
Finally, main() does the heavy lifting of creating a window, calling init(), and
finally entering into the event loop.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 3
4. OpenGL Pipeline
OpenGL begins with the
geometric data you provide
(vertices and geometric
primitives) and first processes it
through a sequence of shader
stages: vertex shading,
tessellation shading (which itself
uses two shaders), and finally
geometry shading, before it’s
passed to the rasterizer. The
rasterizer will generate
fragments for any primitive
that’s inside of the clipping
region, and execute a fragment
shader for each of the
generated fragments. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 4
5. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 5
6. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 6
7. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 7
8. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 8
9. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 9
10. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 10
11. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 11
12. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 12
13. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 13
14. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 14
15. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 15
16. Glut routines for Window Management
• glutInit(int *argc, char **argv) initializes GLUT and processes any command
line arguments.
glutInit() should be called before any other GLUT routine.
• glutInitDisplayMode(unsigned int mode) specifies whether to use an RGBA or
color-index color model. You can also specify whether you want a single- or
double-buffered window. (If you're working in color-index mode, you'll want to
load certain colors into the color map; use glutSetColor() to do this.) Finally, you
can use this routine to indicate that you want the window to have an associated
depth, stencil, and/or accumulation buffer. For example, if you want a window
with double buffering, the RGBA color model, and a depth buffer, you might
call glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH).
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 16
17. Glut routines for Window Management
• glutInitWindowPosition(int x, int y) specifies the screen location for
the upper-left corner of your window.
• glutInitWindowSize(int width, int size) specifies the size, in pixels, of
your window.
• int glutCreateWindow(char *string) creates a window with an
OpenGL context. It returns a unique identifier for the new window.
Be warned: Until glutMainLoop() is called (see next section), the
window is not yet displayed.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 17
18. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 18
19. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 19
20. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 20
21. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 21
22. OpenGL Geometric Primitives
Polygon Types
GL_POLYGON -- draws a polygon
from vertex v0 to vn-1
GL_QUADS -- draws a series of
separate four-sided polygons
GL_TRIANGLES -- draws a series of
separate three-sided polygons
GL_QUAD_STRIP -- draws a strip of
connected quadrilaterals
GL_TRIANGLE_STRIP -- draws a strip
of connected triangles
GL_TRIANGLE_FAN -- draws a strip of
triangles connected about a common
origin
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru
22
23. Sierpinski Gasket - Algorithm
1. Pick an initial point (x, y, z) at random inside the triangle
2. Select one of the three vertices of the triangle at random
3. Find the location halfway between the initial point and the
randomly selected vertex.
4. Display the new point
5. Replace the point(x, y, z) with this new point
6. Return to step 2
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru
23
24. Line Attributes
• Color, thickness, stippling.
• glColor3f() sets color.
• glLineWidth(4.0) sets thickness. The default thickness is 1.0.
a). thin lines b). thick lines c). stippled lines
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru
24
25. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 25
26. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 26
27. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 27
28. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 28
29. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 29
30. Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 30
31. Sample Program
#include <GL/gl.h>
#include <GL/glut.h>
void display(void)
{
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);
/* draw white polygon (rectangle) with corners at (0.25, 0.25, 0.0) and (0.75, 0.75,
0.0) */
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glEnd();
/* don't wait! start processing buffered OpenGL routines */
glFlush();
}
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 31
32. Sample Program
void init(void)
{
/* select clearing (background) color */
glClearColor(0.0, 0.0, 0.0, 0.0);
/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 32
33. Sample Program
/* Declare initial window size, position, and display mode (single buffer
and
RGBA). Open window with "hello" in its title bar. Call initialization
routines. Register callback function to display graphics. Enter
main loop and process events. */
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow("hello");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Output:
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 33
34. glMatrixMode(mode)
• Specifies which matrix is the current matrix
There are actually only three things you can pass to glMatrixMode:
• glMatrixMode(GL_MODELVIEW); is the common case. This makes all subsequent matrix operations
affect the "gl_ModelViewMatrix", which is primarily used for model setup (for example, shrinking the
car model to fit next to the building model).
• glMatrixMode(GL_PROJECTION); switches to the projection matrix, "gl_ProjectionMatrix". The
projection matrix's job is usually to perform the perspective divide.
• glMatrixMode(GL_TEXTURE); switches to the texture matrix. This can be used to adjust the texture
coordinates you pass in.
To find out which matrix stack is currently the target of all matrix operations, call glGet with argument GL_MATRIX_MODE. The
initial value is GL_MODELVIEW.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 34
35. The projection matrix is used to create your viewing volume. Imagine a
scene in the real world. You don’t really see everything around you,
only what your eyes allow you to see. So when we say that we set up
the projection matrix we mean that we set up what we want to see
from the scene that we create. I mean you can draw objects anywhere
in your world. If they are not inside the view volume you won’t see
anything. When you create the view volume imagine that you create 6
clipping planes that define your field of view.
glMatrixMode(mode)
The modelview matrix is used to make various transformations to the
models (objects) in your world. Like this you only have to define your
object once and then translate it or rotate it or scale it.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 35
36. OpenGL Matrix Manipulation
OpenGL has a whole set of useful utility routines that act on the current matrix (as set by glMatrixMode):
•glLoadIdentity();Cleans out the current matrix, replacing it with the identity
•glTranslatef(dx,dy,dz);Shifts the origin of the current coordinate system.
•glScalef(sx,sy,sz);Scales the current coordinate system. Scaling by a big value makes stuff bigger. You can also mirror stuff
by scaling by a negative value.
•glRotatef(ang,x,y,z);Rotate by ang degrees right-handed around the vector x,y,z. For example, glRotatef(45.0,0,0,1); rotates
the stuff onscreen by 45 degrees counterclockwise.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 36
37. OpenGL Transformations
Translation: Translation refers to moving an object to a different position on the screen.
The OpenGL function is glTranslatef( tx, ty, tz ), where tx, ty and tz are translation distances along the three axes
Rotation: Rotation refers to rotating a point.
The OpenGL function is glRotatef (A, x, y, z), where A is the angle of rotation
The above formula will rotate the point around the origin through an angle A.
Scaling: Scaling refers to zooming in and out an object on different scales across axes.
The OpenGL function is glScalef(float x, float y, float z)
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 37
39. Viewing: Camera Analogy
Positioning the Camera
Positioning the Model
Choose a camera lens and
adjust zoom
Mapping to screen
Viewing Transformation
Modeling Transformation
Projection Transformation
Viewport Transformation
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 39
40. Viewport Transformation
• Indicates the shape of the available screen area into which the
scene is mapped
• Since viewport specifies the region the image occupies on the
computer screen, you can think of the viewport transformation
as defining the size and location of the final processed
photograph - for example, whether the photograph should be
enlarged or shrunk.
• If the window changes size, the viewport needs to change
accordingly
void glViewport( int x,
int y,
int width,
int height);
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 40
41. Viewport transformation
glViewport( 0, 0, width, height);
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 41
42. Projection
Perspective v/s Orthographic
Objects which are far away are smaller than those nearby;
Does not preserve the shape of the objects.
Perspective view points give more information about depth;
Easier to view because you use perspective views in real life.
Useful in architecture, game design, art etc.
All objects appear the same size regardless the distance;
Orthographic views make it much easier to compare sizes
of the objects. It is possible to accurately measure the
distances
All views are at the same scale
Very useful for cartography, engineering drawings,
machine parts.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 42
44. Perspective Transformation
//perspective projection
void glFrustum(double left,
double right,
double bottom,
double top,
double near,
double far);
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 44
45. Perspective Transformation
Four sides of the frustum, its top, and its base correspond to the six
clipping planes of the viewing volume.
Objects or parts of objects outside these planes are clipped from the
final image
Does not have to be symmetrical
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 45
47. Orthographic Transformation
//orthographic projection
void glOrtho( double left,
double right,
double bottom,
double top,
double near,
double far);
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 47
48. Modelview Matrix
//perspective projection
void gluLookAt(double eyeX, double eyeY, double eyeZ,
double centerX, double centerY, double centerZ,
double upX, double upY, double upZ);
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 48
49. Setting up the scene
void init(void) { /* called once to set up basic opengl state */
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION); /* Set up the projection matrix */
glLoadIdentity();
// left,right,bottom,top,near,far
glFrustum(-1.0, 1.0, -1.0, 1.0, 1., 10.0); // perspective view
// glOrtho (-1.0, 1.0, -1.0, 1.0, 1., 10.0); // orthographic view
// gluPerspective(45.0f, 1., 1., 10.); // perspective view
glMatrixMode(GL_MODELVIEW); /* Set up the model view matrix */
glLoadIdentity();
eye center up-direction
gluLookAt(0.,0.,2.,0.,0.,0.,0.,1.,0.); /* Camera position */
} Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 49
50. Additional GLUT callback routines
GLUT supports many different callback actions, including:
glutDisplayFunc()defines the function that sets up the image on the screen
glutReshapeFunc() function is called when the size of the window is changed
glutKeyBoardFunc() callback routine to respond on keyboard entry
glutMouseFunc() callback to respond on pressing the mouse button
glutMotionFunc() callback to respond mouse move while a mouse button is pressed
glutPassiveMouseFunc() callback to respond to mouse motion regardless state of mouse
button
glutIdleFunc() callback routine for idle state, usually used for animation
More info: http://www.opengl.org/resources/libraries/glut/spec3/node45.html
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 50
51. Additional GLUT callback routines
int main(int argc, char **argv)
{
. . .
/* Set callback function that responds on keyboard pressing */
glutKeyboardFunc (keypress);
. . .
}
/* keyboard callback routine */
void keypress( unsigned char key, int x, int y)
{
if (key == 'q' || key =='Q' || key ==27)exit(0); // exit
} Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 51
52. Callback routines & Window Resizing
int main(int argc, char **argv) {
. . .
/* Set display as a callback for the current window */
glutDisplayFunc(display);
/* Set callback function that respond to resizing the window */
glutReshapeFunc(resize);
/* Set callback function that responds on keyboard pressing */
glutKeyboardFunc(keypress);
/* Set callback function that responds on the mouse click */
glutMouseFunc(mousepress);
. . .
}
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 52
53. Callback routines & Window Resizing
void keypress( unsigned char key, int x, int y) { … }
void mousepress( int button, int state, int x, int y) { … }
void resize(int width, int height) {
double aspect;
glViewport(0,0,width,height); /* Reset the viewport */
aspect = (double)width / (double)height; /* compute aspect ratio*/
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //reset projection matrix
if (aspect < 1.0) {
glOrtho(-4., 4., -4./aspect, 4./aspect, 1., 10.);
} else {
glOrtho(-4.*aspect, 4.*aspect, -4., 4., 1., 10.);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0., 0., 5., 0., 0., 0., 0., 1., 0.);
}
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 53
54. Skeleton Event-driven Program
// include OpenGL libraries
void main()
{
glutDisplayFunc(myDisplay); // register the redraw function
glutReshapeFunc(myReshape); // register the reshape function
glutMouseFunc(myMouse); // register the mouse action function
glutMotionFunc(myMotionFunc); // register the mouse motion function
glutKeyboardFunc(myKeyboard); // register the keyboard action function
…perhaps initialize other things…
glutMainLoop(); // enter the unending main loop
}
…all of the callback functions are defined here
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 54
55. Callback Functions
• glutDisplayFunc(myDisplay);
• (Re)draws screen when window opened or another window moved off it.
• glutReshapeFunc(myReshape);
• Reports new window width and height for reshaped window. (Moving a
window does not produce a reshape event.)
• glutIdleFunc(myIdle);
• when nothing else is going on, simply redraws display using void myIdle()
{glutPostRedisplay();}
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 55
56. Callback Functions
• glutMouseFunc(myMouse);
• Handles mouse button presses. Knows mouse location and nature of button
(up or down and which button).
• glutMotionFunc(myMotionFunc);
• Handles case when the mouse is moved with one or more mouse buttons
pressed.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 56
57. Callback Functions
• glutPassiveMotionFunc(myPassiveMotionFunc)
• Handles case where mouse enters the window with no buttons pressed.
• glutKeyboardFunc(myKeyboardFunc);
• Handles key presses and releases. Knows which key was pressed and
mouse location.
• glutMainLoop()
• Runs forever waiting for an event. When one occurs, it is handled by the
appropriate callback function.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 57
58. What the Call-back functions do?
• The call-back functions you write are registered, and then the
program enters an endless loop, waiting for events to occur.
• When an event occurs, GL calls the relevant handler function.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 58
59. Simple User Interaction with Mouse
and Keyboard
• Register functions:
• glutMouseFunc (myMouse);
• glutKeyboardFunc (myKeyboard);
• Write the function(s)
• NOTE that any drawing you do when you use these functions must be
done IN the mouse or keyboard function (or in a function called from
within mouse or keyboard callback functions).
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 59
60. Example Mouse Function
• void myMouse(int button, int state, int x, int y);
• Button is one of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or
GLUT_RIGHT_BUTTON.
• State is GLUT_UP or GLUT_DOWN.
• X and y are mouse position at the time of the event.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 60
61. Example Mouse Function
• The x value is the number of pixels from the left of the window.
• The y value is the number of pixels down from the top of the window.
• In order to see the effects of some activity of the mouse or keyboard,
the mouse or keyboard handler must call either myDisplay() or
glutPostRedisplay().
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 61
62. Using Mouse Motion Functions
• glutMotionFunc(myMovedMouse); // moved with button held down
• glutPassiveMotionFunc(myMovedMouse); // moved with buttons up
• myMovedMouse(int x, int y); x and y are the position of the mouse
when the event occurred.
• Code for drawing rubber rectangles using these functions is in Fig.
2.41.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 62
63. Example Keyboard Function
void myKeyboard(unsigned char theKey, int mouseX, int
mouseY)
{
GLint x = mouseX;
GLint y = screenHeight - mouseY; // flip y value
switch(theKey)
{case ‘p’: drawDot(x, y); break;
// draw dot at mouse position
case ‘E’: exit(-1); //terminate the program
default: break; // do nothing
}
}
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 63
64. Example Keyboard Function
• Parameters to the function will always be (unsigned char key, int
mouseX, int mouseY).
• The y coordinate needs to be flipped by subtracting it from
screenHeight.
• Body is a switch with cases to handle active keys (key value is ASCII
code).
• Remember to end each case with a break!
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 64
65. Using Menus
• Both GLUT and GLUI make menus available.
• GLUT menus are simple, and GLUI menus are more powerful.
• We will build a single menu that will allow the user to change the
color of a triangle, which is undulating back and forth as the
application proceeds.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 65
66. GLUT Menu Callback Function
• Int glutCreateMenu(myMenu); returns menu ID
• void myMenu(int num); //handles choice num
• void glutAddMenuEntry(char* name, int value); // value used in
myMenu switch to handle choice
• void glutAttachMenu(int button); // one of GLUT_RIGHT_BUTTON,
GLUT_MIDDLE_BUTTON, or GLUT_LEFT_BUTTON
• Usually GLUT_RIGHT_BUTTON
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 66
67. GLUT Menu-Example
• int submenu1, submenu2;
• submenu1 = glutCreateMenu(mymenu);
• glutAddMenuEntry("abc", 1);
• glutAddMenuEntry("ABC", 2);
• submenu2 = glutCreateMenu(selectColor);
• glutAddMenuEntry("Green", 1);
• glutAddMenuEntry("Red", 2);
• glutAddMenuEntry("White", 3);
• glutCreateMenu(selectFont);
• glutAddMenuEntry("9 by 15", 0);
• glutAddMenuEntry("Times Roman 10", 1);
• glutAddMenuEntry("Times Roman 24", 2); glutAddSubMenu("Messages", submenu1);
• glutAddSubMenu("Color", submenu2); glutAttachMenu(Glut.GLUT_RIGHT_BUTTON);
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 67
68. GLUT SubMenu
• Create a subMenu first, using menu commands, then add it to main
menu.
• A submenu pops up when a main menu item is selected.
• glutAddSubMenu (char* name, int menuID); // menuID is the value
returned by glutCreateMenu when the submenu was created
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 68
69. Using GLUT Menus:
Overview
• What we can do with menus:
• We can create (and destroy) menu data structures.
• We can add entries (and submenus) to a previously created menu.
• We can attach a previously created menu to a mouse button (and we can also detach it).
• We can change the entries of a menu.
• The first three above are illustrated in creature.cpp. We will look at these in
detail shortly.
• Each menu has a callback associated with it: the handler function. This function is
called when the user selects an entry in that menu.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 69
70. Using GLUT Menus:
Menu Creation
• Creating a Menu
• Creating a menu means creating a data structure in memory; nothing is displayed yet.
• GLUT manages the data structure.
• When we create a menu, we also register the handler callback function.
• The initialization function (“init”) is a good place to create your menus.
• To create a menu, call glutCreateMenu.
• This function takes one parameter:
• A pointer to the handler callback function for this menu.
• A menu handler function takes one int parameter and returns void; more on this later.
• Example: glutCreateMenu(handle_menu);
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 70
71. • We can add entries to the end of the current menu.
• What is the current menu? For now, if you have created one menu, then it is the current menu
(similarly, if you have one window, then it is the current window).
• To add an entry, call glutAddMenuEntry.
• This function takes two parameters:
• A char* (C-style string) that gives the text of the entry.
• If you are using the C++ string class, you can pass a C-style string using the .c_str() member
function.
• An int that is passed to the handler function when the user selects this entry.
• Example: glutAddMenuEntry("Toggle eye color", 1);
Adding Entries to a Menu
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 71
72. Using GLUT Menus:
Attaching
• Attaching a Menu to a Mouse Button
• We can attach the current menu to a mouse button in the current window.
• To attach a menu, call glutAttachMenu.
• This function takes one parameter:
• An int indicating which mouse button to attach to.
• Example: glutAttachMenu(GLUT_RIGHT_BUTTON);
• Once we attach a menu, the user can use it.
• Whenever they want, the user pops up the menu with the appropriate mouse action.
• We do not draw the menu; GLUT does this for us.
• When a menu entry is selected, the handler function is called, with the proper number as a
parameter.
• Since a menu is attached in the current window, do not attach a menu until you have created
a window.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 72
73. Using GLUT Menus:
Example
• The following is called in function init.
void make_main_menu()
{
glutCreateMenu(handle_main_menu);
glutAddMenuEntry("Toggle eye color", 1);
glutAddMenuEntry("Toggle mouth motion", 2);
glutAddMenuEntry("Quit", 3);
glutAddMenuEntry("------------------------", 999);
…
glutAddMenuEntry("for CS 381, fall 2003", 999);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
• Value passed to handler callback can be the same for multiple entries.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 73
74. Using GLUT Menus:
Example
• Here is part of the handler callback function (declared before make_main_menu!).
// handle_main_menu
// Menu handling callback function for our menu
void handle_main_menu(int value)
{
switch (value)
{
case 1: // Toggle eye color
blueeyes = !blueeyes;
glutPostRedisplay();
break;
…
case 3: // Quit
exit(0);
break;
case 999: // Other menu items do nothing
break;
• Menu handlers, like keyboard functions, typically consist of one switch statement.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 74
75. • Now, we quickly look at a few more advanced topics. We will discuss
some of these in more detail later on.
• GLUT Menus:
• The “current menu”.
• Submenus.
• Changing menu entries.
• Thoughts on menus in general:
• What are submenus for?
• On changing menus.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 75
76. More on Menus:
GLUT — The Current Menu
• Some GLUT menuing commands (e.g., glutAddMenuEntry, glutAttachMenu) deal with
the current menu.
• If you have just one menu, then it is the current menu.
• glutCreateMenu sets the current menu to the menu created.
• In a menu handler, the current menu is the one handled.
• Function glutCreateMenu returns an int identifying the menu created. If you have multiple
menus, save this value.
int menu_x = glutCreateMenu(handle_menu_x);
• You can set the current menu yourself using glutSetMenu.
• There is also a “current window”. It is dealt with similarly.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 76
77. • A submenu is a menu that is an item in another menu.
• To make a submenu (in the “main” menu):
• Create the submenu (as an ordinary menu, but do not attach it).
• Create the main menu.
• Use glutAddSubMenu to make submenu an item in the main menu.
int superduper_menu =
glutCreateMenu(handle_superduper_menu);
…
int rightmouse_menu =
glutCreateMenu(handle_rightmouse_menu);
glutAddSubMenu("Super-Duper Stuff", superduper_menu);
• The submenu does not need to be attached.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 77
78. More on Menus:
GLUT — Changing Menu Entries
• To change the text or return value of a menu entry:
• Set the the current menu, by passing the proper ID to glutSetMenu.
• If you are in the menu handler, this is unnecessary.
glutSetMenu(superduper_menu);
• Use glutChangeToMenuEntry to set the new text & return value. This function takes 3 parameters:
• The entry number (int): count from the top of the menu, starting at 1.
• The new text (char*).
• The new return value (int).
glutChangeToMenuEntry(1, the_entry.c_str(), 1);
• You can also change submenus, using glutChangeToSubMenu; see the GLUT documentation.
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 78
79. OpenGL Display Lists - Example
// create one display list
int index = glGenLists(1);
// compile the display list
glNewList(index, GL_COMPILE);
glBegin(GL_TRIANGLES);
glVertex3fv(v0);
glVertex3fv(v1);
glVertex3fv(v2);
glEnd();
glEndList();
...
// draw the display list
glCallList(index);
...
// delete it if it is not used any more
glDeleteLists(index, 1);
Prof. Jeo Joy A, Dept. of Computer Science(UG), Kristu Jayanti College(Autonomous) Bengaluru 79