frame buffer 라는 large block of memory 에 저장 됨. Screen 의 color 값 변경은 frame buffer 값 변경으로 이루어 짐.GIF,PNG,JPEG,WebP, natural coordinate system 활용Silicon Graphics 에 의해 개발.sharders 를 제공 (GLSL(OpenGL Shading Lanuage) programming language 사용)(rendering pipeline 의 몇 개 stage 에서 실행 됨)aliasing : discre 한 pixel 에 image 를 표현하다보니 계단과 같이 이미지가 보이는 현상. (jagged)antialiasing : pixel 이 partially covered 되면 background color 와 mix 해서 aliasing 을 줄이는 방법.stroke,fillstroke : 경계를 선으로 긋는 것Fill : closed surface 라면 그냥 Fillwinding number 활용. winding number 란 positive direction 으로 몇 번 감싸졌는지.polygon 을 활용. polygon 은 line segments 로 이루어짐.regular polygon : 길이,각도가 모두 동일convex polygon : polygon 내부에 어떤 2점을 잇든, 그 이은 선이 polygon 내부에 있는 경우.path 를 활용.path 에는 create,move,lineto,closepath 등 command 를 가짐path 는 line 뿐만 아니라 curve 도 될 수 있음. (Bezier curve:2차/3차 다항식 등) Bezier curve 는 control points 로 곡선 형태 조절 가능.Viewport : image 가 display 될 pixel 로 이루어지고 natural pixel coordinates 를 활용하는 rectangle. Window 에서 Viewport 로 coordinate transform 이루어짐. (보통 T 로 표현)world coordinates : 각각 다른 실수 좌표계로 정의된 geometric objects 이 모여 "scence", "world" 를 만드는 좌표계object coordinates 라 함. object 를 scene 에 옮기기 위해서는 object coordinates 에서 scene 에 활용하는 world coordinate system 으로 옮겨야 하고, 이걸 modeling transformation 이라 함. (좌표계가 3개가 있는 것??)affine transform : T(x,y) = (ax+by+e,cx+dy+f) 꼴의 좌표 변환scene graph : tree like structure. root 는 entire scene, children 은 top-level objects in the scene.glPushMatrix(), glPopMatrix() 를 stack of transformation matrices 로 사용.primitive) 만 drawing 가능. curve, curve shape drawing 은 불가능 하고 approximation 만 가능.vertices 로 정의 됨. vertex 는 x,y,z 좌표로 이루어진 점.glVertex2f(<x>,<y>) 에서 2 는 paramter 개수, f는 data type 을 의미.GL_POINTS. single point 를 rendering.GL_LINES,GL_LINE_STRIP,GL_LINE_LOOPGL_LINES : disconnected line segment 를 drawing. 2개의 vertices 를 지정.GL_LINES : connected line segment 를 drawing. 2개의 vertices 를 지정.GL_LINE_LOOP : connected line segment 를 drawing. 2개의 vertices 를 지정. final vertex 로 돌아감. (closed)GL_TRIANGLES,GL_TRIANGLE_STRIP,GL_TRIANGLE_FANGL_QUADS,GL_QUAD_STRIP,GL_POLYGONglColor* 이름을 가짐.glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor3f(<r,g,b>), glColor4f(<r,g,b,a>)glColor3fv,glVertex2iv,etc.depth test 를 사용.depth testdepth 는 viewer 부터 object 까지의 거리를 의미. depth 가 작은 object 가 depth 가 큰 object 를 가림.depth value 를 가짐. 추가 메모리를 써서 depth value 를 저장하는 depth buffer 구성. Drawing 할 때 depth buffer 를 참고해서 pixel 이 visible 한 지 안한지 판단. depth value 는 z좌표를 활용하고 -1 ~ 1 range 를 가짐. default 로 depth test 는 turn off 되있으므로, glEnable(GL_DEPTH_TEST) 호출이 반드시 필요. depth value 는 numerical precision 한계를 가지고 있기 때문에, 여러 object 가 같은 값을 가지는 한계가 발생 할 수도 있음.modeling : construct a scene in 3Deye coordinate 는 z축이 화면에 수직, viewer 쪽의 방향이 (+). x/y 는 나머지는 right-handed cooridnate system. (world coordinates 와 eye coordinate 는 다를 수 있음.)object coordinates 를 가지고 modeling transforms 를 통해 world, complex objects 에 배치 됨.glRotate(r,ax,ay,az) r 은 회적 각도, ax/ay/ax 은 회전축 지정stack of transforms 를 활용object coordinates : 실제 object 를 그리는데 사용하는 좌표modeling transformation : 전체 scene 에서 size,orientation,position 을 조절.world coordinates : complete scene 을 구성하는 coordinates. (modeling transformation maps from object coordinates to world coordinates)eye coordinates : viewer 의 좌표계. viewer 는 origin(0,0,0) 에 있으며, 음의 z축 방향을 보고 있음 (모니터 방향)viewing transformation : world coordinates 에서 eye coordinates로의 변환.modelview transformation : modeling, viewing transform 을 1개의 transform 으로 조합. OpenGL 내부에서는 world coordinates 를 전혀 사용하지 않고, modelview transformation을 사용해서 object coordinates 를 eye coordinates 로 바로 이동.viewport : viewer 는 전체 3D world 를 다 볼 수 있고, viewport 라는 일부 부분만 봄.view volume : 실제로 rendering 되는 volume of space.view volume 을 cube 에 mapping 하는 coordinate transform 을 적용.cube : 중점이 origin 에 있고, x/y/z 좌표가 -1 ~ 1 까지 존재. cube 의 좌표계를 clip coordinates 라고 함.projection transformation : eye coordinates 에서 clip coordinates 를 projection transformation 라고 함.device coordinates : 실제 physical display 에서 그림이 그려지는 2D coordinate system. 일반적으로 device coordinates 의 단위는 pixel. drawing region 은 rectangle of pixels 이고, 이 rectangle 이 viewport.viewport transformation : clip coordinates 를 viewport 로 fit.glViewport(x,y,width,height) 함수를 활용.JOGL 이나 C 용 GLUT library 를 사용해서 화면에 drawing.modelview transformation 과 별도로 projection matrix 를 tracking 함. glRotatef 와 같은 함수는 두 matrix 모두에 적용 될 수 있으므로, 어느 matrix 에 적용 할 지 알기 위해 matrix mode 라는 state property 를 활용. matrix mode 의 값은 GL_PROJECTION, GL_MODELVIEW.view volume 은 무한한 3D world 에서 일부만 해당되며, view volume 은 viewing transformation 과 project 의 조합으로 결정 됨.view transform 은 viewr 가 어디에 위치해 있고, 어느 방향으로 보는지는 정하지만, 얼만큼 보는지는 정하지 않음. projection transform 이 정함. view 안의 모양과 범위를 정함. 카메라가 실제 세상을 보고 있다고 생각하면, view transform 은 카메라의 위치와 방향을 의미하고, projection transform 은 카메라로 실제로 볼 수 있는 Box 의 모양과 크기를 결정한다고 보면 됨.perspective projection 과 orthographic projection이 있음.perspective projectionnear,far 2개의 값의 거리안의 truncated pyramid(frustum)만 보이게 함.glFrustum(xmin,xmax,ymin,ymax,near,far) 함수로 set-uporthographic projectionz 좌표를 삭제하고 3D 를 2D 로 투영. 원근감이 없음. near,far 사용glOrtho(xmin,xmax,ymin,ymax,Near,Far);modeling,viewing 은 개념적으로는 다르지만, matrix 처리 관점에서는 동일.glRotatef(90,0,1,0); 명령은 object y축 기준 90도 회전하는 것과, viewer 를 -90도 회전하는 것으로 모두 동일하게 표현 가능.points,lines,polygons 만 rendering 가능.polyhedron,polygonal mesh 은 polygon 으로 이루어져 있고, curved surface,sphere 는 polygon 으로 approximation 가능.IFS 에서는 모든 vertex 의 좌표를 가짐.Vertex #0. (2, -1, 2)
Vertex #1. (2, -1, -2)
Vertex #2. (2, 1, -2)
Vertex #3. (2, 1, 2)
Vertex #4. (1.5, 1.5, 0)
Vertex #5. (-1.5, 1.5, 0)
Vertex #6. (-2, -1, 2)
Vertex #7. (-2, 1, 2)
Vertex #8. (-2, 1, -2)
Vertex #9. (-2, -1, -2)
Face #0: (0, 1, 2, 3)
Face #1: (3, 2, 4)
Face #2: (7, 3, 4, 5)
Face #3: (2, 8, 5, 4)
Face #4: (5, 8, 7)
Face #5: (0, 3, 7, 6)
Face #6: (0, 6, 9, 1)
Face #7: (2, 1, 9, 8)
Face #8: (6, 7, 8, 9)
IFS 의 장점IFS 에서는 Face 의 vertex 를 index(integer) 로 표현하기 때문에, vertex 의 coordinates 를 정의하는 횟수가 줄어서 memory space 이득이 있음.face 와 vertex 를 따로 drawing 하고 싶을 때, depth 가 같은 문제가 존재하므로, polygon offset 을 활용해서 depth 를 살짝 다르게 함.glVertex2d,glColor3fv,glBegin/glEnd)glDrawArrays, glDrawElements 를 활용 (WebGL 에서도 사용)glDrawArraysglDrawArrays 함수 호출 1번으로 drawint,float,double 을 사용 할 수 있으며, 좌표는 2/3/4 개 사용 가능glVertexPointerglVertexPointer 를 통해서 vertex array meta 정보를 넘겨 줌.void glVertexPointer(int size, int type, int stride, void* array)glEnableClientState(GL_VERTEX_ARRAY); 가 호출 되어야 사용 가능.float coords[8] = { -0.5,-0.5, 0.5,-0.5, 0.5,0.5, -0.5,0.5 };
glVertexPointer( 2, GL_FLOAT, 0, coords );glDrawArraysglDrawArrays 를 사용해서 최종적으로 drawingvoid glDrawArrays(int primitiveType,int firstVertex,int vertexCount) primitiveType : primitive type (ex:GL_QUADS)firstVertext : primitive 를 drawing 하는데 사용되는 first vertex 숫자vertextCount : 사용되는 vertices 숫자.glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );glColorPointvoid glColorPointer(int size, int type, int stride, void* array)glEnableClientState(GL_COLOR_ARRAY); 호출 필요float coords[6] = { -0.9,-0.9, 0.9,-0.9, 0,0.7 }; // two coords per vertex.
float colors[9] = { 1,0,0, 0,1,0, 1,0,0 }; // three RGB values per vertex.
glVertexPointer( 2, GL_FLOAT, 0, coords ); // Set data type and location.
glColorPointer( 3, GL_FLOAT, 0, colors );
glEnableClientState( GL_VERTEX_ARRAY ); // Enable use of arrays.
glEnableClientState( GL_COLOR_ARRAY );
glDrawArrays( GL_TRIANGLES, 0, 3 ); // Use 3 vertices, starting with vertex 0.
glDrawElementsglDrawArrays 와 유사하지만, IFS format 에 사용되도록 설계.void glDrawElements( int primitiveType, vertexCount, dataType, void *array)float vertexCoords[24] = { // Coordinates for the vertices of a cube.
1,1,1, 1,1,-1, 1,-1,-1, 1,-1,1,
-1,1,1, -1,1,-1, -1,-1,-1, -1,-1,1 };
float vertexColors[24] = { // An RGB color value for each vertex
1,1,1, 1,0,0, 1,1,0, 0,1,0,
0,0,1, 1,0,1, 0,0,0, 0,1,1 };
int elementArray[24] = { // Vertex numbers for the six faces.
0,1,2,3, 0,3,7,4, 0,4,5,1,
6,2,1,5, 6,5,4,7, 6,7,3,2 };
glVertexPointer( 3, GL_FLOAT, 0, vertexCoords );
glColorPointer( 3, GL_FLOAT, 0, vertexColors );
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glDrawElements( GL_QUADS, 24, GL_UNSIGNED_INT, elementArray );
display lists 와 VBO (Vertex Buffer Objects) 기술이 존재.glDrawArrays(),glDrawElements() 를 VBO 에서 사용 가능affine transformationglMultMatrixf(T) 함수를 사용하여 임의의 변환 행렬을 사용하는 것도 가능.homogeneous coordinateshomogeneous coordinates 로 표현.glEnable(GL_LIGHTING) 호출 필요.material : The properties of a surface that determine how it interacts lightspecular reflectionspecular highlights : surface 가 모두 illuminated 되어도, 반사된 빛이 viewer 에게 도착한 경로의 surface 만, 빛이 보이는 효과.shininess : specular highlights 의 size 와 sharpness 를 결정하는 material propertyDiffuse reflectiondiffuse color 는 diffuse reflection 의 양을 결정, specular color 는 specular reflection 의 양을 결정, OpenGL 은 ambient color 도 존재하여 ambient light(주변광) 의 반사량을 결정. emission color 는 빛이 있을 때 조금 더 brighter 한 특성.point light : 모든 방향으로 빛을 내보냄.directional light : 같은 방향으로 빛을 내보냄. (빛이 parallel)(태양)ambient color, diffuse color, specular color 를 가지며, intensity or energy 를 의미. 각각의 material 과 얼만큼 세기로 작용하는지를 의미.unit normal vector)를 알아야 각도 계산 가능. (법선 벡터는 polygon 의 앞면 방향) Vertices of a primitive 에 있는 normal vector 를 lighting 계산에 활용. Vertex 마다 normal vector 를 할당.Flat shading : surface 가 face 처럼 보이게 함. 법선 벡터가 Face 에 대해서 수직.Smooth shading : surface 가 smooth 하게 보이게 함. 법선 벡터가 vertex 를 지나는 curved surface 에 대해서 수직.lighting calculation 은 한 point 에 대해서 color (rgb) 를 계산하는 것.
OpenGL 1.1 에서는 vertices of a primitive 에서만 calculation 수행. vertex 에서 꼐산이 완료되면, primitive 의 interior point 는 interpolation.
a(alpha) 계산은 단순함. rgb 계산은 복잡함.
red color of vertex :
빛의 color 기여분 계산
shiness() 값이 클 수록 작고,sharp 한 specular highlight 가 생김.이 외에도 빛의 거리에 의한 효과, spotlight, shadw 효과 등이 더 존재함.
void glMaterialfv(int side, int property, float* valueArray)float[] gold = { 0.24725F, 0.1995F, 0.0745F, 1.0F, /* ambient */
0.75164F, 0.60648F, 0.22648F, 1.0F, /* diffuse */
0.628281F, 0.555802F, 0.366065F, 1.0F, /* specular */
50.0F /* shininess */
};
gl.glMaterialfv( GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, gold, 0 );
gl.glMaterialfv( GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, gold, 4 );
gl.glMaterialfv( GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, gold, 8 );
gl.glMaterialf( GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, gold[12] );
Gl_LIGHT0 과 같이 선언 할 수 있으며 directional ligth,point light 종류가 있고, 각 광원은 diffuse,specular,ambient intensity 가질 수 있음.void glLightfv(int light, int property, float* valueArray);GL_POSITION property로 좌표 설정.modelview transformation 전에 설정. ...viewing transformation 후에 설정. ...modeligh transformation 이후 위치 설정. ...GL_LIGHT_MODEL_AMBIENTGL_LIGHT_MODEL_TWO_SIDE : 양면의 조명을 키는데 사용GL_LIGTH_MODEL_LOVAL_VIEWERTexture : Surface 에 pattern 을 부여. 단일 primitive 내에서 pixel to pixel 간 변형.Image textures : Texture 중 한 종류.OpenGL 에서는 Texture image width, height 는 2 의 제곱 꼴.Texture 가 surface 에 적용 될 때, surface 의 각 점은 texture 의 점과 Mapping 되어야 함. 이를 위해 object 는 texture coordinates 가 필요. OpenGL 에서는 primitive 의 각각 vertex 마다 texture coordinates 가 지정 됨. primitive 내부 점은 vertex 에서의 interpolation 으로 결정 됨.Texture image 는 자체 2D coordinate system 과 함께 제공 됨. s 는 수평 좌표, t 는 수직 좌표, 좌표는 좌하단부터 (0,0) 으로 시작해서 0 ~ 1 범위의 실수 값. (0 ~ 1 밖의 값도 여전히 텍스트 좌표로 유효하긴 함) Texture 좌표는 픽셀 개수와는 상관 없음.textured primitive 를 위해서는 각 vertex 마다 (s,t) 좌표가 필요. texture coordinate 는 vertex 의 attributeglNormal3d(0,0,1); // This normal works for all three vertices.
glBegin(GL_TRIANGLES);
glTexCoord2d(0.3,0.1); // Texture coords for vertex (0,0)
glVertex2d(0,0);
glTexCoord2d(0.45,0.6); // Texture coords for vertex (0,1)
glVertex2d(0,1);
glTexCoord2d(0.25,0.7); // Texture coords for vertex (1,0)
glVertex2d(1,0);
glEnd();
texture coordinates 지정은 다소 어려우므로, 쉬운 방법은 그냥 전체 좌표 (0,0), (1,1) 으로 지정해 버리는 것.minification filter : texture 에서의 2개 이상의 pixel 이 surface 에서의 1개 의 pixel 을 덮을 때.magnification filter : texture 에서의 1개의 pixel 이 surface 에서의 2개 이상의 pixel 을 덮을 때.texels : texture 의 pixel 을 칭 함. texture pixel, texture element.nearest texel filtering : 가장 가까운 texel 의 color 활용, 결과가 좋지는 않음.linear filtering : 여러 texel color 의 average 값을 활용. surface area 가 texture 대비 많이 작을 때는 비효율 적.mipmaps : texture 이미지의 size 를 줄여서 활용. minification filtering 에만 활용. surface 의 크기와 가장 유사한 mipmap 을 선택 한 후, linear filtering 수행.texture 는 2D 뿐만 아니라 1D,3D 도 사용 가능.Texture 가 surface 에 적용되는 세부 옵션 조절 :glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);homogeneous coordinates 로 활용. 좌표계는 (s,t,r,q) 로 표현 됨.texture coordinates 는 vertex coordinates 오 다르지 않으므로, transformation 이 같은 방식으로 이루어짐. modelview, projection transformation 에 따라서 texture transformation 이 행해 짐. 3개 변환의 각각의 값은 matrix 로 저장 됨.texture matrix 는 scaling,rotation,translation 및 조합으로 나타내 짐.glTexImage2D(target, mipmapLevel, internalFormat, width, height, border, format, dataType, pixels);texture objects 를 도입.texture objects 는 동일 프로그램에서 여러 텍스처 이미지로 작업 할 때 사용. GPU 에 여러 texture data 를 미리 저장해 놓을 수 있음.directed acyclic graph(dag) 일 수 있음. (node 가 여러 parent 를 가질 수 있는 자료구조, 1개의 parent 를 가지는 tree 와는 다름)glPushMatrix, glPopmatrix 는 transform stack 을 조작하는데 활용 됨.glPushMatrix 가 호출되고, 해당 node 와 하위 항목들이 rendering 된 후에, glPopMatrix 가 호출되어 이전의 modelview transformation 을 복구 함.glPushAttrib, glPopAttrib 함수를 활용해서 attribute stack 을 유지.viewing transformation 을 결정)modeling transformation 에 적용하는건, scence 전체에 viewing transformation 을 하는 것과 같고, viewing transformation 은 camera 의 modeling transformation 을 하는 것의 역과 같음.scene graph 에 camera object node 를 포함시키면 도움 됨 (?)scene graph 가 탐색 될 때, 어떤 node 든 path 에 따라 적용된 모든 transform 의 합인 modeling transformation 이 적용 됨. 그런데 만약 node 가 camera node 라면 modeling transformation 을 적용하는게 아니라 그 inverse 를 viewing transform 으로 적용 해야 함. inverse 를 위해서 path 를 거꾸로 따라감. patent pointer 를 활용.glLoadIdentity() 를 호출해서 modelview transform 가 identity 가 되게 함.modeling transformation 의 inverse 를 적용.viewing transformation 이 설립(?)modelview transformation 의 영향을 받음.