SlideShare a Scribd company logo
1 of 21
Programming with OpenGL
Part 2: Complete Programs
1
Objectives
• Refine the first program
• Alter the default values
• Introduce a standard program structure
• Simple viewing
• Two-dimensional viewing as a special case of three-dimensional viewing
• Fundamental OpenGL primitives
• Attributes
2
Program Structure
•Most OpenGL programs have a similar structure that
consists of the following functions
• main():
• defines the callback functions
• opens one or more windows with the required properties
• enters event loop (last executable statement)
• init(): sets the state variables
• Viewing
• Attributes
• callbacks
• Display function
• Input and window functions
3
simple.c revisited
• In this version, we shall see the same output but we have defined all
the relevant state values through function calls using the default
values
• In particular, we set
• Colors
• Viewing conditions
• Window properties
4
main.c
#include <GL/glut.h>
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("simple");
glutDisplayFunc(mydisplay);
init();
glutMainLoop();
}
5
includes gl.h
define window properties
set OpenGL state
enter event loop
display callback
GLUT functions
• glutInit allows application to get command line
arguments and initializes system
• gluInitDisplayMode requests properties for the
window (the rendering context)
• RGB color
• Single buffering
• Properties logically ORed together
• glutWindowSize in pixels
• glutWindowPosition from top-left corner of display
• glutCreateWindow create window with title “simple”
• glutDisplayFunc display callback
• glutMainLoop enter infinite event loop
6
init.c
void init()
{
glClearColor (0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}
7
black clear color
opaque window
fill/draw with white
viewing volume
Coordinate Systems
•The units in glVertex are determined by the
application and are called object or problem
coordinates
•The viewing specifications are also in object
coordinates and it is the size of the viewing volume
that determines what will appear in the image
•Internally, OpenGL will convert to camera (eye)
coordinates and later to screen coordinates
•OpenGL also uses some internal representations that
usually are not visible to the application
8
OpenGL Camera
• OpenGL places a camera at the origin in object space pointing in the
negative z direction
• The default viewing volume
is a box centered at the
origin with a side of
length 2
9
Orthographic Viewing
10
z=0
z=0
In the default orthographic view, points are
projected forward along the z axis onto the
plane z=0
Transformations and Viewing
•In OpenGL, projection is carried out by a projection
matrix (transformation)
•There is only one set of transformation functions so
we must set the matrix mode first
glMatrixMode (GL_PROJECTION)
• Transformation functions are incremental so we start
with an identity matrix and alter it with a projection
matrix that gives the view volume
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
11
Two- and three-dimensional viewing
• In glOrtho(left, right, bottom, top,
near, far) the near and far distances are measured
from the camera
• Two-dimensional vertex commands place all vertices in
the plane z=0
• If the application is in two dimensions, we can use the
function
gluOrtho2D(left, right,bottom,top)
• In two dimensions, the view or clipping volume becomes a
clipping window
12
mydisplay.c
void mydisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
13
OpenGL Primitives
14
GL_QUAD_STRIPGL_QUAD_STRIP
GL_POLYGONGL_POLYGON
GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP GL_TRIANGLE_FANGL_TRIANGLE_FAN
GL_POINTSGL_POINTS
GL_LINESGL_LINES
GL_LINE_LOOPGL_LINE_LOOP
GL_LINE_STRIPGL_LINE_STRIP
GL_TRIANGLESGL_TRIANGLES
Polygon Issues
•OpenGL will only display polygons correctly that are
• Simple: edges cannot cross
• Convex: All points on line segment between two points in a
polygon are also in the polygon
• Flat: all vertices are in the same plane
•User program can check if above true
• OpenGL will produce output if these conditions are violated but it
may not be what is desired
•Triangles satisfy all conditions
15
nonsimple polygon
nonconvex polygon
Attributes
• Attributes are part of the OpenGL state and determine the
appearance of objects
• Color (points, lines, polygons)
• Size and width (points, lines)
• Stipple pattern (lines, polygons)
• Polygon mode
• Display as filled: solid color or stipple pattern
• Display edges
• Display vertices
16
RGB color
•Each color component is stored separately in the
frame buffer
•Usually 8 bits per component in buffer
•Note in glColor3f the color values range from 0.0
(none) to 1.0 (all), whereas in glColor3ub the
values range from 0 to 255
17
Indexed Color
• Colors are indices into tables of RGB values
• Requires less memory
• indices usually 8 bits
• not as important now
• Memory inexpensive
• Need more colors for shading
18
Color and State
•The color as set by glColor becomes part of the
state and will be used until changed
• Colors and other attributes are not part of the object but are assigned when
the object is rendered
•We can create conceptual vertex colors by code such
as
glColor
glVertex
glColor
glVertex
19
Smooth Color
•Default is smooth shading
• OpenGL interpolates vertex colors across visible polygons
•Alternative is flat shading
• Color of first vertex
determines fill color
• glShadeModel
(GL_SMOOTH)
or GL_FLAT
20
Viewports
• Do not have use the entire window for the image:
glViewport(x,y,w,h)
• Values in pixels (screen coordinates)
21

More Related Content

Similar to Programming with OpenGL

Similar to Programming with OpenGL (20)

Open gl basics
Open gl basicsOpen gl basics
Open gl basics
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
 
Better Interactive Programs
Better Interactive ProgramsBetter Interactive Programs
Better Interactive Programs
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
18csl67 vtu lab manual
18csl67 vtu lab manual18csl67 vtu lab manual
18csl67 vtu lab manual
 
CGV.pptx
CGV.pptxCGV.pptx
CGV.pptx
 
Computer Viewing
Computer ViewingComputer Viewing
Computer Viewing
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading Language
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
Shading in OpenGL
Shading in OpenGLShading in OpenGL
Shading in OpenGL
 
2D graphics
2D graphics2D graphics
2D graphics
 
GLSL
GLSLGLSL
GLSL
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
Graphical Objects and Scene Graphs
Graphical Objects and Scene GraphsGraphical Objects and Scene Graphs
Graphical Objects and Scene Graphs
 
Chapter-3.pdf
Chapter-3.pdfChapter-3.pdf
Chapter-3.pdf
 
Bai 1
Bai 1Bai 1
Bai 1
 

More from Syed Zaid Irshad

More from Syed Zaid Irshad (20)

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdf
 
DBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionDBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_Solution
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Professional Issues in Computing
Professional Issues in ComputingProfessional Issues in Computing
Professional Issues in Computing
 
Reduce course notes class xi
Reduce course notes class xiReduce course notes class xi
Reduce course notes class xi
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
C Language
C LanguageC Language
C Language
 
Flowchart
FlowchartFlowchart
Flowchart
 
Algorithm Pseudo
Algorithm PseudoAlgorithm Pseudo
Algorithm Pseudo
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book Introduction
 
Security, Copyright and the Law
Security, Copyright and the LawSecurity, Copyright and the Law
Security, Copyright and the Law
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
Data Communication
Data CommunicationData Communication
Data Communication
 
Information Networks
Information NetworksInformation Networks
Information Networks
 
Basic Concept of Information Technology
Basic Concept of Information TechnologyBasic Concept of Information Technology
Basic Concept of Information Technology
 
Introduction to ICS 1st Year Book
Introduction to ICS 1st Year BookIntroduction to ICS 1st Year Book
Introduction to ICS 1st Year Book
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 

Recently uploaded

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...Health
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxnuruddin69
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 

Recently uploaded (20)

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 

Programming with OpenGL

  • 1. Programming with OpenGL Part 2: Complete Programs 1
  • 2. Objectives • Refine the first program • Alter the default values • Introduce a standard program structure • Simple viewing • Two-dimensional viewing as a special case of three-dimensional viewing • Fundamental OpenGL primitives • Attributes 2
  • 3. Program Structure •Most OpenGL programs have a similar structure that consists of the following functions • main(): • defines the callback functions • opens one or more windows with the required properties • enters event loop (last executable statement) • init(): sets the state variables • Viewing • Attributes • callbacks • Display function • Input and window functions 3
  • 4. simple.c revisited • In this version, we shall see the same output but we have defined all the relevant state values through function calls using the default values • In particular, we set • Colors • Viewing conditions • Window properties 4
  • 5. main.c #include <GL/glut.h> int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("simple"); glutDisplayFunc(mydisplay); init(); glutMainLoop(); } 5 includes gl.h define window properties set OpenGL state enter event loop display callback
  • 6. GLUT functions • glutInit allows application to get command line arguments and initializes system • gluInitDisplayMode requests properties for the window (the rendering context) • RGB color • Single buffering • Properties logically ORed together • glutWindowSize in pixels • glutWindowPosition from top-left corner of display • glutCreateWindow create window with title “simple” • glutDisplayFunc display callback • glutMainLoop enter infinite event loop 6
  • 7. init.c void init() { glClearColor (0.0, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } 7 black clear color opaque window fill/draw with white viewing volume
  • 8. Coordinate Systems •The units in glVertex are determined by the application and are called object or problem coordinates •The viewing specifications are also in object coordinates and it is the size of the viewing volume that determines what will appear in the image •Internally, OpenGL will convert to camera (eye) coordinates and later to screen coordinates •OpenGL also uses some internal representations that usually are not visible to the application 8
  • 9. OpenGL Camera • OpenGL places a camera at the origin in object space pointing in the negative z direction • The default viewing volume is a box centered at the origin with a side of length 2 9
  • 10. Orthographic Viewing 10 z=0 z=0 In the default orthographic view, points are projected forward along the z axis onto the plane z=0
  • 11. Transformations and Viewing •In OpenGL, projection is carried out by a projection matrix (transformation) •There is only one set of transformation functions so we must set the matrix mode first glMatrixMode (GL_PROJECTION) • Transformation functions are incremental so we start with an identity matrix and alter it with a projection matrix that gives the view volume glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 11
  • 12. Two- and three-dimensional viewing • In glOrtho(left, right, bottom, top, near, far) the near and far distances are measured from the camera • Two-dimensional vertex commands place all vertices in the plane z=0 • If the application is in two dimensions, we can use the function gluOrtho2D(left, right,bottom,top) • In two dimensions, the view or clipping volume becomes a clipping window 12
  • 15. Polygon Issues •OpenGL will only display polygons correctly that are • Simple: edges cannot cross • Convex: All points on line segment between two points in a polygon are also in the polygon • Flat: all vertices are in the same plane •User program can check if above true • OpenGL will produce output if these conditions are violated but it may not be what is desired •Triangles satisfy all conditions 15 nonsimple polygon nonconvex polygon
  • 16. Attributes • Attributes are part of the OpenGL state and determine the appearance of objects • Color (points, lines, polygons) • Size and width (points, lines) • Stipple pattern (lines, polygons) • Polygon mode • Display as filled: solid color or stipple pattern • Display edges • Display vertices 16
  • 17. RGB color •Each color component is stored separately in the frame buffer •Usually 8 bits per component in buffer •Note in glColor3f the color values range from 0.0 (none) to 1.0 (all), whereas in glColor3ub the values range from 0 to 255 17
  • 18. Indexed Color • Colors are indices into tables of RGB values • Requires less memory • indices usually 8 bits • not as important now • Memory inexpensive • Need more colors for shading 18
  • 19. Color and State •The color as set by glColor becomes part of the state and will be used until changed • Colors and other attributes are not part of the object but are assigned when the object is rendered •We can create conceptual vertex colors by code such as glColor glVertex glColor glVertex 19
  • 20. Smooth Color •Default is smooth shading • OpenGL interpolates vertex colors across visible polygons •Alternative is flat shading • Color of first vertex determines fill color • glShadeModel (GL_SMOOTH) or GL_FLAT 20
  • 21. Viewports • Do not have use the entire window for the image: glViewport(x,y,w,h) • Values in pixels (screen coordinates) 21