SlideShare a Scribd company logo
SER332
Introduction to Graphics and
Game Development
Lecture 03:
OpenGL Overview
Javier Gonzalez-Sanchez
javiergs@asu.edu
PERALTA 230U
Office Hours: By appointment
Microsoft Visual Studio 2017
Windows 10
Install and Configure
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 3
Run the installation file
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 4
Select Desktop Development with C++
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 5
Install
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 6
Restart
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 7
Sign up (optional)
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 8
Settings: Visual C++ (optional)
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 9
Start Page
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 10
Create a new project
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 11
Select Windows Console Application
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 12
Name your Project
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 13
Add the code below to test your project
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 14
Remove Precompiled Headers
1. Right click in the project name and select “Properties”.
2. Select “Not Using Precompiled Headers”
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 15
Build (compile)
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 16
Build succeeded
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 17
Run it
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 18
A console will open
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 19
Download the OpenGL libraries
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 20
Copy DLL file to Windows/System32
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 21
Copy lib and include folders to VC folder
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 22
Update VC++ Directories | Include
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 23
Update VC++ Directories | lib
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 24
Test OpenGL | Copy code from slides 48
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 25
Test OpenGL
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 26
If you get a glut32.dll error,
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 27
… copy the dll file to the project folder
Xcode 9.20
macOS High Sierra
Install and Configure
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 29
Verification
§ OpenGL and GLUT come with the OS and Xcode
installations.
§ To verify, check for:
/System/Library/Frameworks/GLUT.framework
/System/Library/Frameworks/OpenGL.framework
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 30
Create a new Project in Xcode
§ Select "File→New→New Project".
§ Choose a template for your new project under Mac OS X (not
iOS):"Application→Command Line Tool" and click "Next"
§ For the sample code, specify "Product Name" as "sampleapp",
"Company Identifier" as "sample", select "Type" "C++", and click
"Next”.
§ A window pops up to prompt you where you want to put the
new project folder.
§ Uncheck "Create local git repository for this project” Then click
"Create”.
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 31
Add Libraries
§ In the middle pane, click the "Build Phases" tab, open the "Link
Binary With Libraries" list, and click the '+' sign at the bottom left
corner of the list.
§ A list of frameworks should pop up. Scroll down the list to
"OpenGL.framework" and click "Add". Repeat for
"GLUT.framework".
§ To suppress "Deprecations" warnings for GLUT, in the middle
pane, click the "Build Settings" tab. On the second menu of
the panel, click on "All". Scroll down (or search for) "Apple
LLVM 5.1 - Custom Compiler Flags". Click to the right of "Other
C Flags" and type in "-Wno-deprecated".
Eclipse Oxygen 2 (release 4.7.2)
macOS High Sierra
Install and Configure
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 33
Install
• Download Eclipse IDE for C/C++ Developers
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 34
Configure
§ Create File àNew à Project…
§ Choose C/C++ àC Project
§ Give a name to the project
§ Select Project type àHello World ANSI C ProjectàMacOSX
GCC
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 35
Configure
§ In order to set-up them in Eclipse, open the project properties
and go in: “C/C++ Build->Settings->MacOSX C++ Linker-
>Miscellaneous” and write this in the Linker flags text box:
-framework GLUT -framework openGL -framework Cocoa
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 36
Configure
§ Add gl.h and glut.h in the directory
§ Go to project propertiesà C/C++ general àPath and Symbols à
Include(tab)à GNU C add 2 include directories
/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers
/System/Library/Frameworks/GLUT.framework/Versions/A/Headers
Part 1
Introduction to OpenGL
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 38
OpenGL
§ OpenGL basic library – most commands
§ OpenGL Utility (GLU) – some high level commands
e.g. generating complex objects, cylinder, sphere
§ OpenGL Utility Toolkit (GLUT)
windowing commands
38
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 39
What Is OpenGL?
§ Software interface to graphics hardware
§ Competitors: DirectX, Java2D and Java3D,…
§ Communicate between CPU and GPU via drivers
§ A client and server execution model
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 40
OpenGL Rendering Pipeline
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 41
OpenGL as a State Machine
§ Maintain pipeline states: current color, viewing and
projection transformation, polygon drawing modes,
etc.
§ Hierarchical state maintenance
glPushAttrib(), glPushMatrix(), glPopAttrib(), glPopMatrix(), …
glColor3f(1.0f, 0.0f, 0.0f); // <- alter current state
// Draw a cube
//What color is the cube?
glColor3f(0.0, 1.0f, 0.0f); // <- alter current state
// Draw a sphere.
// What color is the sphere?
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 42
OpenGL Libraries
OpenGL core library (GL)
§ #include <GL/gl.h>
§ OpenGL32 on Windows
§ GL on most UNIX / LINUX systems (libGL.a)
OpenGL Utility Library (GLU)
§ #include <GL/glu.h>
§ Provides functionality in OpenGL core but avoids having to rewrite
code
OpenGL Utility Toolkit (GLUT)
§ #include <GL/glut.h>
§ Provides functionality common to all window systems
o Open a window
o Get input from mouse and keyboard
o Menus
o Event-driven
§ Code is portable but GLUT lacks the functionality of a good toolkit for
a specific platform
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 43
OpenGL and Related APIs
GLUT
GLU
GL
GLX, AGL
or WGL
X, Win32, Mac O/S
software and/or hardware
application program
OpenGL Motif
widget or similar
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 44
OpenGL Syntax
§ functions have prefix gl and initial capital letters for each word
glClearColor(), glEnable(), glPushMatrix() …
§ glu for GLU functions
gluLookAt(), gluPerspective() …
§ constants begin with GL_, use all capital letters
GL_COLOR_BUFFER_BIT,
GL_PROJECTION,
GL_MODELVIEW …
§ Extra letters in some commands indicate the number and
type of variables
glColor3f(), glVertex3f() …
§ OpenGL data types
GLfloat, GLdouble, GLint, GLenum, …
Part 2
GLUT: OpenGL Utility Toolkit
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 46
GLUT: OpenGL Utility Toolkit
§ A simplified window system toolkit
o Create windows
o Initialize display context
o Handle basic application events: screen refreshing, timer, resize…
o Handle user inputs
§ A higher level geometric toolkit
o glutSolidSphere, glutSolidCube,…
§ Application Structure
o Configure and open window
o Initialize OpenGL state
o Register input callback functions
• render
• resize
• input: keyboard, mouse, etc.
o Enter event processing loop
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 47
Installation (Windows)
§ glut.h – in your include path
gl.h and glu.h are included by glut.h
§ glut32.lib in your library path
§ glut32.dll in “windowssystem” path
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 48
GLUT Window Management
§ glutInit (&argc, argv); //Glut initialization
§ glutCreateWindow ("Example"); //Create a window
§ glutDisplayFunc (myDisplay) //callback function
§ glutMainLoop() // activate the display window
§ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | …)
// set initial options
§ glutInitWindowPosition (x, y); // integer
§ glutInitWindowSize (width, height ); // integer
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 49
Example 1
/**
* https://github.com/javiergs/SER332/blob/master/Lecture03/main.c
*/
#if defined(__APPLE__)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
// main
void main(int argc, char** argv){
glutInit(&argc, argv); // glut init
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500); // actual window size
glutInitWindowPosition(0,0); // window location
glutCreateWindow("simple");
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop(); //event loop
}
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 50
// myInit
void myInit() {
glClearColor(0.764f, 0.129f, 0.282f, 1.0); // maroon
glColor3f(1.0f, 0.843f, 0.0f); // gold
// projection transformations
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, -1.0, 1.0); // units inside
}
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 51
// myDisplay
void myDisplay() {
glClear(GL_COLOR_BUFFER_BIT); // clear the window
glBegin(GL_POLYGON); // fill connected polygon
glVertex2f(-0.7, 0.7); // vertices of the square
glVertex2f( 0.6, 0.7);
glVertex2f(-0.7, -0.6);
glEnd();
glBegin(GL_POLYGON); // fill connected polygon
glVertex2f( 0.7, 0.6); // vertices of the square
glVertex2f(-0.6, -0.7);
glVertex2f( 0.7, -0.7);
glEnd();
glFlush(); //forces issued commands to execute
}
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 52
Example 1
500
500
(0.7,0.7)
(-0.7,-0.7)
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 53
Double Buffering
§ Double buffering is necessary for almost all OpenGL applications:
§ Render into back buffer
§ Swap buffers when finished rendering a frame: The old back
buffer becomes the front buffer that is displayed. The old front
buffer becomes the back buffer that is rendered into.
§ What happens when you do not use double buffering?
§ flickering artifacts, tearing artifacts
§ Commands:
§ glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
§ glutSwapBuffers(); //instead of glFlush()
Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 54
Homework
Start Programming!
SER332 Introduction to Graphics
Javier Gonzalez-Sanchez
javiergs@asu.edu
Spring 2018
Disclaimer. These slides can only be used as study material for the class SER332 at ASU. They cannot be distributed or used for another purpose.

More Related Content

Similar to 201801 SER332 Lecture 03

Mesa and Its Debugging, Вадим Шовкопляс
Mesa and Its Debugging, Вадим ШовкоплясMesa and Its Debugging, Вадим Шовкопляс
Mesa and Its Debugging, Вадим Шовкопляс
Sigma Software
 
openGl configuration_in visual studio 2019.pptx
openGl configuration_in visual studio 2019.pptxopenGl configuration_in visual studio 2019.pptx
openGl configuration_in visual studio 2019.pptx
MuhammadUmer787617
 
Kubernetes Deployments: A "Hands-off" Approach
Kubernetes Deployments: A "Hands-off" ApproachKubernetes Deployments: A "Hands-off" Approach
Kubernetes Deployments: A "Hands-off" Approach
Rodrigo Reis
 
201707 SER332 Lecture 06
201707 SER332 Lecture 06 201707 SER332 Lecture 06
201707 SER332 Lecture 06
Javier Gonzalez-Sanchez
 
Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
AnandM62785
 
IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)
IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)
IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)
Alexandre Gouaillard
 
Git as version control for Analytics project
Git as version control for Analytics projectGit as version control for Analytics project
Git as version control for Analytics project
Nag Arvind Gudiseva
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and Future
Igalia
 
Gitops Hands On
Gitops Hands OnGitops Hands On
Gitops Hands On
Brice Fernandes
 
Coding GRIN GLOBAL Wizards
Coding GRIN GLOBAL WizardsCoding GRIN GLOBAL Wizards
Coding GRIN GLOBAL Wizards
Edwin Rojas
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Fabian Jakobs
 
generate IP CORES
generate IP CORESgenerate IP CORES
generate IP CORES
guest296013
 
Grails beginners workshop
Grails beginners workshopGrails beginners workshop
Grails beginners workshop
JacobAae
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.Girish Ghate
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature plugins
GR8Conf
 
BCON22: oneAPI backend - Blender Cycles on Intel GPUs
BCON22: oneAPI backend - Blender Cycles on Intel GPUsBCON22: oneAPI backend - Blender Cycles on Intel GPUs
BCON22: oneAPI backend - Blender Cycles on Intel GPUs
Xavier Hallade
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
Syed Zaid Irshad
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
Javier Gonzalez-Sanchez
 
CIP Developing Curator Tool Wizards
CIP Developing Curator Tool WizardsCIP Developing Curator Tool Wizards
CIP Developing Curator Tool Wizards
Edwin Rojas
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentDavid Galeano
 

Similar to 201801 SER332 Lecture 03 (20)

Mesa and Its Debugging, Вадим Шовкопляс
Mesa and Its Debugging, Вадим ШовкоплясMesa and Its Debugging, Вадим Шовкопляс
Mesa and Its Debugging, Вадим Шовкопляс
 
openGl configuration_in visual studio 2019.pptx
openGl configuration_in visual studio 2019.pptxopenGl configuration_in visual studio 2019.pptx
openGl configuration_in visual studio 2019.pptx
 
Kubernetes Deployments: A "Hands-off" Approach
Kubernetes Deployments: A "Hands-off" ApproachKubernetes Deployments: A "Hands-off" Approach
Kubernetes Deployments: A "Hands-off" Approach
 
201707 SER332 Lecture 06
201707 SER332 Lecture 06 201707 SER332 Lecture 06
201707 SER332 Lecture 06
 
Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
 
IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)
IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)
IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)
 
Git as version control for Analytics project
Git as version control for Analytics projectGit as version control for Analytics project
Git as version control for Analytics project
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and Future
 
Gitops Hands On
Gitops Hands OnGitops Hands On
Gitops Hands On
 
Coding GRIN GLOBAL Wizards
Coding GRIN GLOBAL WizardsCoding GRIN GLOBAL Wizards
Coding GRIN GLOBAL Wizards
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
 
generate IP CORES
generate IP CORESgenerate IP CORES
generate IP CORES
 
Grails beginners workshop
Grails beginners workshopGrails beginners workshop
Grails beginners workshop
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature plugins
 
BCON22: oneAPI backend - Blender Cycles on Intel GPUs
BCON22: oneAPI backend - Blender Cycles on Intel GPUsBCON22: oneAPI backend - Blender Cycles on Intel GPUs
BCON22: oneAPI backend - Blender Cycles on Intel GPUs
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
CIP Developing Curator Tool Wizards
CIP Developing Curator Tool WizardsCIP Developing Curator Tool Wizards
CIP Developing Curator Tool Wizards
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
 

More from Javier Gonzalez-Sanchez

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
Javier Gonzalez-Sanchez
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 09
201801 CSE240 Lecture 09201801 CSE240 Lecture 09
201801 CSE240 Lecture 09
Javier Gonzalez-Sanchez
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 
201801 CSE240 Lecture 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
 
201801 CSE240 Lecture 09
201801 CSE240 Lecture 09201801 CSE240 Lecture 09
201801 CSE240 Lecture 09
 

Recently uploaded

"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 

Recently uploaded (20)

"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 

201801 SER332 Lecture 03

  • 1. SER332 Introduction to Graphics and Game Development Lecture 03: OpenGL Overview Javier Gonzalez-Sanchez javiergs@asu.edu PERALTA 230U Office Hours: By appointment
  • 2. Microsoft Visual Studio 2017 Windows 10 Install and Configure
  • 3. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 3 Run the installation file
  • 4. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 4 Select Desktop Development with C++
  • 5. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 5 Install
  • 6. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 6 Restart
  • 7. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 7 Sign up (optional)
  • 8. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 8 Settings: Visual C++ (optional)
  • 9. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 9 Start Page
  • 10. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 10 Create a new project
  • 11. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 11 Select Windows Console Application
  • 12. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 12 Name your Project
  • 13. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 13 Add the code below to test your project
  • 14. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 14 Remove Precompiled Headers 1. Right click in the project name and select “Properties”. 2. Select “Not Using Precompiled Headers”
  • 15. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 15 Build (compile)
  • 16. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 16 Build succeeded
  • 17. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 17 Run it
  • 18. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 18 A console will open
  • 19. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 19 Download the OpenGL libraries
  • 20. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 20 Copy DLL file to Windows/System32
  • 21. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 21 Copy lib and include folders to VC folder
  • 22. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 22 Update VC++ Directories | Include
  • 23. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 23 Update VC++ Directories | lib
  • 24. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 24 Test OpenGL | Copy code from slides 48
  • 25. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 25 Test OpenGL
  • 26. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 26 If you get a glut32.dll error,
  • 27. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 27 … copy the dll file to the project folder
  • 28. Xcode 9.20 macOS High Sierra Install and Configure
  • 29. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 29 Verification § OpenGL and GLUT come with the OS and Xcode installations. § To verify, check for: /System/Library/Frameworks/GLUT.framework /System/Library/Frameworks/OpenGL.framework
  • 30. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 30 Create a new Project in Xcode § Select "File→New→New Project". § Choose a template for your new project under Mac OS X (not iOS):"Application→Command Line Tool" and click "Next" § For the sample code, specify "Product Name" as "sampleapp", "Company Identifier" as "sample", select "Type" "C++", and click "Next”. § A window pops up to prompt you where you want to put the new project folder. § Uncheck "Create local git repository for this project” Then click "Create”.
  • 31. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 31 Add Libraries § In the middle pane, click the "Build Phases" tab, open the "Link Binary With Libraries" list, and click the '+' sign at the bottom left corner of the list. § A list of frameworks should pop up. Scroll down the list to "OpenGL.framework" and click "Add". Repeat for "GLUT.framework". § To suppress "Deprecations" warnings for GLUT, in the middle pane, click the "Build Settings" tab. On the second menu of the panel, click on "All". Scroll down (or search for) "Apple LLVM 5.1 - Custom Compiler Flags". Click to the right of "Other C Flags" and type in "-Wno-deprecated".
  • 32. Eclipse Oxygen 2 (release 4.7.2) macOS High Sierra Install and Configure
  • 33. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 33 Install • Download Eclipse IDE for C/C++ Developers
  • 34. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 34 Configure § Create File àNew à Project… § Choose C/C++ àC Project § Give a name to the project § Select Project type àHello World ANSI C ProjectàMacOSX GCC
  • 35. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 35 Configure § In order to set-up them in Eclipse, open the project properties and go in: “C/C++ Build->Settings->MacOSX C++ Linker- >Miscellaneous” and write this in the Linker flags text box: -framework GLUT -framework openGL -framework Cocoa
  • 36. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 36 Configure § Add gl.h and glut.h in the directory § Go to project propertiesà C/C++ general àPath and Symbols à Include(tab)à GNU C add 2 include directories /System/Library/Frameworks/OpenGL.framework/Versions/A/Headers /System/Library/Frameworks/GLUT.framework/Versions/A/Headers
  • 38. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 38 OpenGL § OpenGL basic library – most commands § OpenGL Utility (GLU) – some high level commands e.g. generating complex objects, cylinder, sphere § OpenGL Utility Toolkit (GLUT) windowing commands 38
  • 39. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 39 What Is OpenGL? § Software interface to graphics hardware § Competitors: DirectX, Java2D and Java3D,… § Communicate between CPU and GPU via drivers § A client and server execution model
  • 40. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 40 OpenGL Rendering Pipeline
  • 41. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 41 OpenGL as a State Machine § Maintain pipeline states: current color, viewing and projection transformation, polygon drawing modes, etc. § Hierarchical state maintenance glPushAttrib(), glPushMatrix(), glPopAttrib(), glPopMatrix(), … glColor3f(1.0f, 0.0f, 0.0f); // <- alter current state // Draw a cube //What color is the cube? glColor3f(0.0, 1.0f, 0.0f); // <- alter current state // Draw a sphere. // What color is the sphere?
  • 42. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 42 OpenGL Libraries OpenGL core library (GL) § #include <GL/gl.h> § OpenGL32 on Windows § GL on most UNIX / LINUX systems (libGL.a) OpenGL Utility Library (GLU) § #include <GL/glu.h> § Provides functionality in OpenGL core but avoids having to rewrite code OpenGL Utility Toolkit (GLUT) § #include <GL/glut.h> § Provides functionality common to all window systems o Open a window o Get input from mouse and keyboard o Menus o Event-driven § Code is portable but GLUT lacks the functionality of a good toolkit for a specific platform
  • 43. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 43 OpenGL and Related APIs GLUT GLU GL GLX, AGL or WGL X, Win32, Mac O/S software and/or hardware application program OpenGL Motif widget or similar
  • 44. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 44 OpenGL Syntax § functions have prefix gl and initial capital letters for each word glClearColor(), glEnable(), glPushMatrix() … § glu for GLU functions gluLookAt(), gluPerspective() … § constants begin with GL_, use all capital letters GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW … § Extra letters in some commands indicate the number and type of variables glColor3f(), glVertex3f() … § OpenGL data types GLfloat, GLdouble, GLint, GLenum, …
  • 45. Part 2 GLUT: OpenGL Utility Toolkit
  • 46. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 46 GLUT: OpenGL Utility Toolkit § A simplified window system toolkit o Create windows o Initialize display context o Handle basic application events: screen refreshing, timer, resize… o Handle user inputs § A higher level geometric toolkit o glutSolidSphere, glutSolidCube,… § Application Structure o Configure and open window o Initialize OpenGL state o Register input callback functions • render • resize • input: keyboard, mouse, etc. o Enter event processing loop
  • 47. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 47 Installation (Windows) § glut.h – in your include path gl.h and glu.h are included by glut.h § glut32.lib in your library path § glut32.dll in “windowssystem” path
  • 48. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 48 GLUT Window Management § glutInit (&argc, argv); //Glut initialization § glutCreateWindow ("Example"); //Create a window § glutDisplayFunc (myDisplay) //callback function § glutMainLoop() // activate the display window § glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | …) // set initial options § glutInitWindowPosition (x, y); // integer § glutInitWindowSize (width, height ); // integer
  • 49. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 49 Example 1 /** * https://github.com/javiergs/SER332/blob/master/Lecture03/main.c */ #if defined(__APPLE__) #include <GLUT/glut.h> #else #include <GL/glut.h> #endif // main void main(int argc, char** argv){ glutInit(&argc, argv); // glut init glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); // actual window size glutInitWindowPosition(0,0); // window location glutCreateWindow("simple"); myInit(); glutDisplayFunc(myDisplay); glutMainLoop(); //event loop }
  • 50. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 50 // myInit void myInit() { glClearColor(0.764f, 0.129f, 0.282f, 1.0); // maroon glColor3f(1.0f, 0.843f, 0.0f); // gold // projection transformations glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0, 1.0, -1.0, 1.0); // units inside }
  • 51. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 51 // myDisplay void myDisplay() { glClear(GL_COLOR_BUFFER_BIT); // clear the window glBegin(GL_POLYGON); // fill connected polygon glVertex2f(-0.7, 0.7); // vertices of the square glVertex2f( 0.6, 0.7); glVertex2f(-0.7, -0.6); glEnd(); glBegin(GL_POLYGON); // fill connected polygon glVertex2f( 0.7, 0.6); // vertices of the square glVertex2f(-0.6, -0.7); glVertex2f( 0.7, -0.7); glEnd(); glFlush(); //forces issued commands to execute }
  • 52. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 52 Example 1 500 500 (0.7,0.7) (-0.7,-0.7)
  • 53. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 53 Double Buffering § Double buffering is necessary for almost all OpenGL applications: § Render into back buffer § Swap buffers when finished rendering a frame: The old back buffer becomes the front buffer that is displayed. The old front buffer becomes the back buffer that is rendered into. § What happens when you do not use double buffering? § flickering artifacts, tearing artifacts § Commands: § glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); § glutSwapBuffers(); //instead of glFlush()
  • 54. Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 54 Homework Start Programming!
  • 55. SER332 Introduction to Graphics Javier Gonzalez-Sanchez javiergs@asu.edu Spring 2018 Disclaimer. These slides can only be used as study material for the class SER332 at ASU. They cannot be distributed or used for another purpose.