Graphics Basic Windows & OpenGL Programming 컴퓨터그래픽스연구실
OpenGL 관련참고사이트 OpenGL 공식사이트 http://www.opengl.org/ Khronos Group http://www.khronos.org/ Nehe Productions http://nehe.gamedev.net/
OpenGL 파일설정 압축을푼후다음경로로파일을복사 헤더파일 (glut.h) Microsoft Visual Studio\VC98\Include\GL (6.0) or Microsoft Visual Studio 8\VC\Include (8.0) 정적라이브러리파일 (glut32.lib & glut.def) Microsoft Visual Studio\VC98\Lib (6.0) or Microsoft Visual Studio 8\VC\Lib (8.0) 동적라이브러리파일 (glut32.dll) C:\WINDOWS\system32
프로젝트생성 [VS 6.0] (1/3) [File] [New] (Ctrl+N) [Win32 Console Application] 선택 Project Name 정한후 [OK] [An empty project] [Finish]
프로젝트생성 [VS 6.0] (2/3) [Project] [Settings ] (Alt+F7) Link 의 Object/library modules 에다음파일을추가 opengl32.lib glu32.lib glut32.lib glaux.lib
프로젝트생성 [VS 6.0] (3/3) [File] [New] (Ctrl+N) C++ Source File 선택 File 이름정한후 [OK] 완료
프로젝트생성 [VS 8.0] (1/3) [File] [New] [Project] (Ctrl+Shift+N) Visual C++ Win32 Win32 Console App 이름정한후 [OK] 빈프로젝트선택
프로젝트생성 [VS 8.0] (2/3) [Project] [ 속성 ] (Alt+F7) [ 구성속성 ] [ 링커 ] [ 입력 ] 추가종속성에다음파일을추가 opengl32.lib glu32.lib glut32.lib glaux.lib
프로젝트생성 [VS 8.0] (3/3) 소스파일선택후우클릭 새항목추가 코드 C++ 파일 (.cpp) 이름선택 추가 (A) 완료
Example 예제및실행결과
Viewing void glulookat GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble atx, GLdouble aty, GLdouble atz, GLdouble upx, GLdouble upy, GLdouble upz eyex, eyey, eyez : Camera Position(x,y,z) atx, aty, atz : Camera Focus(x,y,z) upx, upy, upz : Camera Up-vector Default glutlookat(0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);
Viewing void glulookat
View Volume void glortho GLdouble left, GLdouble right, GLdouble bottom, GLdouble top GLdouble znear, GLdouble zfar void glfrustum GLdouble left, GLdouble right, GLdouble bottom, GLdouble top GLdouble znear, GLdouble zfar void glperspective GLdouble fov, GLdouble aspect, GLdouble near, GLdouble fars fov : Field of View (degree : 0~180) aspect : Aspect Ratio (Width/Height) near : near clipping plane far : far clipping plane
View Volume void glfrustum
OpenGL 의그래픽기본요소 점 GL_POINTS 선 GL_LINES GL_LINE_STRIP GL_LINE_LOOP 도형 GL_POLYGON GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUAD_STRIP
OpenGL 의그래픽기본요소 점 (GL_POINTS) glbegin(gl_points); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); glend(); v1 v4 v2 v3
OpenGL 의그래픽기본요소 선 (GL_LINES) glbegin(gl_lines); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); glend(); v1 v4 v2 v3
OpenGL 의그래픽기본요소 선 (GL_LINE_STRIP) glbegin(gl_line_strip); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); glend(); v1 v4 v2 v3
OpenGL 의그래픽기본요소 도형 (GL_LINE_LOOP) glbegin(gl_line_loop); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); glend(); v1 v4 v2 v3
OpenGL 의그래픽기본요소 도형 (GL_TRIANGLES) glbegin(gl_triangles); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); glvertex3f(v3x, v3y, v3z); glend(); v1 v2 v3
OpenGL 의그래픽기본요소 도형 (GL_QUADS) glbegin(gl_quads); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); glend(); v1 v4 v2 v3
OpenGL 의그래픽기본요소 도형 (GL_POLYGON) glbegin(gl_polygon); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); glvertex3f(v5x, v5y, v5z); glvertex3f(v6x, v6y, v6z); glend(); v2 v1 v3 v6 v4 v5
OpenGL 의그래픽기본요소 도형 (GL_TRIANGLE_STRIP) glbegin(gl_triangle_strip); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); glvertex3f(v5x, v5y, v5z); glend(); v1 v2 v3 v4 v5
OpenGL 의그래픽기본요소 도형 (GL_TRIANGLE_FAN) glbegin(gl_triangle_fan); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); v5 v4 v3 glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); v2 glvertex3f(v5x, v5y, v5z); v1 glend();
OpenGL 의그래픽기본요소 도형 (GL_QUAD_STRIP) glbegin(gl_quad_strip); glvertex3f(v1x, v1y, v1z); glvertex3f(v2x, v2y, v2z); v1 v3 v5 glvertex3f(v3x, v3y, v3z); glvertex3f(v4x, v4y, v4z); glvertex3f(v5x, v5y, v5z); v2 v4 v6 glvertex3f(v6x, v6y, v6z); glend();
그래픽함수관련 ( 속성설정 ) glpointsize(glfloat size) 점의크기 gllinewidth(glfloat width) 선의두께 glgetfloatv(gl_line_size_range) 드라이버가지원하는최대선의두께를반환
그래픽함수관련 ( 속성설정 ) glshademodel(mode) 다각형내부채움모드설정 mode GL_FLAT : 다각형의내부를모두동일한색으로 GL_SMOOTH : 정점의색을 Weighted Average 보간 Gradation 기본값
Example
Example
Example
직교투영함수 Clipping glortho(gldouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); left : 클리핑공간좌측끝의좌표값 right : 클리핑공간우측끝의좌표값 bottom : 클리핑공간하단끝의좌표값 top : 클리핑공간상단끝의좌표값 near : 원점과관측자사이의최대거리 far : 원점과관측자의반대편사이의최대거리 ex) glmatrixmode(gl_projection); glloadidentity(); glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); // 투영좌표계설정 // 초기화
직교투영함수 glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); Projection glortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); Projection
직교투영함수 glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); => projection glortho(-3.0, 3.0, -3.0, 3.0, -1.0, 1.0); => projection
Viewport 함수 윈도우의영역을설정한다. glviewport(glint x, GLint y, GLsizei width, GLsizei height); x : 좌하단 x좌표 y : 좌하단 y좌표 width : 너비 height : 높이 Ex) glutinitwindowsize(200, 200); glviewport(0, 0, 100, 100); (0, 200) (0, 100) (0, 0) (100, 0) (200, 0)
Example