Java Swing continued Swing component hierarchy Graphical components

  • Slides: 99
Download presentation
Java Swing, continued

Java Swing, continued

Swing component hierarchy • Graphical components in Java form an inheritance hierarchy: java. lang.

Swing component hierarchy • Graphical components in Java form an inheritance hierarchy: java. lang. Object +--java. awt. Component +--java. awt. Container | +--javax. swing. JComponent | +--javax. swing. JButton | +--javax. swing. JLabel | +--javax. swing. JMenu. Bar | +--javax. swing. JOption. Pane | +--javax. swing. JPanel | +--javax. swing. JText. Area | +--javax. swing. JText. Field | +--java. awt. Window +--java. awt. Frame +--javax. swing. JFrame • When doing GUI programming, always import these packages: import java. awt. *; import javax. swing. *;

What Can be Summarized? Derived a new container class from, say, JFrame In the

What Can be Summarized? Derived a new container class from, say, JFrame In the derived class • Define a constructor that sets up the title and size of the window • Set up the proper lay out of the outer container • Create inner containers (using JPanel or other containers) • Set up the proper lay out of each inner containers • Add the interface objects, such as buttons and others, to the corresponding containers • Remember to associate a listener object for each interface object • Add the containers to the Frame object in order Define listener classes to handle possible events fired by the interface objects added in the window In the main function • Create the object of the derived window class • Launch the interface by setting it as visible

TEXT FIELD AND TEXT AREA AND SCROLL BARS

TEXT FIELD AND TEXT AREA AND SCROLL BARS

Text Field and Text Area Examples

Text Field and Text Area Examples

Text Fields • A text field is an object of the class JText. Field

Text Fields • A text field is an object of the class JText. Field – It is displayed as a field that allows the user to enter a single line of text private JText. Field name; . . . name = new JText. Field(NUMBER_OF_CHAR); – In the text field above, at least NUMBER_OF_CHAR characters can be visible

Text Fields • There is also a constructor with one additional String parameter for

Text Fields • There is also a constructor with one additional String parameter for displaying an initial String in the text field JText. Field name = new JText. Field( "Enter name here. ", 30); • A Swing GUI can read the text in a text field using the get. Text method String input. String = name. get. Text(); • The method set. Text can be used to display a new text string in a text field name. set. Text("This is some output");

A Text Field (Part 6 of 7)

A Text Field (Part 6 of 7)

A Text Field (Part 7 of 7) What layout is it used?

A Text Field (Part 7 of 7) What layout is it used?

A Text Field (Part 1 of 7)

A Text Field (Part 1 of 7)

A Text Field (Part 2 of 7)

A Text Field (Part 2 of 7)

A Text Field (Part 3 of 7)

A Text Field (Part 3 of 7)

A Text Field (Part 4 of 7)

A Text Field (Part 4 of 7)

A Text Field (Part 5 of 7)

A Text Field (Part 5 of 7)

Text Areas • A text area is an object of the class JText. Area

Text Areas • A text area is an object of the class JText. Area – It is the same as a text field, except that it allows multiple lines – Two parameters to the JText. Area constructor specify the minimum number of lines, and the minimum number of characters per line that are guaranteed to be visible JText. Area the. Text = new JText. Area(5, 20); – Another constructor has one addition String parameter for the string initially displayed in the text area JText. Area the. Text = new JText. Area( "Enterntext here. " 5, 20);

Text Areas • The line-wrapping policy for a JText. Area can be set using

Text Areas • The line-wrapping policy for a JText. Area can be set using the method set. Line. Wrap – The method takes one boolean type argument – If the argument is true, then any additional characters at the end of a line will appear on the following line of the text area – If the argument is false, the extra characters will remain on the same line and not be visible the. Text. set. Line. Wrap(true);

Text Fields and Text Areas • A JText. Field or JText. Area can be

Text Fields and Text Areas • A JText. Field or JText. Area can be set so that it can not be changed by the user the. Text. set. Editable(false); – This will set the. Text so that it can only be edited by the GUI program, not the user – To reverse this, use true instead (this is the default) the. Text. set. Editable(true);

Tip: Labeling a Text Field • In order to label one or more text

Tip: Labeling a Text Field • In order to label one or more text fields: – Use an object of the class JLabel – Place the text field(s) and label(s) in a JPanel – Treat the JPanel as a single component

Numbers of Characters Per Line • The number of characters per line for a

Numbers of Characters Per Line • The number of characters per line for a JText. Field or JText. Area object is the number of em spaces • An em space is the space needed to hold one uppercase letter M – The letter M is the widest letter in the alphabet – A line specified to hold 20 M 's will almost always be able to hold more than 20 characters

Tip: Inputting and Outputting Numbers • When attempting to input numbers from any Swing

Tip: Inputting and Outputting Numbers • When attempting to input numbers from any Swing GUI, input text must be converted to numbers – If the user enters the number 42 in a JText. Field, the program receives the string "42" and must convert it to the integer 42 String input = name. get. Text(); int num = Integer. parse. Int(input); • The same thing is true when attempting to output a number – In order to output the number 42, it must first be converted to the string "42" Integer. to. String(num);

Scroll Bar • When a text area is created, the number of lines that

Scroll Bar • When a text area is created, the number of lines that are visible and the number of characters per line are specified as follows: JText. Area memo. Display = new JText. Area(15, 30); • However, it would often be better not to have to set a firm limit on the number of lines or the number of char -acters per line – This can be done by using scroll bars with the text area

Scroll Bar Scroll bars can be added to text areas using the JScroll. Pane

Scroll Bar Scroll bars can be added to text areas using the JScroll. Pane class –The JScroll. Pane class is in the javax. swing package –An object of the class JScroll. Pane is like a view port with scroll bars

View Port for a Text Area

View Port for a Text Area

Scroll Bar • When a JScroll. Pane is created, the text area to be

Scroll Bar • When a JScroll. Pane is created, the text area to be viewed is given as an argument JText. Area memo. Display = new JText. Area(15, 30); JScroll. Pane scrolled. Text= new JScroll. Pane(memo. Display); • The JScroll. Pane can then be added to a container, such as a JPanel or JFrame text. Panel. add(scrolled. Text);

Scroll Bar • The scroll bar policies can be set as follows: – scrolled.

Scroll Bar • The scroll bar policies can be set as follows: – scrolled. Text. set. Horizontal. Scroll. Bar. Poli cy(JScroll. Pane. HORIZONTAL_SCROLLBAR_ALW AYS); – scrolled. Text. set. Vertical. Scroll. Bar. Policy (Jscroll. Pane. VERTICAL_SCROLLBAR_ALWAYS); • If invocations of these methods are omitted, then the scroll bars will be visible only when needed – If all the text fits in the view port, then no scroll bars will be visible – If enough text is added, the scroll bars will appear automatically

A Text Area with Scroll Bar What layout is it used?

A Text Area with Scroll Bar What layout is it used?

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

A Text Area with Scroll Bar

ICONS

ICONS

Icons • JLabels, JButtons, and JMenu. Items can have icons – An icon is

Icons • JLabels, JButtons, and JMenu. Items can have icons – An icon is just a small picture (usually) – It is not required to be small • An icon is an object of the Image. Icon class – It is based on a digital picture file such as. gif, . jpg, or. tiff • Labels, buttons, and menu items may display a string, an icon, a string and an icon, or nothing

Icons • The class Image. Icon is used to convert a picture file to

Icons • The class Image. Icon is used to convert a picture file to a Swing icon Image. Icon duke. Icon = new Image. Icon("duke_waving. gif"); – The picture file must be in the same directory as the class in which this code appears, unless a complete or relative path name is given – Note that the name of the picture file is given as a string

Icons • An icon can be added to a label using the set. Icon

Icons • An icon can be added to a label using the set. Icon method as follows: JLabel duke. Label = new JLabel("Mood check"); duke. Label. set. Icon(duke. Icon); • Instead, an icon can be given as an argument to the JLabel constructor: JLabel duke. Label = new JLabel(duke. Icon); • Text can be added to the label as well using the set. Text method: duke. Label. set. Text("Mood check");

Icons • Icons and text may be added to JButtons and JMenu. Items in

Icons • Icons and text may be added to JButtons and JMenu. Items in the same way as they are added to a JLabel JButton happy. Button = new JButton("Happy"); Image. Icon happy. Icon = new Image. Icon("smiley. gif"); happy. Button. set. Icon(happy. Icon);

Icons • Button or menu items can be created with just an icon by

Icons • Button or menu items can be created with just an icon by giving the Image. Icon object as an argument to the JButton or JMenu. Item constructor Image. Icon happy. Icon = new Image. Icon("smiley. gif"); JButton smile. Button = new JButton(happy. Icon); JMenu. Item happy. Choice = new JMenu. Item(happy. Icon); – A button or menu item created without text should use the set. Action. Command method to explicitly set the action command, since there is no string

Using Icons What layout is it used?

Using Icons What layout is it used?

Using Icons (Part 1 of 5)

Using Icons (Part 1 of 5)

Using Icons (Part 2 of 5)

Using Icons (Part 2 of 5)

Using Icons (Part 3 of 5)

Using Icons (Part 3 of 5)

Using Icons (Part 4 of 5)

Using Icons (Part 4 of 5)

Using Icons (Part 5 of 5)

Using Icons (Part 5 of 5)

WINDOW LISTENERS

WINDOW LISTENERS

Window Listeners • Clicking the close-window button on a JFrame fires a window event

Window Listeners • Clicking the close-window button on a JFrame fires a window event – Window events are objects of the class Window. Event • The set. Window. Listener method can register a window listener for a window event – A window listener can be programmed to respond to this type of event – A window listener is any class that satisfies the Window. Listener interface

Window Listeners • A class that implements the Window. Listener interface must have definitions

Window Listeners • A class that implements the Window. Listener interface must have definitions for all seven method headers in this interface • Should a method not be needed, it is defined with an empty body public void window. Deiconified(Window. Event e) { }

Methods in the Window. Listener Interface (Part 1 of 2)

Methods in the Window. Listener Interface (Part 1 of 2)

Methods in the Window. Listener Interface (Part 2 of 2)

Methods in the Window. Listener Interface (Part 2 of 2)

A Window Listener Inner Class • An inner class often serves as a window

A Window Listener Inner Class • An inner class often serves as a window listener for a JFrame – The following example uses a window listener inner class named Check. On. Exit add. Window. Listener(new Check. On. Exit()); • When the close-window button of the main window is clicked, it fires a window event – This is received by the anonymous window listener object • This causes the window. Closing method to be invoked

A Window Listener Inner Class • The method window. Closing creates and displays a

A Window Listener Inner Class • The method window. Closing creates and displays a Confirm. Window class object – It contains the message "Are you sure you want to exit? " as well as "Yes" and "No" buttons • If the user clicks "Yes, " the action event fired is received by the action. Performed method – It ends the program with a call to System. exit • If the user clicks "No, " the action. Performed method invokes the dispose method – This makes the calling object go away (i. e. , the small window of the Confirm. Window class), but does not affect the main window

A Window Listener (Part 8 of 8)

A Window Listener (Part 8 of 8)

A Window Listener (Part 1 of 8)

A Window Listener (Part 1 of 8)

A Window Listener (Part 2 of 8)

A Window Listener (Part 2 of 8)

A Window Listener (Part 3 of 8)

A Window Listener (Part 3 of 8)

A Window Listener (Part 4 of 8)

A Window Listener (Part 4 of 8)

A Window Listener (Part 5 of 8)

A Window Listener (Part 5 of 8)

A Window Listener (Part 6 of 8)

A Window Listener (Part 6 of 8)

A Window Listener (Part 7 of 8)

A Window Listener (Part 7 of 8)

The dispose Method • The dispose()method of the JFrame class is used to eliminate

The dispose Method • The dispose()method of the JFrame class is used to eliminate the invoking JFrame without ending the program – The resources consumed by this JFrame and its components are returned for reuse – Unless all the elements are eliminated (i. e. , in a one window program), this does not end the program • dispose is often used in a program with multiple windows to eliminate one window without ending the program

GRAPHICS OBJECTS

GRAPHICS OBJECTS

Screen Coordinate System

Screen Coordinate System

The Method paint and the Class Graphics • Almost all Swing and Swing-related components

The Method paint and the Class Graphics • Almost all Swing and Swing-related components and containers have a method called paint(Graphics g) • The method paint draws the component or container on the screen – It is already defined, and is called automatically when the figure is displayed on the screen – However, it must be redefined in order to draw geometric figures like circles and boxes – When redefined, always include the following: super. paint(g);

The Method paint and the Class Graphics • Every container and component that can

The Method paint and the Class Graphics • Every container and component that can be drawn on the screen has an associated Graphics object – The Graphics class is an abstract class found in the java. awt package • This object has data specifying what area of the screen the component or container covers – The Graphics object for a JFrame specifies that drawing takes place inside the borders of the JFrame object

The Method paint and the Class Graphics • The object g of the class

The Method paint and the Class Graphics • The object g of the class Graphics can be used as the calling object for a drawing method – The drawing will then take place inside the area of the screen specified by g • The method paint has a parameter g of type Graphics – When the paint method is invoked, g is replaced by the Graphics object associated with the JFrame – Therefore, the figures are drawn inside the JFrame

Happy Face Example

Happy Face Example

Happy Face Example

Happy Face Example

Drawing inside JPanel • Many times, it is recommended to draw inside a panel

Drawing inside JPanel • Many times, it is recommended to draw inside a panel rather than the JFrame object. • In this case, the paint. Component(Graphics g) should be overridden.

Drawing and Mouse Click Example

Drawing and Mouse Click Example

Some useful methods • • • void set. Color(Color color) void set. Font(Font font)

Some useful methods • • • void set. Color(Color color) void set. Font(Font font) void draw. String(String text, int x, int y) void draw. Line(int x 1, int y 1, int x 2, int y 2) void draw. Rect(int x, int y, int width, int height) void draw. Round. Rect(int x, int y, int width, int height, int arc. Width, int arc. Height) void draw. Oval(int x, int y, int width, int height) void draw. Arc(int x, int y, int width, int height, int start. Angle, int angular. Extent) void fill. Rect(int x, int y, int width, int height) void fill. Round. Rect(int x, int y, int width, int height, int arc. Width, int arc. Height) void fill. Oval(int x, int y, int width, int height) void fill. Arc(int x, int y, int width, int height, int start. Angle, int angular. Extent)

Using Open. GL with Java! http: //jogamp. org/jogl/www/ http: //en. wikipedia. org/wiki/Java_Open. GL http:

Using Open. GL with Java! http: //jogamp. org/jogl/www/ http: //en. wikipedia. org/wiki/Java_Open. GL http: //jogamp. org/wiki/index. php/Jogl_Tutorial

What is Open. GL? • It is NOT a programming language. • It is

What is Open. GL? • It is NOT a programming language. • It is a Graphics Rendering API consisting of a set of functions with a well defined interface. • Whenever we say that a program is Open. GLbased or Open. GL applications, we mean that it is written in some programming language (such as C/C++ or Java) that makes calls to one or more of Open. GL libraries.

Open. GL & Alternative • Based on GL (graphics library) by Silicon Graphics Inc.

Open. GL & Alternative • Based on GL (graphics library) by Silicon Graphics Inc. (SGI) (www. opengl. org) Advantages: • Runs on everything, including smart phones (Open. GL/ES) Alternatives: • Microsoft’s Direct 3 D – limited to MS-Windows (http: //windows. microsoft. com/enus/windows 7/products/features/directx-11) • Sun’s Java 3 D – slower, implemented on top of Open. GL (http: //www. java 3 d. org/)

Useful Websites and Books • Official Site http: //www. opengl. org • Non official

Useful Websites and Books • Official Site http: //www. opengl. org • Non official sites http: //nehe. gamedev. net/ http: //google. com/ • BOOKS Open. GL Red Book (http: //www. glprogramming. com/red/) & Open. GL Blue Book (http: //www. glprogramming. com/blue/)

Library Layers APP GLUT • Open. GL = GL + GLU • GLUT opens

Library Layers APP GLUT • Open. GL = GL + GLU • GLUT opens and manages Open. GL windows and adds helper functions • Open. GL Extensions provide direct device-dependent access to hardware GLU GL OS Driver HW EXT – Basic low-level GL routines implemented using OS graphics routines – Time-saving higher-level GLU routines implemented using GL routines

Open. GL API Functions • Open. GL contains over 200 functions – Primitive functions:

Open. GL API Functions • Open. GL contains over 200 functions – Primitive functions: define the elements (e. g. points, lines, polygons, etc. ) – Attribute functions: control the appearance of primitives (e. g. colors, line types, light source, textures, etc. ) – Viewing functions: determine the properties of camera. Handle transformations. – Windowing functions: not part of core Open. GL (in GLUT) – Other functions

Graphics Pipeline of Open. GL Model Coords Model Xform Viewing Xform World Coords Homogeneous

Graphics Pipeline of Open. GL Model Coords Model Xform Viewing Xform World Coords Homogeneous Divide Still Clip Coords Window Coordinates Window to Viewport Viewing Coords Clipping Perspective Distortion Clip Coords Viewport Coordinates

Viewport Coordinates • Physical per-pixel integer coordinates • Also called screen or device coordinates

Viewport Coordinates • Physical per-pixel integer coordinates • Also called screen or device coordinates (0, VRES-1) (HRES-1, VRES-1) gl. Viewport(x, y, w, h) – x, y – lower left pixel (integers) – width – height • Sometimes (0, 0) is in the upper left corner (e. g. for mouse input) (0, 0) (HRES-1, 0)

Window Coordinates • Logical, mathematical floating-point coordinates (-1, 1) (1, 1) gl. Ortho(l, r,

Window Coordinates • Logical, mathematical floating-point coordinates (-1, 1) (1, 1) gl. Ortho(l, r, b, t, n, f) (for 3 D) – left, right, bottom, top – near, far: limits depth • For 2 D use • glu. Ortho 2 D(l, r, b, t) calls gl. Ortho(l, r, b, t, -1, 1) • To use per-pixel coordinates, call: glu. Ortho 2 D(-. 5, w-. 5, h-. 5); (-1, -1) (1, -1)

2 D Geometric Primitives • Primitives – fundamental entities such as point and polygons

2 D Geometric Primitives • Primitives – fundamental entities such as point and polygons • Basic types of geometric primitives – Points – Line segments – Polygons

2 D Geometric Primitives GL_POINTS GL_POLYGON GL_LINES GL_QUADS GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES GL_TRIANGLE_FAN All geometric

2 D Geometric Primitives GL_POINTS GL_POLYGON GL_LINES GL_QUADS GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES GL_TRIANGLE_FAN All geometric primitives are specified by vertices

Specifying Geometric Primitives gl. Begin( type ); gl. Vertex*(…); …… gl. Vertex*(…); gl. End();

Specifying Geometric Primitives gl. Begin( type ); gl. Vertex*(…); …… gl. Vertex*(…); gl. End(); type determines how vertices are combined

An Example void draw. Square (GLfloat *color) { gl. Color 3 fv( color );

An Example void draw. Square (GLfloat *color) { gl. Color 3 fv( color ); // sets the color of the square gl. Begin(GL_POLYGON); gl. Vertex 2 f ( 0. 0, 0. 0 ); gl. Vertex 2 f ( 1. 1, 1. 1 ); gl. Vertex 2 f ( 0. 0, 1. 0 ); gl. End(); gl. Flush(); // force the renderer to output the results }

Points (-1, 1) (1, 1) gl. Begin(GL_POINTS); gl. Vertex 2 f(-. 6, 1. );

Points (-1, 1) (1, 1) gl. Begin(GL_POINTS); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End(); (-1, -1) (1, -1)

Lines (-1, 1) (1, 1) gl. Begin(GL_LINES); gl. Vertex 2 f(-. 6, 1. );

Lines (-1, 1) (1, 1) gl. Begin(GL_LINES); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End(); (-1, -1) (1, -1)

Line Strip (-1, 1) (1, 1) gl. Begin(GL_LINE_STRIP); gl. Vertex 2 f(-. 6, 1.

Line Strip (-1, 1) (1, 1) gl. Begin(GL_LINE_STRIP); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End(); (-1, -1) (1, -1)

Line Loop (-1, 1) (1, 1) gl. Begin(GL_LINE_LOOP); gl. Vertex 2 f(-. 6, 1.

Line Loop (-1, 1) (1, 1) gl. Begin(GL_LINE_LOOP); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End(); (-1, -1) (1, -1)

Polygon (-1, 1) Open. GL only supports convex polygons (and really only triangles) (1,

Polygon (-1, 1) Open. GL only supports convex polygons (and really only triangles) (1, 1) gl. Begin(GL_POLYGON); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End(); (-1, -1) (1, -1)

Quads (-1, 1) (1, 1) gl. Begin(GL_QUADS); gl. Vertex 2 f(-. 6, 1. );

Quads (-1, 1) (1, 1) gl. Begin(GL_QUADS); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End(); (-1, -1) (1, -1)

Quads gl. Begin(GL_QUADS); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-.

Quads gl. Begin(GL_QUADS); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End();

Quads (-1, 1) (1, 1) gl. Begin(GL_QUADS); gl. Vertex 2 f(-. 6, 1. );

Quads (-1, 1) (1, 1) gl. Begin(GL_QUADS); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(. 6, 1. ); gl. Vertex 2 f(-. 6, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(. 2, . 6); gl. End(); (-1, -1) (1, -1)

Triangles (-1, 1) (1, 1) gl. Begin(GL_TRIANGLES); gl. Vertex 2 f(-. 6, 1. );

Triangles (-1, 1) (1, 1) gl. Begin(GL_TRIANGLES); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End(); (-1, -1) (1, -1)

Triangles (-1, 1) (1, 1) gl. Begin(GL_TRIANGLES); gl. Vertex 2 f(-. 6, 1. );

Triangles (-1, 1) (1, 1) gl. Begin(GL_TRIANGLES); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, . 6); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); … gl. End(); (-1, -1) (1, -1)

Triangle Strip (-1, 1) (1, 1) gl. Begin(GL_TRIANGLE_STRIP); gl. Vertex 2 f(-. 6, 1.

Triangle Strip (-1, 1) (1, 1) gl. Begin(GL_TRIANGLE_STRIP); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 6, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(-. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 6, 1. ); gl. End(); (-1, -1) (1, -1)

Triangle Strip (-1, 1) First two vertices prime the pump, then every new vertex

Triangle Strip (-1, 1) First two vertices prime the pump, then every new vertex creates a triangle connecting it to the previous two vertices (1, 1) gl. Begin(GL_TRIANGLE_STRIP); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(-. 2, . 6); gl. Vertex 2 f(-. 2, -. 6); gl. Vertex 2 f(. 6, -1. ); gl. Vertex 2 f(. 6, -. 6); gl. End(); … (-1, -1) (1, -1)

Triangle Fan (-1, 1) First two vertices prime the pump, then every new vertex

Triangle Fan (-1, 1) First two vertices prime the pump, then every new vertex creates a triangle connecting it to the previous vertex and the first vertex (1, 1) gl. Begin(GL_TRIANGLE_FAN); gl. Vertex 2 f(-. 2, . 6); gl. Vertex 2 f(-. 6, 1. ); gl. Vertex 2 f(. 2, . 6); gl. Vertex 2 f(. 2, -. 6); gl. Vertex 2 f(-. 2, -. 6); gl. End(); … (-1, -1) (1, -1)

Assigning Color gl. Color 3 f(0, 0, 1); gl. Begin(GL_POLYGON); gl. Vertex 2 f(-1,

Assigning Color gl. Color 3 f(0, 0, 1); gl. Begin(GL_POLYGON); gl. Vertex 2 f(-1, 1); gl. Vertex 2 f(-1, -1); gl. Vertex 2 f(1, -1); gl. End(); gl. Begin(GL_POLYGON); gl. Color 3 f(0, 1, 0); gl. Vertex 2 f(-1, 1); gl. Color 3 f(0, 0, 1); gl. Vertex 2 f(-1, -1); gl. Color 3 f(1, 0, 0); gl. Vertex 2 f(1, -1); gl. End(); gl. Color 3 f(1, 0, 0); gl. Begin(GL_POLYGON); gl. Vertex 2 f(-1, 1); gl. Vertex 2 f(-1, -1); gl. Vertex 2 f(1, -1); gl. End(); gl. Color 3 f(0, 0, 0); gl. Begin(GL_LINE_LOOP); gl. Vertex 2 f(-1, 1); gl. Vertex 2 f(-1, -1); gl. Vertex 2 f(1, -1); gl. End();

Other Graphics Functionality in Open. GL - Viewport projection and transformation glu. Perspective( fovy,

Other Graphics Functionality in Open. GL - Viewport projection and transformation glu. Perspective( fovy, aspect, z. Near, z. Far ) glu. Look. At (eyex, eyey, eyez, atx, aty, atz, upx, upy, upz ) gl. Frustum( left, right, bottom, top, z. Near, z. Far ) - Model transformation gl. Translate {fd} (TYPE x, TYPE y, TYPE z) gl. Scale {fd} (TYPE x, TYPE y, TYPE z) gl. Rotate {fd} (TYPE angle, TYPE x, TYPE y, TYPE z) - Texturing - Lighting