lecture 9: visualization6.s096 lecture 9 { visualization 3 / 28 opengl how will we use it? i’ve...
TRANSCRIPT
![Page 1: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/1.jpg)
6.S096 Lecture 9 – VisualizationOpenGL, Makefiles, Large Projects
Andre Kessler
Andre Kessler 6.S096 Lecture 9 – Visualization 1 / 28
![Page 2: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/2.jpg)
OpenGL
What is OpenGL?
The standard for most 2D/3D graphics renderingtoday.http://www.opengl.org/
Highly cross-platform (between OS, architecture, etc)
Everything from decade-old computers to mobile devices today.
An abstract API for drawing; bindings based in C
Interface with the GPU graphics pipeline.
Andre Kessler 6.S096 Lecture 9 – Visualization 2 / 28
![Page 3: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/3.jpg)
OpenGL
How do we get it?
There are a lot of really old (harmful!) tutorials outthere.
These are good ones:
Jason L. McKesson: http://www.arcsynthesis.org/gltut/
opengl-tutorial: http://www.opengl-tutorial.org/
WikiBooks
Andre Kessler 6.S096 Lecture 9 – Visualization 3 / 28
![Page 4: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/4.jpg)
OpenGL
How will we use it?
I’ve written some wrappers for the initialization (both general GL andglut).
Let’s look at the code (GlutWrapper.h)
Andre Kessler 6.S096 Lecture 9 – Visualization 4 / 28
![Page 5: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/5.jpg)
OpenGL
OpenGL Display Function (jumping ahead)
glBindBuffer( GL_ARRAY_BUFFER, _positionBufferObject );
glBufferSubData( GL_ARRAY_BUFFER, 0,
sizeof( float ) * _bufSize, _buf );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
Andre Kessler 6.S096 Lecture 9 – Visualization 5 / 28
![Page 6: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/6.jpg)
OpenGL
OpenGL Display Function (jumping ahead)
glUseProgram( _program );
glBindBuffer( GL_ARRAY_BUFFER, _positionBufferObject );
glEnableVertexAttribArray( 0 );
glVertexAttribPointer( 0, 4, GL_FLOAT, GL_FALSE, 0, 0 );
glDrawArrays( GL_TRIANGLE_STRIP, 0, (GLsizei) _bufSize );
glDisableVertexAttribArray( 0 );
glUseProgram( 0 );
glutSwapBuffers();
glutPostRedisplay();
Andre Kessler 6.S096 Lecture 9 – Visualization 6 / 28
![Page 7: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/7.jpg)
OpenGL
OpenGL Initialization
glutInit( &argc, argv );
uint32_t displayMode = GLUT_DOUBLE
| GLUT_ALPHA
| GLUT_DEPTH
| GLUT_STENCIL;
glutInitDisplayMode( displayMode );
// We’ll be using OpenGL 3.0
glutInitContextVersion( 3, 0 );
glutInitContextProfile( GLUT_CORE_PROFILE );
Andre Kessler 6.S096 Lecture 9 – Visualization 7 / 28
![Page 8: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/8.jpg)
OpenGL
OpenGL: Buffer Objects
glGenBuffers( 1, &_positionBufferObject );
glBindBuffer( GL_ARRAY_BUFFER, _positionBufferObject );
//..etc
glBufferData( GL_ARRAY_BUFFER, 4 * bufSize,
_buf, GL_STATIC_DRAW );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
Andre Kessler 6.S096 Lecture 9 – Visualization 8 / 28
![Page 9: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/9.jpg)
OpenGL
More in the code...
Let’s look into the code...
Andre Kessler 6.S096 Lecture 9 – Visualization 9 / 28
![Page 10: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/10.jpg)
OpenGL
Components
Requirements
25% Physics Engine - quality and extensibility of simulation code
25% Visualization - OpenGL; getting a good visualization working
15% Unit testing - gtest, quality and coverage of tests
15% Software Process - code reviews, overall integration of project
10% Interactive - user interactivity with simulation (keyboard, mouse, etc)
10% Do something cool - make it look cool, add a useful feature, dosomething interesting!
Extra 5% available in all areas for exceptional effort.
Andre Kessler 6.S096 Lecture 9 – Visualization 10 / 28
![Page 11: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/11.jpg)
OpenGL
Physics Engine Inaccuracies
Your integrator should be improving on the basic;this is what the basic one does:
Andre Kessler 6.S096 Lecture 9 – Visualization 11 / 28
![Page 12: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/12.jpg)
OpenGL
Binary Star System Example 1
Andre Kessler 6.S096 Lecture 9 – Visualization 12 / 28
![Page 13: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/13.jpg)
OpenGL
Binary Star System Example 2
Andre Kessler 6.S096 Lecture 9 – Visualization 13 / 28
![Page 14: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/14.jpg)
OpenGL
Binary Star System Example 3
Andre Kessler 6.S096 Lecture 9 – Visualization 14 / 28
![Page 15: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/15.jpg)
OpenGL
Binary Star System Example 4
Andre Kessler 6.S096 Lecture 9 – Visualization 15 / 28
![Page 16: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/16.jpg)
OpenGL
Binary Star System Example 5
Andre Kessler 6.S096 Lecture 9 – Visualization 16 / 28
![Page 17: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/17.jpg)
OpenGL
Binary Star System Example 6
Andre Kessler 6.S096 Lecture 9 – Visualization 17 / 28
![Page 18: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/18.jpg)
OpenGL
Binary Star System Example 7
Andre Kessler 6.S096 Lecture 9 – Visualization 18 / 28
![Page 19: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/19.jpg)
OpenGL
Binary Star System Example 8
Andre Kessler 6.S096 Lecture 9 – Visualization 19 / 28
![Page 20: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/20.jpg)
OpenGL
Binary Star System Example 9
Andre Kessler 6.S096 Lecture 9 – Visualization 20 / 28
![Page 21: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/21.jpg)
OpenGL
Binary Star System Example 10
Andre Kessler 6.S096 Lecture 9 – Visualization 21 / 28
![Page 22: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/22.jpg)
OpenGL
Visualization
OpenGL!
Andre Kessler 6.S096 Lecture 9 – Visualization
Courtesy of Aaron M. Geller. Used with permission.
22 / 28
![Page 23: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/23.jpg)
OpenGL
Content Provided: Reminder
Vector3.h
So that you don’t have to write (all) of your own vector math, feel free touse the header available.
It’s a templated 3-d vector class that can be widely useful and isguaranteed fast (“plain old data type”)
Andre Kessler 6.S096 Lecture 9 – Visualization 23 / 28
![Page 24: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/24.jpg)
OpenGL
Content Provided - Vector3.h
template<typename T>
class Vector3 {
T _x, _y, _z;
public:
Vector3() : _x{}, _y{}, _z{} {}
Vector3( T x_, T y_, T z_ ) :
_x{x_}, _y{y_}, _z{z_} {}
inline T x() const { return _x; }
inline T y() const { return _y; }
inline T z() const { return _z; }
T norm() const;
T normsq() const;
};
Andre Kessler 6.S096 Lecture 9 – Visualization 24 / 28
![Page 25: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/25.jpg)
Makefile Structure
Reminder: the compilation process
1. Preprocess
2. Compile
3. Link
Andre Kessler 6.S096 Lecture 9 – Visualization 25 / 28
![Page 26: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/26.jpg)
Makefile Structure
Code Reviews: what you send to me
Your name and the name of the person whose code you are reviewing.
The snippet of code you are reviewing: more than 30 lines, less than100.
Your comments interspersed in their code.
A summary of main points relating to the review (what they did well,major areas for improvement, common issues, general observations).
You should choose a bite-sized chunk that will take you 45 mins to 1 hourto fully review.
Andre Kessler 6.S096 Lecture 9 – Visualization 26 / 28
![Page 27: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/27.jpg)
Makefile Structure
Code Reviews: what you send to me
Your name and the name of the person whose code you are reviewing.
The snippet of code you are reviewing: more than 30 lines, less than100.
Your comments interspersed in their code.
A summary of main points relating to the review (what they did well,major areas for improvement, common issues, general observations).
You should choose a bite-sized chunk that will take you 45 mins to 1 hourto fully review.
Andre Kessler 6.S096 Lecture 9 – Visualization 26 / 28
![Page 28: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/28.jpg)
Makefile Structure
Examples
Let’s see some examples...
Andre Kessler 6.S096 Lecture 9 – Visualization 27 / 28
![Page 29: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/29.jpg)
Wrap-up
Wrap-up & Friday
Final project due Saturday
Send me your code reviews tonight please!
Class on Fri.
Grab-bag: coding interviews, general perspective
Bring all your C++ questions!
Questions?
Lab today
We’ll be covering more OpenGL and helping out with projects.
Andre Kessler 6.S096 Lecture 9 – Visualization 28 /28
![Page 30: Lecture 9: Visualization6.S096 Lecture 9 { Visualization 3 / 28 OpenGL How will we use it? I’ve written some wrappers for the initialization (both general GL and glut). Let’s look](https://reader035.vdocuments.net/reader035/viewer/2022063001/5f1c6dd6b03c3c0f6e3735e8/html5/thumbnails/30.jpg)
MIT OpenCourseWarehttp://ocw.mit.edu
6.S096 Effective Programming in C and C++IAP 2014
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.