Presentation is loading. Please wait.

Presentation is loading. Please wait.

OpenGL Course Notes Chapter 1: Introduction Jim Mims.

Similar presentations


Presentation on theme: "OpenGL Course Notes Chapter 1: Introduction Jim Mims."— Presentation transcript:

1 OpenGL Course Notes Chapter 1: Introduction Jim Mims

2 Table of Contents Origin and Purpose C++ Essentials Some Definitions Required Software Include Files Managing Windows: Windows Procedures Vs GLUT Functions GLUT Windows Management Functions Handling Input Events Some Built-In 3D Objects Example Code

3 OpenGL: Origin and Purpose The OpenGL API (Application Programming Interface) began as an initiative by Silicon Graphics to create a single, vendor-independent API for the development of 2D and 3D graphics applications. Prior to the introduction of OpenGL, many hardware vendors had different graphics libraries. This situation made it expensive for software developers to support versions of their applications on multiple hardware platforms, and it made porting of applications from one hardware platform to another very time-consuming and difficult. Silicon Graphics saw the lack of a standard graphics API as an inhibitor to the growth of the 3D marketplace and decided to lead an industry group in creating such a standard.

4 OpenGL: Origin and Purpose The result of this work was the OpenGL API library. The OpenGL API began as a specification, then a sample implementation was produced that hardware vendors could use to develop OpenGL drivers for their hardware. The sample implementation has been released under an open source license. Modifications to the OpenGL API are made through the OpenGL Architecture Review Board, an industry group that contains founding, permanent, and auxiliary members.

5 OpenGL: Origin and Purpose The OpenGL specification is overseen by the OpenGL Architecture Review Board (ARB). The OpenGL Architecture Review Board (ARB) is an industry consortium that currently governs the OpenGL specification. It was formed in 1992, and defines the conformance tests, approves the OpenGL specification and advances the standard. In July 2006, it was announced that the ARB voted to transfer control of the OpenGL specification to the Khronos Group.

6 OpenGL: Origin and Purpose The Khronos Group is a member-funded industry consortium focused on the creation of open standard, royalty-free APIs to enable the authoring and accelerated playback of dynamic media on a wide variety of platforms and devices. All Khronos members are able to contribute to the development of Khronos API specifications, are empowered to vote at various stages before public deployment, and are able to accelerate the delivery of their cutting-edge 3D platforms and applications through early access to specification drafts and conformance tests.

7 C++ Essentials Functions Groupings of code that accomplish a task. Enclosed in braces {} Main Function All programs must have one Enclosed in braces Last line is return 0; Semicolons Used to terminate a line of code Importing Libraries #include if in standard C++ library #include name of library if not in standard C++ library

8 C++ Essentials Some Data Types int, float, double, char, string Some Operators >, <, =, ==, != Loops For (int i = 0; i<10;i++) { //code goes here } Calling a Function Use the name of the function VB 6: ByRef or ByVal Comments // or /*……*/

9 Some Definitions Geometric Primitives Points, lines, and polygons Models Objects constructed from geometric primitives Rendering Process by which computer generates images (things on the screen) from models Bit A 0 or a 1 Bitplane Area in memory that holds one bit of information for every pixel on the screen (how green, for example) Framebuffer Contains the bitplanes – all the graphics information the graphics display needs to control the color and intensity of all the pixels on the screen

10 Some Definitions Rendering Pipeline Series of processing stages – summarized next Rendering Pipeline: Display Lists Data structure for storing all data (geometric primitives or pixels) for subsequent use. The alternative is to process the data immediately (immediate mode) Rendering Pipeline: Evaluators All geometric primitives described by vertices. Surfaces and curves described by control points and basis functions. Evaluators derive vertices from the surface and curve representations. Rendering Pipeline: Primitive Assembly Includes cleanup operations such things as clipping. Rendering Pipeline: Pixel Operations Operations on pixels – geometric data takes a different route.

11 Some Definitions Rendering Pipeline: Texture Assembly Applying textures onto geometric objects to make them look more realistic. Rendering Pipeline: Rasterization The conversion of both geometric and pixel data into fragments. Each fragment square corresponds to a pixel in the framebuffer. Color and depth values are assigned for each square. Rendering Pipeline: Fragment Operations Series of operations that are performed before the values are stored in the framebuffer. Fragments may be altered or removed.

12 Required Software The location of the following software is system dependent. For Windows, the following files should be in a directory similar to the following: Program Files\Microsoft Visual Studio\VC\include\gl gl.h Primary OpenGL header file. Contains prototypes for various functions glu.h Header file for the OPenGL Utility library glut.h Header file for OpenGL Graphic Library Utility Toolkit - used to manage Windows. Ensures that gl.h and glu.h are included automatically - including them with separate code is redundant.

13 Required Software For Windows, the following files should be in a directory similar to the following: Program Files\Microsoft Visual Studio\VC\lib Opengl32.lib Library containing bindings to OpenGL functions. glu32.lib Library containing bindings to OpenGL Utility Library functions Glut32.lib Library contining bindings to GLUT Library functions

14 Required Software For Windows, the following files should be in a directory similar to the following: Windows\System32 opengl32.dll Dynamic link library containing OpenGL function implementations and hooks into video hardware drivers. glu32.dll Dynamic link library containing OpenGL Utility Library function implementations.

15 Include Files #include #include is a C++ preprocessor directive. It tells the compiler to insert the file included in The <> indicates that the files are in the standard library directory for C++ The GL is a sub directory in the include directory – created when you install Windows.

16 Managing Windows: Windows Vs GLUT Functions There are 2 options: using Windows procedures (not intuitive) or using GLUT functions. This course emphasizes the latter. To use Windows procedures you open C++ and select File, New, Win32 Application. You must #include GLUT stands for OpenGL Utility Toolkit – it is used to perform windows activities – controlling the window. To use GLUT functions, you open C++ and select File, New, Win32 Console Application. You must #include. Glut.h ensure that both gl.h and glu.h are included.

17 Windows Management Functions glutInit() Initializes GLUT – should be called before any other GLUT function. glutInitDisplayMode(int mode) Specifies whether to use an RGBA or color-index color model and to set some other items. glutInitWindowPosition(int x, int y) Specifies the screen location for the upper-left corner of the window. glutWindowSize(int width, int size) Specifies the size, in pixels, of the window. glutCreateWindow() Creates a window glutMainLoop() Displays the window

18 Handling Input Events glutReshapeFunc(int w, int h) Indicates what action should be taken when the window is resized. glutKeyboardFunc(char key, int x, int y) glutMouseFunc(int button, int state, int x, int y) Allow you to link a keyboard key or a mouse button with a routine that is invokes when the key or mouse button is pressed or released glutMotionFunc(int x, int y) Regisers a routine call back when the mouse is moved while a mouse button is also pressed.

19 Some Built-In 3D Objects glutSolidSphere(double radius, int slices, int stacks) glutWireSphere(double radius, int slices, int stacks) Renders a sphere centered at the modeling coordinates origin of the specified radius. The sphere is subdivided around the Z axis into slices and along the Z axis into stacks. radius is the radius of the sphere slices is the number of subdivisions around the Z axis stacks is the number of subdivisions along the Z axis glutSolidCube (double size) glutWireCube(double size) Render a solid or wireframe. The cube is centered at the modeling coordinates origin with sides of length size.

20 Some Built-In 3D Objects glutSolidCone(base, height, slices, stacks) glutWireCone(base, height, slices, stacks) Render a solid or wireframe cone respectively oriented along the z axis. The base of the cone is placed at z=0, and the top at z=height. The cone is subdivided around the z axis into slices, and along the z axis into stacks. base is the radius of the base of the cone height is the height of the cone slices is the number of subdivisions around the Z axis stacks is the number of subdivisions along the Z axis

21 Some Built-In 3D Objects glutSolidTorus(double innerRadius, double outerRadius, int nsides, int rings) glutWireTorus (double innerRadius, double outerRadius, int nsides, int rings) Render a solid or wireframe torus (doughnut) respectively centered at the modeling coordinates origin whose axis is aligned with the Z axis. innerRadius is the inner radius of the torous outerRadius is the outer radius of the torus nsides is teh number of sides for each radial section rings is the number of radial divisions for the torus

22 Some Built-In 3D Objects glutSolidTeapot(double size) glutWireTEapot(double size) Render a solid or wireframe teapot respectively. Both surface normals and texture coordinates for the teapot are generated. Size is the relative size of the teapot glutSolidTetrahedron() glutWireTetrahedron() Render a solid or wireframe tetrahedron respectively centered at the modeling coordinates origin with a radius square root of 3.

23 Many Teapots

24 Clipped Wireframe Sphere

25 Example Code #include void display(void) { //clear all pixels glClear (GL_COLOR_BUFFER_BIT); //draw white polygon (rectangle) with indicated corners 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();

26 Example Code //start processing buffered OpenGL routines glFlush (); } void init (void) { //Select clearing 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); }

27 Example Code /************************************************************************************** Declare initial window size, position, and display mode (single buffer, 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; }

28 Example Code: Output


Download ppt "OpenGL Course Notes Chapter 1: Introduction Jim Mims."

Similar presentations


Ads by Google