Open GL gl h glu h l include

  • Slides: 45
Download presentation

모든 Open. GL 함수의 프로토타입과 자료형, 매크로 등은 gl. h 라는 헤더 파일에 있다.

모든 Open. GL 함수의 프로토타입과 자료형, 매크로 등은 gl. h 라는 헤더 파일에 있다. 유틸리티 라이브러리는 glu. h 라는 파일에 있다. l #include <windows. h> l #include <glglu. h> GLUT 라이브러리 설치: glut 32. dll과 glut 32. lib GLUT 헤더 파일 설치: glut. h l C: Windowssystem 32 <= glut 32. dll l C: Program FilesMicrosoft Visual StudioVC 98lib <= glut 32. lib l C: Program FilesMicrosoft Visual StudioVC 98IncludeGL <= glut. h 2012 -2학기 Chapter 1 Open. GL 소개 5

프로그램 설치 비주얼 C++ GLUT 라이브러리: glutdlls 37 beta l http: //www. opengl. org/resources/libraries/glut/

프로그램 설치 비주얼 C++ GLUT 라이브러리: glutdlls 37 beta l http: //www. opengl. org/resources/libraries/glut/ GLUT 설치 l Visual Studio 6 l glut. h C: Program FilesMicrosoft Visual StudioVC 98IncludeGL l glut 32. lib C: Program FilesMicrosoft Visual StudioVC 98Lib l Glut 32. dll C: WindowsSystem 32 l Visual Studio 2005 l glut. h C: Program FilesMicrosoft Visual Studio 8VCPlatform. SDKIncludegl l glut 32. lib C: Program FilesMicrosoft Visual Studio 8VCPlatform. SDKLib l glut 32. dll C: WindowsSystem 32 2012 -2학기 가상현실 6

l l Visual Studio 2008 l glut. h C: Program FilesMicrosoft SDKsWindowsv 6. 0

l l Visual Studio 2008 l glut. h C: Program FilesMicrosoft SDKsWindowsv 6. 0 AIncludegl l glut 32. lib C: Program FilesMicrosoft SDKsWindowsv 6. 0 ALib Visual Studio 2010 2012 -2학기 가상현실 7

예제 소스 프로그램 http: //www. opengl. org/archives/resources/code/samples/redbo ok/ ftp: //ftp. sgi. com/opengl 14. zip

예제 소스 프로그램 http: //www. opengl. org/archives/resources/code/samples/redbo ok/ ftp: //ftp. sgi. com/opengl 14. zip GLUT 소스 코드나 최신 버전의 프로그램 및 예제 l http: //www. opengl. org/resources/libraries/glut/ 2012 -2학기 Chapter 1 Open. GL 소개 9

Open. GL 커맨드 문법 모든 Open. GL 커맨드 앞에는 gl이라는 접두사가 붙음 상수들은 “GL_”로

Open. GL 커맨드 문법 모든 Open. GL 커맨드 앞에는 gl이라는 접두사가 붙음 상수들은 “GL_”로 시작. 커맨드 접미사 - gl. Color 3 f() : f는 부동 소수점을 의미, 3은 함수 인자가 3개 접미사 데이터 타입 C언어 타입 Open. GL 타입정의 b 8비트 integer signed char GLlbyte s 16비트 integer Short GLshort i 32비트 integer int 또는 long GLint, GLsizei f 32비트 floating-point Float GLfloat, GLclampf d 64비트 floating-point double GLdouble, GLclampd ub 8비트 unsigned integer unsigned char GLbyte, GLboolean us 16비트 unsigned integer unsigned short GLushort ui 32비트 unsigned integer unsigned int 또는 unsigned long GLuint, GLenum, GLbitfield 2012 -2학기 Chapter 1 Open. GL 소개 14

Open. GL 렌더링 파이프라인 연산 순서 Pixel Data Vertex Data Display list Pixel Operations

Open. GL 렌더링 파이프라인 연산 순서 Pixel Data Vertex Data Display list Pixel Operations Evaluators Resterization Texture assembly Per-vertex Operations and Primitive assembly Per-fragment operations Fame. Buffer 2012 -2학기 Chapter 1 Open. GL 소개 18

GLX 루틴에 접근하려면 l #include < X 11/Xlib. h> l #include < GL/glx. h>

GLX 루틴에 접근하려면 l #include < X 11/Xlib. h> l #include < GL/glx. h> MS Windows에서 WGL 루틴에 접근하려면 l #include <windows. h> 윈도우 관리 태스크를 관리하기 위해 GLUT를 사용하려면 l #include <GL/glut. h> 표준 C 라이브러리 시스템 콜 사용 시 l #include <stdlib. h> l #include <stdio. h> 2012 -2학기 Chapter 1 Open. GL 소개 25

GLUT를 사용한 간단한 Open. GL 프로그램 #include <GL/glut. h> #include <stdlib. h> void display(void)

GLUT를 사용한 간단한 Open. GL 프로그램 #include <GL/glut. h> #include <stdlib. h> void display(void) { gl. Clear (GL_COLOR_BUFFER_BIT); /* 모든 픽셀을 지운다 */ /* (0. 25, 0. 0) 과 (0. 75, 0. 0)에 모서리를 둔 흰색 폴리곤을 그 린다*/ gl. Color 3 f (1. 0, 1. 0); gl. Begin(GL_POLYGON); gl. Vertex 3 f (0. 25, 0. 0); gl. Vertex 3 f (0. 75, 0. 25, 0. 0); 2012 -2학기 Chapter 1 Open. GL 소개 29

gl. Vertex 3 f (0. 75, 0. 0); gl. Vertex 3 f (0. 25,

gl. Vertex 3 f (0. 75, 0. 0); gl. Vertex 3 f (0. 25, 0. 75, 0. 0); gl. End(); gl. Flush (); /* 기다리지 않고, 버퍼에 저장된 Open. GL 루틴을 실행한다. */ } void init (void) { gl. Clear. Color (0. 0, 0. 0); /* 클리어 컬러를 선택한다 */ gl. Matrix. Mode(GL_PROJECTION); /* 뷰잉값을 초기화 한다 */ gl. Load. Identity(); gl. Ortho(0. 0, 1. 0, -1. 0, 1. 0); } 2012 -2학기 Chapter 1 Open. GL 소개 30

/* 초기 윈도우의 크기와 위치, 디스플레이 모드(싱글버퍼와 RGBA모드)를 설정한다. * 그리고 타이틀바에 “hello” 가

/* 초기 윈도우의 크기와 위치, 디스플레이 모드(싱글버퍼와 RGBA모드)를 설정한다. * 그리고 타이틀바에 “hello” 가 출력되는 윈도우를 연다. 초기화 루틴들을 실행시킨다 * 그래픽을 출력하도록 콜백 함수를 등록한다. *마지막으로, 메인 루프를 실행하고 이벤트를 처리한다. */ int main(int argc, char** argv) { glut. Init(&argc, argv); glut. Init. Display. Mode (GLUT_SINGLE | GLUT_RGB); glut. Init. Window. Size (250, 250); glut. Init. Window. Position (100, 100); glut. Create. Window ("hello"); init (); glut. Display. Func(display); glut. Main. Loop(); return 0; } 2012 -2학기 Chapter 1 Open. GL 소개 31

이러한 오브젝트들은 와이어프레임 방식으로 그리거나, 표면 법선 을 정의하여 솔리드 쉐이딩된 형태로 그릴 수

이러한 오브젝트들은 와이어프레임 방식으로 그리거나, 표면 법선 을 정의하여 솔리드 쉐이딩된 형태로 그릴 수 있다. 정육면체와 구를 그리기 위한 루틴들로 다음과 같은 것들이 제공 l l void glut. Wire. Cube(GLdouble size); void glut. Solid. Cube(GLdouble size); void glut. Wire. Sphere(GLdouble radius, GLint slices, GLint stacks); void glut. Solid. Sphere(GLdouble radius, GLint slices, GLint stacks); GLUT 참고 l http: //www. opengl. org/resources/libraries/glut/spec 3. html 2012 -2학기 Chapter 1 Open. GL 소개 35

애니메이션 원리 open_window(); for (i = 0; i < 1000000; i++) { clear_the_window(); draw_frame(I);

애니메이션 원리 open_window(); for (i = 0; i < 1000000; i++) { clear_the_window(); draw_frame(I); wait_until_a_24 th_of_a_second_is_over(); } 더블버퍼링을 사용한 부드러운 애니메이션 open_window_in_double_buffer_mode(); for (i = 0; i < 1000000; i++) { clear_the_window(); draw_frame(i); swap_the_buffers(); } 2012 -2학기 Chapter 1 Open. GL 소개 36

더블버퍼링을 사용한 프로그램 glut. Swap. Buffers()를 사용하는 방법을 보여주고 있다. 마우스 버튼 을 이용하여

더블버퍼링을 사용한 프로그램 glut. Swap. Buffers()를 사용하는 방법을 보여주고 있다. 마우스 버튼 을 이용하여 회전을 켜고 끄도록 하였다. #include <GL/glut. h> #include <stdlib. h> static GLfloat spin = 0. 0; void init(void) { gl. Clear. Color (0. 0, 0. 0); gl. Shade. Model (GL_FLAT); } 2012 -2학기 Chapter 1 Open. GL 소개 39

void display(void){ gl. Clear(GL_COLOR_BUFFER_BIT); gl. Push. Matrix(); gl. Rotatef(spin, 0. 0, 1. 0); gl.

void display(void){ gl. Clear(GL_COLOR_BUFFER_BIT); gl. Push. Matrix(); gl. Rotatef(spin, 0. 0, 1. 0); gl. Color 3 f(1. 0, 1. 0); gl. Rectf(-25. 0, 25. 0); gl. Pop. Matrix(); glut. Swap. Buffers(); } 2012 -2학기 Chapter 1 Open. GL 소개 40

void spin. Display(void) { spin = spin + 2. 0; if (spin > 360.

void spin. Display(void) { spin = spin + 2. 0; if (spin > 360. 0) spin = spin - 360. 0; glut. Post. Redisplay(); } void reshape(int w, int h) { gl. Viewport (0, 0, (GLsizei) w, (GLsizei) h); gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); gl. Ortho(-50. 0, -1. 0, 1. 0); gl. Matrix. Mode(GL_MODELVIEW); gl. Load. Identity(); } 2012 -2학기 Chapter 1 Open. GL 소개 41

void mouse(int button, int state, int x, int y) { switch (button) { case

void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) glut. Idle. Func(spin. Display); break; case GLUT_MIDDLE_BUTTON: case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) glut. Idle. Func(NULL); break; default: break; } } 2012 -2학기 Chapter 1 Open. GL 소개 42

/* 더블 버퍼 디스플레이 모드를 요청하고, 마우스 입력 콜백 함수를 등록 */ int main(int

/* 더블 버퍼 디스플레이 모드를 요청하고, 마우스 입력 콜백 함수를 등록 */ int main(int argc, char** argv) { glut. Init(&argc, argv); glut. Init. Display. Mode (GLUT_DOUBLE | GLUT_RGB); glut. Init. Window. Size (250, 250); glut. Init. Window. Position (100, 100); glut. Create. Window (argv[0]); init (); glut. Display. Func(display); glut. Reshape. Func(reshape); glut. Mouse. Func(mouse); glut. Main. Loop(); return 0; /* ANSI C requires main to return int. */ } 2012 -2학기 Chapter 1 Open. GL 소개 43

Nate Robins 의 Open. GL 튜토리얼 http: //www. xmission. com/~nate/tutors. html 2012 -2학기 Chapter

Nate Robins 의 Open. GL 튜토리얼 http: //www. xmission. com/~nate/tutors. html 2012 -2학기 Chapter 1 Open. GL 소개 45