Download - OpenGL Starter L02
Mohammad ShakerMohammadshaker.com mohammadshakergtr.wordpress.com
OpenGL Starter Course@ZGTRShaker
Cube Maps
Cube Maps
Cube Maps
glBegin(GL_QUADS);// Negative XglTexCoord3f(-1.0f, -1.0f, 1.0f);glVertex3f(-fExtent, -fExtent, fExtent);glTexCoord3f(-1.0f, -1.0f, -1.0f);glVertex3f(-fExtent, -fExtent, -fExtent);glTexCoord3f(-1.0f, 1.0f, -1.0f);glVertex3f(-fExtent, fExtent, -fExtent);glTexCoord3f(-1.0f, 1.0f, 1.0f);glVertex3f(-fExtent, fExtent, fExtent);…..
Texture Mapping
FPS
FPSFrame Per Second
Lighting and Blending!
Lighting and Blending!
Combining light and texture
Lighting
Lighting
Lighting
Lighting
Lighting
Lighting
Lighting
Lighting
Lighting
Lighting
Lighting - Types
• Ambient Light: doesn’t come from any particular direction. It has an original
source somewhere, but the rays of light have bounced around the room or scene
and become directionless.
Lighting - Types
• Diffuse Light: The diffuse part of an OpenGL light is the directional component
that appears to come from a particular direction and is reflected off a surface with
an intensity proportional to the angle at which the light rays strike the surface.
Thus, the object surface is brighter if the light is pointed directly at the surface
than if the light grazes the surface from a greater angle.
Lighting - Types
• Specular light: Like diffuse light, specular light is a highly directional property, but
it interacts more sharply with the surface and in a particular direction.
Lighting
The per-vertex specular highlight is improved by using separate specularor a specular exponent texture.
Lighting
• An unlit jet reflects no light.
Lighting
The output from the completed AMBIENT sample program.
The output from the AMBIENT program when the light source is cut in half.
Lighting
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position
Lighting
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position
Lighting
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
glEnable(GL_LIGHT1); // Enable Light One
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position
Lighting
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light ValuesGLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light ValuesGLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position
if (keys['B']) // Is B Key Pressed And bp FALSE?{
bp=TRUE; // If So, bp Becomes TRUEblend =!blend; // Toggle blend TRUE / FALSEif(blend) // Is blend TRUE?{
glEnable(GL_BLEND); // Turn Blending OnglDisable(GL_DEPTH_TEST); // Turn Depth Testing Off
}else // Otherwise{
glDisable(GL_BLEND); // Turn Blending OffglEnable(GL_DEPTH_TEST); // Turn Depth Testing On
}}
Blending
Blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Blending
Wire Framing
Wire Framing
Shadowing
Shadowing
Shadowing
Shadowing
Shadowing
Shadowing
// Draw objects in the scene, including base planeDrawModels(GL_TRUE);
// Enable alpha test so that shadowed fragments are discardedglAlphaFunc(GL_GREATER, 0.9f);glEnable(GL_ALPHA_TEST);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
// Set up shadow comparisonglEnable(GL_TEXTURE_2D);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,GL_COMPARE_R_TO_TEXTURE);
// Set up the eye plane for projecting the shadow map on the sceneglEnable(GL_TEXTURE_GEN_S);glEnable(GL_TEXTURE_GEN_T);glEnable(GL_TEXTURE_GEN_R);glEnable(GL_TEXTURE_GEN_Q);….
DrawModels(GL_TRUE);
Depth Buffer
Fog
Fog
• Why Fog?!
Blurring
Blurring
Blurring
Blurring
Blurring
Dynamic environment mapping
Dynamic environment mapping
Camera
Camera
Camera
Camera
Camera
Clipping
Clipping
Reflection
Reflection
Brightening
Brightening
Blooming!
Blooming!
Blooming!
Antialiasing
Anitalysing
Particles System
Particles System
Particles System
Particles System
Simple Particle System
• glTexCoord2d();
typedef struct // Create A Structure For Particle{
bool active; // Active (Yes/No)float life; // Particle Lifefloat fade; // Fade Speedfloat r; // Red Valuefloat g; // Green Valuefloat b; // Blue Valuefloat x; // X Positionfloat y; // Y Positionfloat z; // Z Positionfloat xi; // X Directionfloat yi; // Y Directionfloat zi; // Z Directionfloat xg; // X Gravityfloat yg; // Y Gravityfloat zg; // Z Gravity
} particles; // Particlesparticles particle[MAX_PARTICLES]; // Particle Array (Room For Particle Info)
LensFlare
LensFlare
Shaders
Shaders
Shaders
Shaders
Shaders
Shaders
Shaders
Shaders
Shaders – Geometry Shaders
3D Object Loaders
3D Object Loaders
3D Object Loaders
3D Object Loaders
3D Object Loaders
3D Object Loaders
Terrain
Terrain
Height map
Height map
Height map
Height map
Sound Engines
Sound Engine
• Fmod
• OpenAL
• Others
End of a Very Short Intro to OpenGL
Take a Look on my other courses @ http://www.slideshare.net/ZGTRZGTR
Available courses to the date of this slide:
http://www.mohammadshaker.com
https://twitter.com/ZGTRShaker @ZGTRShaker
https://de.linkedin.com/pub/mohammad-shaker/30/122/128/
http://www.slideshare.net/ZGTRZGTR
https://www.goodreads.com/user/show/11193121-mohammad-shaker
https://plus.google.com/u/0/+MohammadShaker/
https://www.youtube.com/channel/UCvJUfadMoEaZNWdagdMyCRA
http://mohammadshakergtr.wordpress.com/