polygons 2 color scree shots 3copies
TRANSCRIPT
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
1/47
Transparency
of polygons
CHAPTER 1
INTRODUCTION
INTRODUCTION TO COMPUTER GRAPHICS
Computer Graphics is one of the most effective and commonly used methods to
communicate the processed information to the user. It displays the information in the form of
graphical objects such as pictures, charts, graphs and diagram instead of simple text.
Graphics often combine text, illustration, and color. Graphic design may consist of
the deliberate selection, creation, or arrangement of typography alone, as in a brochure, flier,poster, web site, or book without any other element. Clarity or effective communication may
be the objective, association with other cultural elements may be sought, or merely, the
creation of a distinctive style.
Graphics can be functional or artistic. The latter can be a recorded version, such
as a photograph, or an interpretation by a scientist to highlight essential features, or an artist,
in which case the distinction with imaginary graphics may become blurred.
Computer Graphics today is largely interactive. The user controls the contents,
structure, and appearance of objects and their displayed images by using input devices, such
as a keyboard, mouse, or touch-sensitive panel on the screen.
Computer graphics concerns with the pictorial synthesis of real or imaginary
objects from their computer based models, where as the related field of image processingtreats the converse process, the analysis of scenes, or the reconstruction of models of 2D or
3D objects from their pictures.
A broad classification of major subfields in Computer Graphics might be:
Geometry Studies ways to represent and process surfaces.
Animation Studies ways to represent and manipulate motion.
Rendering Studies algorithms to reproduce light transport.
Dept. Of CSE, B.T.L.I.T1
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
2/47
Transparency
of polygons
Imaging Studies image acquisition or image editing.
Computer graphics Computer graphics is concerned with all aspects of producing pictures
and images using a computer.
Translation Translation is an operation that displaces points by a fixed size in a given
direction.
Rotation Three features of transformation extended to other rotations.
There is one point in the origin that is unchanged by the rotation called fixed point.
Two dimensional plane is part of three dimensional space, we can reinterpret thisrotation in three dimension.
3.Rotation in the two dimensional plane z=0 is equivalent to a three dimensional
rotation about the z-axis.
Scaling Scaling is an non rigid body transformation by which we can make an object
bigger or smaller.
AREAS OF APPLICATION OF COMPUTER GRAPHICS
User interfaces and Process control.
Cartography.
Office automation and Desktop publishing.
Plotting of graphs and charts.
Computer aided Drafting and designs.
Simulation and Animation.
Dept. Of CSE, B.T.L.I.T2
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
3/47
Transparency
of polygons
INTRODUCTION TO OpenGL
About OpenGL
OpenGL has become a widely accepted standard for developing graphics application.Most of our applications will be designed to access OpenGL directly through functions in
three libraries. Functions in main GL library have names that begin with the letters gl and
are stored in a library usually referred to as GL.
The second is the OpenGL Utility Library (GLU). This library uses only GL functions
but contains code for creating common objects and simplifying viewing. All functions in
GLU can be created from the core GL library. The GLU library is available in all OpenGL
implementations; functions in the GLU library begin with the letters glu.
The third is called the OpenGL Utility Toolkit (GLUT), which provides the minimum
functionality that should be expected in any modern windowing system.
Dept. Of CSE, B.T.L.I.T3
GL
GLUT
GLX
Xlib, Xtk
Frame
buffer
OpenGL
Application
program
GLU
Library organization of OpenGL
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
4/47
Transparency
of polygons
CHAPTER 2
SYSTEM SPECIFICATION
2.1 SOFTWARE SPECIFICATION
Platform used: Microsoft XP/98.
Technology used: Microsoft (Visual Studio 2006) with OpenGL libraries.
Language: C/C++.
2.2 HARDWARE SPECIFICATION
This package has been developed on:
Pentium 4 or better.
40 GB hard disk.
128 MB RAM.
VGA Color Monitor.
However it has been designed to work on systems with minimal resources.
Dept. Of CSE, B.T.L.I.T4
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
5/47
Transparency
of polygons
CHAPTER 3
SOFTWARE DESCRIPTION
3.1 FRONT END
OpenGL has become a widely accepted standard for developing graphics application.
Most of our applications will be designed to access OpenGL directly through functions in
three libraries. Functions in main GL library have names that begin with the letters gl and
are stored in a library usually referred to as GL.
The second is the OpenGL Utility Library (GLU). This library uses only GL functions
but contains code for creating common objects and simplifying viewing. All functions in
GLU can be created from the core GL library. The GLU library is available in all OpenGL
implementations; functions in the GLU library begin with the letters glu.
The third is called the OpenGL Utility Toolkit (GLUT), which provides the minimum
functionality that should be expected in any modern windowing system.
Dept. Of CSE, B.T.L.I.T5
GL
GLUT
GLX
Xlib, Xtk
Frame
buffer
OpenGL
Application
program
GLU
Library organization of OpenGL
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
6/47
Transparency
of polygons
3.2 FEATURES
Visual Studio 2008 features include an XAML-based designer (codenamed Cider),
workflow designer, LINQ to SQL designer (for defining the type mappings and object
encapsulation for SQL Server data), XSLT debugger, JavaScript Intellisense support,
JavaScript Debugging support, support forUACmanifests, a concurrent build system, among
others. It ships with an enhanced set of UI widgets, both for Windows Forms and WPF. It
also includes a multithreaded build engine (MSBuild) to compile multiple source files (and
build the executable file) in a project across multiple threads simultaneously. It also includes
support for compiling PNG compressed icon resources introduced in Windows Vista. An
updated XML Schema designer will ship separately some time after the release of Visual
Studio 2008.
Dept. Of CSE, B.T.L.I.T6
http://en.wikipedia.org/wiki/XAMLhttp://en.wikipedia.org/wiki/Workflow_Foundationhttp://en.wikipedia.org/wiki/Language_Integrated_Queryhttp://en.wikipedia.org/wiki/SQLhttp://en.wikipedia.org/wiki/XSLThttp://en.wikipedia.org/wiki/JavaScripthttp://en.wikipedia.org/wiki/Intellisensehttp://en.wikipedia.org/wiki/User_Account_Controlhttp://en.wikipedia.org/wiki/Manifest_(.NET_Framework)http://en.wikipedia.org/wiki/Concurrent_programminghttp://en.wikipedia.org/wiki/WinFormshttp://en.wikipedia.org/wiki/Windows_Presentation_Foundationhttp://en.wikipedia.org/wiki/Thread_(computing)http://en.wikipedia.org/wiki/Portable_Network_Graphicshttp://en.wikipedia.org/wiki/Icon_(computing)http://en.wikipedia.org/wiki/Resource_(Windows)http://en.wikipedia.org/wiki/XML_Schema_(W3C)http://en.wikipedia.org/wiki/XAMLhttp://en.wikipedia.org/wiki/Workflow_Foundationhttp://en.wikipedia.org/wiki/Language_Integrated_Queryhttp://en.wikipedia.org/wiki/SQLhttp://en.wikipedia.org/wiki/XSLThttp://en.wikipedia.org/wiki/JavaScripthttp://en.wikipedia.org/wiki/Intellisensehttp://en.wikipedia.org/wiki/User_Account_Controlhttp://en.wikipedia.org/wiki/Manifest_(.NET_Framework)http://en.wikipedia.org/wiki/Concurrent_programminghttp://en.wikipedia.org/wiki/WinFormshttp://en.wikipedia.org/wiki/Windows_Presentation_Foundationhttp://en.wikipedia.org/wiki/Thread_(computing)http://en.wikipedia.org/wiki/Portable_Network_Graphicshttp://en.wikipedia.org/wiki/Icon_(computing)http://en.wikipedia.org/wiki/Resource_(Windows)http://en.wikipedia.org/wiki/XML_Schema_(W3C) -
8/6/2019 Polygons 2 Color Scree Shots 3copies
7/47
Transparency
of polygons
CHAPTER 4
PROJECT DESCRIPTION
4.1 OVERVIEW OF PROJECT
This graphics package entitled TRANSPARENCY OF POLYGONS IN VISUAL
C++ USING OPENGL aims at giving an idea about of rendering objects. Rendering objects
transparently gives additional insight in complex and overlapping structures. However,
traditional techniques for the rendering of transparent objects such as alpha blending are not
very well suited for the rendering of multiple transparent objects in dynamic scenes.
Screen door transparency is a technique to render transparent objects in a simple and
efficient way: no sorting is required and intersecting polygons can be handled without further
preprocessing. With this technique, polygons are rendered through a mask: only where the
mask is present, pixels are set. However, artifacts such as incorrect opacities and distracting
patterns can easily occur if the masks are not carefully designed. The requirements on the
masks are considered. Algorithms are presented for the creation of larger masks (e.g.3232).
The opacity of a surface is a measure of how much light penetrates through that
surface. An opacity of 1 (=1) corresponds to a completely opaque surface that blocks all
light incident on it. A surface with an opacity of 0 is transparent: All light passes through it.
The transparency or translucency of a surface with opacity is given by 1-.
In this project we have used Torus ,Icosahedrons ,Cone ,Teapot,
Dodecahedron and Tetrahedron to illustrate Screen door transparency using OpenGL.
The package has a user-friendly menu based interface. These aspects are implemented using
GLUT library. C++ user interface library.
Dept. Of CSE, B.T.L.I.T7
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
8/47
Transparency
of polygons
4.2 MODULE DESCRIPTION
Translation
Translation is done by adding the required amount of translation quantities to each of
the points of the objects in the selected area. If P(x,y) be the a point and (tx, ty) translation
quantities then the translated point is given by
P'(x,y) = p(x+tx,y+ty).
Rotation
The rotation of an object by an angle 'a' is accomplished by rotating each of the points
of the object. The rotated points can be obtained using the formula
Newx = oldx*cos(a) - oldy*sin(a)
Newy = oldx*sin(a) + oldy*cos(a)
Forrotation by an angle clockwise about the origin, the functional form is x' = xcos +ysin and y' = xsin + ycos. Written in matrix form, this becomes:
Similarly, for a rotation counter-clockwise about the origin, the functional form is x' = xcos ysin and y' = xsin + ycos and the matrix form is:
The OpenGL provides very powerful translation, rotation and scaling facilities which
relive the programmers by allowing them to concentrate on their job rather than focusing on
how to implement these operations. OpenGL also provides viewing and modeling
transformations.
Dept. Of CSE, B.T.L.I.T8
http://en.wikipedia.org/wiki/Coordinate_rotationhttp://en.wikipedia.org/wiki/Coordinate_rotationhttp://en.wikipedia.org/wiki/Coordinate_rotation -
8/6/2019 Polygons 2 Color Scree Shots 3copies
9/47
Transparency
of polygons
glutInitDisplayMode sets the initial display mode.
Declaration:
Void glutInitDisplayMode (unsigned int mode);
Remarks: The initial display mode is used when creating top-
level windows, sub windows, and overlays to determine the OpenGL
display mode for the to-be-created window or overlay.
glutInitWindowposition set the initial window position.
Declaration:
void glutInitWindowPosition(int x, int y);
x :Window X location in pixels.
y:Window Y location in pixels.
glutInitWindowSize set the initial window size.
Declaration:
void glutInitWindowSize(int width,int height);
width :Width in pixels.
Height :Height in pixels.
glutPostRedisplay
Declaration:Void glutPostRedisplay();
Remarks : This function request that display call back be
executed after the current callback returns.
glutAttachMenu
Declaration:
Void glutAttachMenu(int button);
Dept. Of CSE, B.T.L.I.T9
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
10/47
Transparency
of polygons
Remarks: This function attaches the current menu to the
specified mouse button.
glutAddSubMenu
Declaration:
Void glutAddSubMenu(char * name,int value);
Remarks: This function adds a sub menu with the string name
to the menu.
glutSwapBuffers
Declaration:
Void glutSwapBuffers();
Remarks:This function swaps the front and the back buffers.
glutDisplayFunc
Declaration:
Void glutDisplayFunc(void(*func)void));
Remarks: This function registers the display function that is
executed when the window needs to be redrawn.
glClear
Declaration:
Void glClear();
Remarks: This function clears the particular buffer.
glclearColor
Declaration:
Void glClearColor(GLfloatred,GLfloat green,Glfloat
blue,Glfloat alpha);
Remarks: This function sets the color value that is used whenDept. Of CSE, B.T.L.I.T10
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
11/47
Transparency
of polygons
clearing the color buffer.
glEnd
Declaration:
Void glEnd();
Remarks: This function is used in conjuction with glBegin to
delimit the vertices of an opengl primitive.
glRotate
Declaration:
Void glRotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble
z);
Remarks: This function multiplies the current matrix by a
rotation matrix that performs a counterclockwise rotation around a
directional vector that passes from the origin through the point(x,y,z).
glScale
Declaration:
Void glScaled(GLdouble x,GLdouble y,GLdouble z);
Remarks: This function multiplies the current matrix by a
scaling matrix.
glTranslate
Declaration:
Void glTranslated(GLdouble x,GLdouble y,GLdouble z);
Remarks: This function multiplies the current matrix by a
translation matrix.
glPopMatrixand glPushMatrix
Declaration:
Void glPushMatrix();
Void glPopMatrix();
Dept. Of CSE, B.T.L.I.T11
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
12/47
Transparency
of polygons
Remarks: This function pushes and pops from the matrix stack
corresponding to the current matrix mode.
glDisableand glEnable
Declaration:
void glDisable(GLenum feature);
void glEnable(GLenum feature);
Remarks: This glDisable disables an opengl drawing
feature,and glEnableenables an opengl drawing feature.
glmatrixmode
Declaration:
Void glMatrixMode(GLenum mode);
Remarks: This function specifies which matrix will be affected
by subsequent transformations mode can be
GL_MODELVIEW,GL_PROJECTION or GL_TEXTURE.
glLightfv
Declaration:
Void glLightfv(GLenum light,GLenum param,TYPE value);
Remarks: It sets the scalar and vector parameter param for light
source light.
glViewport
Declaration:Void glViewport(int x,int y,GLsizei width,GLsizei height);
Remarks:It specifies a width height viewport in pixels whose
lower left corner is at (x,y) measured from the origin of the window.
glOrtho
Declaration:
Dept. Of CSE, B.T.L.I.T12
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
13/47
Transparency
of polygons
Void glOrtho(GLdouble left, GLdouble right, GLdouble
bottom,GLdouble top,GLdouble near,GLdouble far);
Remarks:It defines an orthographic viewing volume with all
parameters measured from the center of the projection plane.
Reshape
Declaration:
Void ReshapeFunc(int width,int height);
Remarks:It registers the reshape callback function f.The
callback function returns the height and width of the new window. The
reshape callback invokes a display callback.
Torus
Declaration:
Void glutSolidTorus(GLdouble innerradius,GLdouble outerradius,
Glint nsides,Glint rings);
Remarks:Renders a solid torus centered at origin.
Tetrahedron
Declarations:
Void glutSolidTetrahedron();
Remarks:Renders a solid tetrahedron centered at the modeling
coordinates origin with a radius of 3.
KeyboardFunc
Declaration:
Void glutKeyboardFunc(void (*func)(unsigned char key,int x,int y));
Remarks: Func is called when event of keypress happened. x,y
specify mouse position when key is pressed. In this sample function.
MouseFunc
Dept. Of CSE, B.T.L.I.T13
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
14/47
Transparency
of polygons
Declaration:
Void glutMouseFunc(void (*func)(int button,int state,int x,int y));
Remarks: Sets the function that handles mouse clicks occurring in
the Gl windows.
Icosahedron
Declaration:
Void glutIsocahedron();
Remarks:Renders the solid isocahedron centered at the modeling
coordinates origin with a radius of 1.0.
Dodecahedron
Declaration:
Void glutDodecahedron();
Remarks:Renders the solid dodecahedron centered at the modeling
coordinates origin with a radius of 3.
Teapot
Declaration:
Void glutSolidTeapot(Gldouble dim);
Remarks:Renders the solid teapot centered at the modeling
coordinates origin with the given dimension.
Cone
Declaration:
Void glutSolidCone(GLdouble baseradius,GLdouble height,Glint
slices,Glint stacks);
Remarks:Renders the solid cone centered at the modeling
coordinates origin with the given base radius and given height in Z
axis.
Dept. Of CSE, B.T.L.I.T14
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
15/47
Transparency
of polygons
Dept. Of CSE, B.T.L.I.T15
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
16/47
Transparency
of polygons
4.3 DATAFLOW DIAGRAM
LEFT MOUSE BUTTONDept. Of CSE, B.T.L.I.T16
START
MAIN
INITIALIZE
CALLBACKFUNCTIONS
MOUSEBUTTON
RIGHTCLICK
TEAPOTCONE
50%OPAQUE
ROTATEUP
100%OPAQUE
ICOSAHEDRON
DODECAHEDRON
EVENTS
0%OPAQUE
ROTATEDOWN
TETRAHEDRON
TORUS
STOP
QUIT
END
ROTATELEFT
ROTATERIGHT
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
17/47
Transparency
of polygons
4.4 INPUT DESIGN
Figure above is input for mouse event on the press of RIGHT key,in
the output screen link is generated from credit sheet to the main output screen.
Figure above is mouse event for transperency of polygons.
4.5 OUTPUT DESIGN
Figure above in the output design which accepts the mouse
event and generates the required output on to the display screen.
Dept. Of CSE, B.T.L.I.T17
ON right
click
Mouse
Event
Link from creditto output screen
Main outputscreen
Mouse
Event
Select any onepolygons from thelist Diplay on
screen
Uponmouse
Event
Generate therequired
output
Display on
the screen
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
18/47
Transparency
of polygons
CHAPTER 5
CONCLUSION
I had a great experience in the course of designing this package, which made mediscover and learn many things as, pertain to the topic of OpenGL programming. I have tried
to my best potential to incorporate all the basic level requirements of a normal graphics
package for Windows operating system.
This is very reliable graphics package supporting various objects like circle, ellipse,
rectangle, square, cube, sphere, cone, octahedron, dodecahedron, icosahedrons etc. for both
solid and wireframe. Also color selection, menu based interface are included. Transformation
like translation, rotations are also provided.
Owing to certain constraints I could not incorporate all the tasks that a graphics
package should perform. However it meets the basic requirements of user successfully. Since
its user friendly it enables the user to interact effectively and easily.
Special attention has been provided to the interfaces, menus and submenus that make
its use comfortable. I hope this package proves to be flexible in all respects to one and all.
Dept. Of CSE, B.T.L.I.T18
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
19/47
Transparency
of polygons
CHAPTER 6
FUTURE ENHANCEMENTS
This project has been designed using C++, which works on the Windows platform.
The project can be designed using other languages and better graphical interfaces. The
following features could have been incorporated:
Resizing windows.
Better backgrounds.
Choosing colors.
Individual polygon rotation.
Dept. Of CSE, B.T.L.I.T19
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
20/47
Transparency
of polygons
CHAPTER 7
APPENDIX
7.1 SOURCE CODE
/* screendoor demonstrates "screen door" transparency using
OpenGL's polygon stipple feature. */
/* ICOSAHEDRON-A geometrical shape occurring in many virus particles, with 20
triangular faces and 12 corners.
TETRAHEDRON-A tetrahedron (plural: tetrahedra) is a polyhedron composed of four
triangular faces, three of which meet at each vertex.
A regular tetrahedron is one in which the four triangles are regular, or "equilateral", and is
one of the Platonic solids.
TORUS-(geometry) A three-dimensional shape consisting of a ring with a circular cross-
section.
The shape of an inner tube or hollow doughnut.
*/
#include
//#include
#include
Dept. Of CSE, B.T.L.I.T20
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
21/47
Transparency
of polygons
#define TORUS 1
#define TETRAHEDRON 2
#define ICOSAHEDRON 3
#define CONE 4
#define DODECAHEDRON 5
#define TEAPOT 6
/*Screen-door transparency uses a bit mask to cause certain pixels not to be rasterized. The
percentage of bits in the bitmask which are set to 1 is equivalent to the transparency of the
object [27].
In OpenGL, screen-door transparency is implemented using polygon stippling.*/
#if 0 /* Comment containing C comments. */
Example usage:
/* Assumes default unpack pixel store settings; see glPixelStore */
glEnable(GL_POLYGON_STIPPLE);
glPolygonStipple(stippleMask[0]); /* 0% opaqueness */
glPolygonStipple(stippleMask[8]); /* 50% opaqueness */
glPolygonStipple(stippleMask[16]); /* 100% opaqueness */
Dept. Of CSE, B.T.L.I.T21
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
22/47
Transparency
of polygons
#endif
const GLubyte stippleMask[17][128] =
{
/* NOTE: 0% opaqueness is faster to set and probably faster to render with:
glDisable(GL_POLYGON_STIPPLE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); */
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00},
Dept. Of CSE, B.T.L.I.T22
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
23/47
Transparency
of polygons
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77},
/* NOTE: 100% opaqueness is faster to set and probably faster to render with:
glDisable(GL_POLYGON_STIPPLE); */
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
};
/* to do modification*/
GLfloat angle = 20.0;
Dept. Of CSE, B.T.L.I.T23
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
24/47
Transparency
of polygons
int torusStipple = 4,dodecStipple = 6,teaptStipple = 8, icoStipple = 8, tetraStipple =
16,coneStipple=4;
/* Initialize material property and light source. */
void
myinit(void)
{
GLfloat light_ambient[] =
{0.2, 0.2, 0.2, 1.0}; /*to achieve uniform light level*/
GLfloat light_diffuse[] =
{1.0, 1.0, 1.0, 1.0}; /*to appear same,scattered eqally*/
GLfloat light_specular[] =
{1.0, 1.0, 1.0, 1.0}; /* to appear shiny through reflection */
GLfloat light_position[] =
{1.0, 1.0, 1.0, 0.0};
glClearColor(0.49, 0.62, 0.75, 0.0);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
Dept. Of CSE, B.T.L.I.T24
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
25/47
Transparency
of polygons
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0); //to enable the light glenable=enable the openGL function
glDepthFunc(GL_LESS); //Passes if the incoming depth value is less than the stored depth
value.
glEnable(GL_DEPTH_TEST); //to enable z-buff alg
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);//to change the behavior of polygon face
glEnable(GL_POLYGON_STIPPLE);
/*Lighting, means tell gl to use lighting calculations in the render pipline.
LIGHT0, is a definition of a light implementation. i.e. type of light, position,
color, attenuation etc. etc..*/
glNewList(TORUS, GL_COMPILE);
glutSolidTorus(0.275, 0.85, 10, 15);
glEndList();
glNewList(TETRAHEDRON, GL_COMPILE);
glutSolidTetrahedron();
glEndList();
glNewList(DODECAHEDRON, GL_COMPILE);
Dept. Of CSE, B.T.L.I.T25
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
26/47
Transparency
of polygons
glutSolidDodecahedron();
glEndList();
glNewList(TEAPOT, GL_COMPILE);
glutSolidTeapot(0.6);
glEndList();
glNewList(ICOSAHEDRON, GL_COMPILE);
glutSolidIcosahedron();
glEndList();
glNewList(CONE, GL_COMPILE);
glutSolidCone(0.5,1.5,20,16);
glEndList();
}
void
display1(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glScalef(1.3, 1.3, 1.3);
glRotatef(angle,0.0,1.0,0.0);
glPushMatrix();
Dept. Of CSE, B.T.L.I.T26
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
27/47
Transparency
of polygons
glTranslatef(-0.75, -0.5, 0.0);
glRotatef(270.0, 1.0, 0.0, 0.0);
glPolygonStipple(stippleMask[tetraStipple]);
/*This is accomplished by specifying a polygon stipple
pattern with glPolygonStipple() and by rendering the
transparent primitive with polygon stippling enabled
(glEnable(GL_POLYGON_STIPPLE)). The number of bits
set in the stipple pattern determine the amount of
translucency and opacity; setting more bits result
in a more opaque object, and setting fewer bits
results in a more translucent object. */
glCallList(TETRAHEDRON);
glPopMatrix();
glPushMatrix();
glScalef(0.5,0.5,0.5);
glTranslatef(-3.5, -1.5, 0.0);
//glRotatef(135.0, 0.0, 0.0, 1.0);
glPolygonStipple(stippleMask[dodecStipple]);
glCallList(DODECAHEDRON);
glPopMatrix();
glPushMatrix();
Dept. Of CSE, B.T.L.I.T27
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
28/47
Transparency
of polygons
glTranslatef(1.9, -0.5, 0.0);
glRotatef(0.0, 0.0, 0.0, 1.0);
glPolygonStipple(stippleMask[teaptStipple]);
glCallList(TEAPOT);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.75, 0.5, 0.0);
glRotatef(90.0, 1.0, 0.0, 0.0);
glPolygonStipple(stippleMask[torusStipple]);
glCallList(TORUS);
glPopMatrix();
glPushMatrix();
glTranslatef(0.75, 0.0, -1.0);
glPolygonStipple(stippleMask[icoStipple]);
glCallList(ICOSAHEDRON);
glPopMatrix();
glPushMatrix();
glTranslatef(-2.0, 0.0, -1.0);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glPolygonStipple(stippleMask[coneStipple]);
glCallList(CONE);
Dept. Of CSE, B.T.L.I.T28
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
29/47
Transparency
of polygons
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glScalef(1.3, 1.3, 1.3);
glRotatef(angle,1.0,0.0,0.0);
glPushMatrix();
glTranslatef(-0.75, -0.5, 0.0);
glRotatef(270.0, 1.0, 0.0, 0.0);
glPolygonStipple(stippleMask[tetraStipple]);
glCallList(TETRAHEDRON);
glPopMatrix();
Dept. Of CSE, B.T.L.I.T29
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
30/47
Transparency
of polygons
glPushMatrix();
glScalef(0.5,0.5,0.5);
glTranslatef(-3.5, -1.5, 0.0);
//glRotatef(135.0, 0.0, 0.0, 1.0);
glPolygonStipple(stippleMask[dodecStipple]);
glCallList(DODECAHEDRON);
glPopMatrix();
glPushMatrix();
glTranslatef(1.9, -0.5, 0.0);
glRotatef(0.0, 0.0, 0.0, 1.0);
glPolygonStipple(stippleMask[teaptStipple]);
glCallList(TEAPOT);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.75, 0.5, 0.0);
glRotatef(90.0, 1.0, 0.0, 0.0);
glPolygonStipple(stippleMask[torusStipple]);
glCallList(TORUS);
glPopMatrix();
glPushMatrix(); //to save present values of matrics
Dept. Of CSE, B.T.L.I.T30
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
31/47
Transparency
of polygons
glTranslatef(0.75, 0.0, -1.0);
glPolygonStipple(stippleMask[icoStipple]);
glCallList(ICOSAHEDRON);
glPopMatrix(); //to remove
glPushMatrix();
glTranslatef(-2.0, 0.0, -1.0);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glPolygonStipple(stippleMask[coneStipple]);
glCallList(CONE);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void
reshape(int w, int h)
{
glViewport(0, 0, w, h);//avoid distortion to match aspectratio
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
32/47
Transparency
of polygons
glOrtho(-2.5, 2.5, -2.5 * (GLfloat) h / (GLfloat) w,
2.5 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
else
glOrtho(-2.5 * (GLfloat) w / (GLfloat) h,
2.5 * (GLfloat) w / (GLfloat) h, -2.5, 2.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}
void
torusTransparency(int value)
{
torusStipple = value;
glutPostRedisplay();
}
void
icoTransparency(int value)
{
icoStipple = value;
glutPostRedisplay();
}
void
Dept. Of CSE, B.T.L.I.T32
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
33/47
Transparency
of polygons
tetraTransparency(int value)
{
tetraStipple = value;
glutPostRedisplay();
}
void
coneTransparency(int value)
{
coneStipple = value;
glutPostRedisplay();
}
void
dodecTransparency(int value)
{
dodecStipple = value;
glutPostRedisplay();
}
void
teaptTransparency(int value)
{
teaptStipple = value;
glutPostRedisplay();
}
Dept. Of CSE, B.T.L.I.T33
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
34/47
Transparency
of polygons
void
noop(int value)
{
switch(value) {
case 1:
angle -= 25;
display();
break;
case 2:
angle += 25;
display();
break;
case 3:
angle -= 25;
display1();
break;
case 4:
angle += 25;
display1();
break;
case 666:
exit(0);
Dept. Of CSE, B.T.L.I.T34
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
35/47
Transparency
of polygons
}
//glutPostRedisplay();
}
void
createTransparencyMenu(void)
{
char label[20];
int i;
for (i = 0; i < 3; i++) {
sprintf(label, "%d opaque", i * 100 / 2);
glutAddMenuEntry(label, i);
}
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN) {
angle -= 25;
display();
}
Dept. Of CSE, B.T.L.I.T35
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
36/47
Transparency
of polygons
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN) {
angle += 25;
display();
}
break;
default:
break;
}
}
void keys(unsigned char key, int x, int y)
//Note: because there is an Idle-func, we don't have to call Display here
{
switch(key)
{
case 'R':
case 'r':
glClearColor(1.0,0.0,0.0,1.0);
display();
break;
case 'B':
Dept. Of CSE, B.T.L.I.T36
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
37/47
Transparency
of polygons
case 'b':
glClearColor(0.0,0.0,1.0,1.0);
display();
break;
case 'G':
case 'g':
glClearColor(0.0,1.0,0.0,1.0);
display();
break;
case 'K':
case 'k':
glClearColor(0.0,0.0,0.0,1.0);
display();
break;
case 'W':
case 'w':
glClearColor(1.0,1.0,1.0,1.0);
display();
break;
case 'Y':
case 'y':
glClearColor(1.0,1.0,0.0,1.0);
Dept. Of CSE, B.T.L.I.T37
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
38/47
Transparency
of polygons
display();
break;
case 'O':
case 'o':
glClearColor(1.0,0.4,0.0,1.0);
display();
break;
case 'C':
case 'c':
glClearColor(1.0,0.0,1.0,1.0);
display();
break;
default :
glClearColor(0.49, 0.62, 0.75, 0.0);
}
}
int
main(int argc, char **argv)
{
int torusMenu, icoMenu, tetraMenu,coneMenu,dodecMenu,teaptMenu;
char key;
glutInit(&argc, argv);
Dept. Of CSE, B.T.L.I.T38
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
39/47
Transparency
of polygons
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(640,480);
glutCreateWindow("screen door transparency");
glutKeyboardFunc(keys);
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutDisplayFunc(display1);
glutReshapeFunc(reshape);
myinit();
torusMenu = glutCreateMenu(torusTransparency);
createTransparencyMenu();
icoMenu = glutCreateMenu(icoTransparency);
createTransparencyMenu();
tetraMenu = glutCreateMenu(tetraTransparency);
createTransparencyMenu();
coneMenu = glutCreateMenu(coneTransparency);
createTransparencyMenu();
dodecMenu = glutCreateMenu(dodecTransparency);
createTransparencyMenu();
teaptMenu = glutCreateMenu(teaptTransparency);
createTransparencyMenu();
Dept. Of CSE, B.T.L.I.T39
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
40/47
Transparency
of polygons
glutCreateMenu(noop);
glutAddSubMenu("Torus", torusMenu);
glutAddSubMenu("Icosahedron", icoMenu);
glutAddSubMenu("Tetrahedron", tetraMenu);
glutAddSubMenu("Cone", coneMenu);
glutAddSubMenu("Dodecahedron", dodecMenu);
glutAddSubMenu("Teapot", teaptMenu);
glutAddMenuEntry("Rotate up", 1);
glutAddMenuEntry("Rotate down", 2);
glutAddMenuEntry("Rotate left",3);
glutAddMenuEntry("Rotate right",4);
glutAddMenuEntry("Quit", 666);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}
Dept. Of CSE, B.T.L.I.T40
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
41/47
Transparency
of polygons
7.2 SCREEN SHOTS
Screenshot 1
Fig 7.21 Complete 100% transparent polygons.
Screenshot 2
Dept. Of CSE, B.T.L.I.T41
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
42/47
Transparency
of polygons
Fig 7.22 Complete 100% opaque Torus.
Screenshot 3
Fig 7.23 Complete 100% opaque Icosahedron.
Screenshot 4
Dept. Of CSE, B.T.L.I.T42
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
43/47
Transparency
of polygons
Fig 7.24 Complete 100% opaque Tetrahedron.
Screenshot 5
Fig 6.1.5 Complete 100% opaque Cone.
Screenshot6
Dept. Of CSE, B.T.L.I.T43
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
44/47
Transparency
of polygons
Fig 6.1.6 Complete 100% opaque Dodecahedron.
Screenshot 7
Fig 6.1.7 Complete 100% opaque Teapot.
Screenshot 8
Dept. Of CSE, B.T.L.I.T44
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
45/47
Transparency
of polygons
Fig 6.1.8 100% opaque polygons.
Screenshot 9
Fig 6.1.9 Downward rotation of the polygons.
Dept. Of CSE, B.T.L.I.T45
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
46/47
Transparency
of polygons
Screenshot 10:
Fig 6.1.10 Upward rotation of the polygons.
CHAPTER 8
REFERENCES
BOOKS
Edward Angel, Interactive Computer Graphics,5th
edition, Pearson
Education,2005.
Computer Graphics, Addison-Wesley 1997 James D Foley, Andries Van
Dam, Steven K Feiner, John F Huges.
Dept. Of CSE, B.T.L.I.T46
-
8/6/2019 Polygons 2 Color Scree Shots 3copies
47/47
Transparency
of polygons
F.S.Hill and Stephen M.Kelly ,Computer Graphics using OpenGl ,3rd
Edition.
WEBSITES
http://www.opengl.org.
http://www.wikipedia.com.
http://basic4gl.wikispaces.com.
http://www.opengl.org/http://www.opengl.org/http://www.wikipedia.com/http://basic4gl.wikispaces.com/http://www.opengl.org/http://www.wikipedia.com/http://basic4gl.wikispaces.com/