Download presentation
Presentation is loading. Please wait.
Published byGeorgia Blake Modified 6년 전
1
OpenGL Programming (III) 1. Drawing in 3D 2. Manipulating 3D Space
컴퓨터 그래픽스 담당교수 : 김 창 헌
2
GLUT Library Sample Code GLUT32.LIB/DLL OPENGL32.LIB, GLU32.LIB
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("sphere"); glutDisplayFunc(display); gfxinit(); glutMainLoop();
3
GLUT Multiple windows for OpenGL rendering.
Callback driven event processing. A simple pop-up menu facility. Miscellaneous window management functions. The X Journal available in PostScript
4
CALLBACK 함수 지정 GLUT Function
키보드 함수 glutKeyboardFunc(..) 마우스 함수 Main 함수 시각화 함수 glutDisplayFunc(..) 메뉴 함수
5
CALLBACK 함수 glutMouseFunc(mouse); glutDisplayFunc(display);
void mouse(int btn, int state, int x, int y) { printf("button %d is %s at (%d,%d)", btn, state == GLUT_DOWN ? "down" : "up", x, y); } glutDisplayFunc(display); void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCallList(1); /* render sphere display list */ glutSwapBuffers(); }
6
Drawing in 3D : Lines, Points
색깔 선 그리기 Line Strip Line Loop Line Stipple
7
Drawing in 3D : Polygon SetupRC RenderScene ( display )
glShadeModel(GL_FLAT); glFrontFace(GL_CW); RenderScene ( display ) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glEnable(GL_CULL_FACE ) glEnable(GL_DEPTH_TEST);
8
Hidden Surface Removal
Depth Test viewing plane 을 기준으로 한 3차원 물체의 깊이 test 보이지 않는 부분 제거 관련 Code glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
9
Back Face Culling 육면체로 된 방 내부 Back Face Culling
뒷면 제거 Polygon의 생성방향 설정 필요 glFrontFace(GL_CCW);
10
Manipulation 3D Space : Coordinate Transformation
Transformation Pipeline Original Vertex Data Transformed eye coordinate Clip coordinate Normalized device coordinate Window coordinate
11
Model View Object의 rotation, translation, scaling
viewing transformation 포함 ( duality ) 입력 : 3차원 좌표값 ( world coordinate) 결과 : viewpoint 기준의 좌표값 ( eye coordinate ) glLoadIdentity( ); glPushMatrix(); glPopMatrix();
12
Projection Orthographic Projection Perspective Projection
gluPerspective( fovy, aspect, zNear, zFar ); Perspective viewing volume w Observer h fovy near far
Similar presentations