Category Archives: OpenGL
OpenGL Blending
Blending 예제
http://dis.dankook.ac.kr/lectures/cg08/entry/blending-예제
Blending Filter 예제
http://dis.dankook.ac.kr/lectures/cg08/entry/blending-filter-예제
// Default (no blending) = Cs*1
glBlendFunc(GL_ONE, GL_ZERO)
// Draw background only = Cd*1
glBlendFunc(GL_ZERO, GL_ONE) // Addition Blending = Cs*1 + Cd*1
glBlendFunc(GL_ONE, GL_ONE)
// Alpha blending (back-to-front) = Cs*As + Cd*(1-As)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) // Brighten the scene = Cs*As + Cd*1
glBlendFunc(GL_SRC_ALPHA, GL_ONE) // Multiplicative blending = Cd*Cs
glBlendFunc(GL_ZERO, GL_SRC_COLOR)// darken the scene = Cd*As
glBlendFunc(GL_ZERO, GL_SRC_ALPHA);// Invert all the colors = Cs*(1-Cd)
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO)
OpenGL Texture Mapping
/// init texture
void initTexture(char *filename, GLuint& textureID, GLint param=GL_REPEAT)
{
// 중간 생략
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, param);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, param);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, numComponents == 3 ? GL_RGB : GL_RGBA, imageWidth, imageHeight,
0, numComponents == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, imageBuffer);
glBindTexture(GL_TEXTURE_2D, 0);
}
/// Draw
void draw()
{
glBindTexture(GL_TEXTURE_2D, texID1);
glBegin(GL_QUADS);
glNormal3f(0, 0, 1);
glTexCoord2i( __________________ );
glVertex3f(-2.0, -1.0, 0.0);
glTexCoord2i(__________________);
glVertex3f(-0.1, -1.0, 0.0);
glTexCoord2i(__________________);
glVertex3f(-0.1, 1.0, 0.0);
glTexCoord2i(__________________);
glVertex3f(-2.0, 1.0, 0.0);
glEnd();
}
OpenGL Texture Mapping
Texture binding, texture generate, texture filtering, texture subimage, texture mapping by procedural definition & using imagefile, mipmapping, texture environment setting (modulate/decal), texture distorting, texture transformation, flipbook animation, etc
http://dis.dankook.ac.kr/lectures/cg08/entry/texture-mapping-예제
Texture filtering & environment paramaters
http://dis.dankook.ac.kr/lectures/cg08/entry/texture-filtering-environment-parameters-예제
wrapping parameters (REPEAT | CLAMP)
magnification/minification filter parameters (NEAREST | LINEAR | LINEAR_MIPMAP_LINEAR)
environment parameters (MODULATE | DECAL | BLEND | REPLACE)
Texture generation
http://dis.dankook.ac.kr/lectures/cg08/entry/texture-generation-예제
Multitexturing
http://dis.dankook.ac.kr/lectures/cg09/entry/OPENGL-Multitexturing
multipass-multitexturingsingpass-multitexturing
Billboarding
http://dis.dankook.ac.kr/lectures/cg09/entry/OPENGL-Billboarding
Before Billboarding
After Billboarding
OpenGL Material
OpenGL Shading
shading model – FLAT/SMOOTH
shademodel.cpp
if (shading == GL_FLAT)
glShadeModel(GL_FLAT);
else if (shading == GL_SMOOTH)
glShadeModel(GL_SMOOTH);
glPushMatrix();
glTranslatef(-1.0, 0.0, 0.0);
glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0); // red
glVertex3f(-1, -1, 4);
glColor3f(0, 1, 0); // green
glVertex3f(1, -1, 4);
glColor3f(0, 0, 1); // blue
glVertex3f(0, 1, 4);
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(1.0, 0.0, 0.0);
glBegin(GL_TRIANGLES);
glColor3f(0, 0, 1); // blue
glVertex3f(-1, -1, 4);
glColor3f(0, 1, 0); // green
glVertex3f(1, -1, 4);
glColor3f(1, 0, 0); // red
glVertex3f(0, 1, 4);
glEnd();
glPopMatrix();
OpenGL Lighting and Shading
OpenGL Shadow Reflection
planar shadow (double blending effect) 6201891012.cpp
stencil shadow (stencil buffer to avoid double blending on shadow) 2273437428.cpp
// create a shadow matrix that will project the desired shadow
void buildShadowMatrix(GLfloat shadowMat[16], GLfloat plane[4], GLfloat lightpos[4])
{
GLfloat dot; // dot product of light position and ground plane normal
dot = plane[0]*lightpos[0] + plane[1]*lightpos[1] +
plane[2]*lightpos[2] + plane[3]*lightpos[3];
shadowMat[0] = dot – lightpos[0] * plane[0];
shadowMat[1] = – lightpos[0] * plane[1];
shadowMat[2] = – lightpos[0] * plane[2];
shadowMat[3] = – lightpos[0] * plane[3];
shadowMat[4] = – lightpos[1] * plane[0];
shadowMat[5] = dot – lightpos[1] * plane[1];
shadowMat[6] = – lightpos[1] * plane[2];
shadowMat[7] = – lightpos[1] * plane[3];
shadowMat[8] = – lightpos[2] * plane[0];
shadowMat[9] = – lightpos[2] * plane[1];
shadowMat[10] = dot – lightpos[2] * plane[2];
shadowMat[11] = – lightpos[2] * plane[3];
shadowMat[12] = – lightpos[3] * plane[0];
shadowMat[13] = – lightpos[3] * plane[1];
shadowMat[14] = – lightpos[3] * plane[2];
shadowMat[15] = dot – lightpos[3] * plane[3];
}
planar reflection (demonstrate reflection matrix)
9670376557.cppstencil reflection (stencil buffer to render mirror surface) 8244993501.cpp
// create a reflection matrix that will project the desired shadow
void buildReflectionMatrix(GLfloat reflectionMat[16], GLfloat plane[4])
{
reflectionMat[0] = 1 – 2 * plane[0] * plane[0];
reflectionMat[1] = – 2 * plane[0] * plane[1];
reflectionMat[2] = – 2 * plane[0] * plane[2];
reflectionMat[3] = – 2 * plane[0] * plane[3];
reflectionMat[4] = – 2 * plane[1] * plane[0];
reflectionMat[5] = 1 – 2 * plane[1] * plane[1];
reflectionMat[6] = – 2 * plane[1] * plane[2];
reflectionMat[7] = – 2 * plane[1] * plane[3];
reflectionMat[8] = – 2 * plane[2] * plane[0];
reflectionMat[9] = – 2 * plane[2] * plane[1];
reflectionMat[10] = 1 – 2 * plane[2] * plane[2];
reflectionMat[11] = – 2 * plane[2] * plane[3];
reflectionMat[12] = 0.0;
reflectionMat[13] = 0.0;
reflectionMat[14] = 0.0;
reflectionMat[15] = 1.0;
}
http://dis.dankook.ac.kr/lectures/cg09/entry/OPENGL-ShadowMatrix-ReflectionMatrix
OpenGL camera
town – LEFT/RIGHT/UP/DOWN – x축/z축으로 카메라의 위치를 움직임
uptown – LEFT/RIGHT/UP/DOWN – y축/x축으로 물체를 회전시킴
LEFT MOUSEBUTTON MOTION – x축과 y축으로 물체를 회전시킴
MIDDLE MOUSEBUTTON MOTION – x축과 y축으로 물체를 이동시킴
RIGHT MOUSEBUTTON MOTION – x축과 z축으로 물체를 이동시킴
camera class를 사용하여 x/y/x축 카메라의 위치이동과 x/y/x축 카메라의 방향이동
F1&F2 – x축 카메라 위치이동
F3&F4 – y축 카메라 위치이동
F5&F6 – z축 카메라 위치이동
F7&F8 – x축 카메라 방향이동 (PITCH)
F9&F10 – y축 카메라 방향이동 (YAW)
HOME&END – z축 카메라 방향이동 (ROLL)
http://dis.dankook.ac.kr/lectures/cg08/entry/camera-movement