Mohammad Shaker
Mohammadshaker.com mohammadshakergtr.wordpress.com
OpenGL Starter Course
@ZGTRShaker
Cube Maps
Cube Maps
Cube Maps
glBegin(GL_QUADS);
// Negative X
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);
glTexCoord3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-fExtent, fExtent, fExtent);
…..
Texture Mapping
FPS
FPS
Frame 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 specular
or 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 Values
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values
GLfloat 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 TRUE
blend =!blend; // Toggle blend TRUE / FALSE
if(blend) // Is blend TRUE?
{
glEnable(GL_BLEND); // Turn Blending On
glDisable(GL_DEPTH_TEST); // Turn Depth Testing Off
}
else // Otherwise
{
glDisable(GL_BLEND); // Turn Blending Off
glEnable(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 plane
DrawModels(GL_TRUE);
// Enable alpha test so that shadowed fragments are discarded
glAlphaFunc(GL_GREATER, 0.9f);
glEnable(GL_ALPHA_TEST);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
// Set up shadow comparison
glEnable(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 scene
glEnable(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 Life
float fade; // Fade Speed
float r; // Red Value
float g; // Green Value
float b; // Blue Value
float x; // X Position
float y; // Y Position
float z; // Z Position
float xi; // X Direction
float yi; // Y Direction
float zi; // Z Direction
float xg; // X Gravity
float yg; // Y Gravity
float zg; // Z Gravity
} particles; // Particles
particles 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
mohammadshakergtr@gmail.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/
OpenGL Starter L02

OpenGL Starter L02