Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sang Il Park Sejong University

Similar presentations


Presentation on theme: "Sang Il Park Sejong University"— Presentation transcript:

1 Sang Il Park Sejong University
Starting OpenGL Sang Il Park Sejong University Most of the slides are taken from Jehee Lee’s

2 Graphics Rendering Pipeline
Rendering: the conversion of a scene into an image Scene is composed of “models” in 3D space. Models are composed of “primitives” supported by graphics packages such as OpenGL. Models entered by hand or created by a program 3D Scene render 2D Image

3 Functions of a Graphic Package
Graphics Library such as Core, OpenGL, DirectX Provide primitives for graphic description Build and maintain graphic representation models Provide primitives for viewing operations Support user interaction with application program Interact directly with users to allow them modify viewing parameters, if possible

4 Graphics API 응용프로그램 인터페이스 라이브러리
API (Application Programming Interface)

5 General Graphics Packages
Graphics packages are device-independent Official Standards GKS : ANSI85, 2D, Europe GKS-3D : ANSI88 PHIGS : ANSI88 - Hierarchical structures PHIGS+ : ISO 92 Non-official Standards Silicon Graphics OpenGL (1992) Open Inventor Microsoft DirectX Sun Mircorsystems VRML

6 Graphics API 발전과정

7 OpenGL 저수준 API 장면을 묘사하는 것이 아니라 구체적 프러시져를 호출 cf. DirectX from Microsoft: 호환성 결여 하드웨어와 거의 직접 연관 (하드웨어 성능을 최대한 발휘) Inventor, VRML, Java3D 등은 고수준 API의 기반

8 오픈지엘 명령어 구조 명령어(함수)의 이름 규칙: 예제: float: C/C++ 타입, GLfloat: GL 타입 gl
명령이름 매개변수 개수 매개변수 형식

9 오픈지엘 명령어 구조 벡터 타입: 지엘은 API 지엘은 비 객체지향적 명령어가 아니라 함수명. 그러나 혼용 처리속도를 향상
함수 오버로딩이 불가능 3차원 정점이라면 glVertex3f( ), 2차원 정점이라면 glVertex2f( )

10 OpenGL 프로그램 구성요소 GL: OpenGL Core Library GLU: OpenGL Utility Library
렌더링 기능을 제공하는 함수 라이브러리 GLU: OpenGL Utility Library 50여개의 함수. GL 라이브러리의 도우미 다각형 분할, 투상, 2차원 곡면, NURBS 등 고급기능을 제공하는 함수 GL 함수로 작성 GLUT: OpenGL Utility Toolkit 사용자 입력을 받아들이거나 화면 윈도우를 제어하기 위한 함수 윈도우 운영체제 기능과의 인터페이스

11 GLUT 윈도우 기능: 프로그램 실행에 필요한 창(Window)을 관리 콜백 기능: 프로그램 실행 중 발생하는 사용자 입력을 처리

12 GLUT의 CALLBACK 타입별 콜백함수

13 GLUT의 CALLBACK 아이들(idle) 콜백 큐에 이벤트가 없을 때 실행 정의되어 있지 않으면 운영체제는 다른 일을 수행
드라이버를 통해 주기적으로 이벤트 검사

14 OpenGL/GLUT 설치와 설정 참고자료:
GLUT Tutorial page:

15 Visual Studio 2005에서의 세팅 필요 파일 세팅 : 필요파일받기
에서 glut bin.zip 을 다운로드 함 압축을 풀고, glut.h, glut32.lib, glut32.dll 이 있음을 확인

16 Visual Studio 2005에서의 세팅 필요 파일 세팅1 : 헤더 파일 세팅
헤더파일(glut.h)을 아래 폴더에 복사 C:\Program Files\Microsoft Visual Studio 8 \VC\PlatformSDK\Include\GL

17 Visual Studio 2005에서의 세팅 필요 파일 세팅2 : 정적라이브러리(lib) 파일 세팅
라이브러리파일(glut32.lib)를 아래 폴더에 복사 c:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib

18 Visual Studio 2005에서의 세팅 필요 파일 세팅3 : 동적라이브러리(dll) 파일 세팅
라이브러리파일(glut32.dll)을 아래 폴더에 복사 c:\WINDOWS\system32

19 Visual Studio 2005에서의 세팅 프로젝트 새로 만들기: Win32 콘솔 응용프로그램

20 Visual Studio 2005에서의 세팅 프로젝트 새로 만들기: Win32 콘솔 응용프로그램 세팅 시 “빈 프로젝트” 선택!

21 Visual Studio 2005에서의 세팅 프로젝트 새로 만들기: Win32 콘솔 응용프로그램 세팅 시 “빈 프로젝트” 선택!

22 Visual Studio 2005에서의 세팅 프로젝트 Link Setting: 추가종속성에 opengl32.lib glu32.lib glut32.lib 추가

23 Visual Studio 2005에서의 세팅 Source code 추가: 프로젝트>새항목추가>코드>C++ File(.cpp) 추가

24 Test Code: 창띄우기 #include <GL/glut.h> void MyDisplay (void) { }
void main () glutInitWindowPosition (50, 100); glutInitWindowSize (400, 300); glutCreateWindow ("My First OpenGL"); glutDisplayFunc (MyDisplay); glutMainLoop ( );

25 GLUT 윈도우 제어

26 Viewport 뷰포트(Viewport): 창 내에서 OpenGL이 그림을 그리는 영역 glViewport로 설정 가능
뷰포트 미 설정시 기본값으로 윈도우 = 뷰포트 윈도우 크기조절에 따라 뷰포트 내부 그림도 자동으로 크기조절 그림을 그리는 좌표계와 종횡비가 다를 경우 왜곡이 생길 수 있음 왜곡 Viewport가 네개인 예

27 Test Code: 화면지우기 #include <GL/glut.h> void myDisplay (void) {
glClear (GL_COLOR_BUFFER_BIT); glFlush ( ); } void main () glutInitWindowPosition (50, 100); glutInitWindowSize (400, 300); glutCreateWindow ("My First OpenGL"); glutDisplayFunc (myDisplay); glutMainLoop ( );

28 Test Code: 초기값 설정1 #include <GL/glut.h> void initialize (void) {
glClearColor (1.0f,1.0f,1.0f,0.0f); } void myDisplay (void) glClear (GL_COLOR_BUFFER_BIT); glFlush ( ); void main () glutInitWindowPosition (50, 100); glutInitWindowSize (400, 300); glutCreateWindow ("My First OpenGL"); initialize(); glutDisplayFunc (myDisplay); glutMainLoop ( );

29 상태변수 오픈지엘의 역할 = Rendering 시의 상태변수 설정 렌더링은 상태변수를 참조하며 실행됨

30 상태변수란? 파라미터 리스트 시스템 테이블 “현 상태” 라는 개념
drawLine((1, 0), (3, 0), 3, 4, (255, 0, 0)); drawLine((3, 0), (2, 5), 3, 4, (255, 0, 0)); drawLine((2, 5), (1, 0), 3, 4, (255, 0, 0)); 시스템 테이블 setLineStyle(2); setLineWidth(4); setLineColor(255, 0, 0); drawLine((1, 0), (3, 0)); drawLine((3, 0), (2, 5)); drawLine((2, 5), (1, 0)); “현 상태” 라는 개념 Current State

31 실제 OpenGL의 경우

32 상태변수 예 상태변수 설정 상태변수 검색 기능관련 상태변수 glColor3f(1.0, 1.0, 1.0);
GL_CURRENT_COLOR 상태변수 값을 (1.0, 1.0, 1.0)으로 설정 다른 명령에 의해 값이 바뀔 때까지 모든 물체를 그릴 때 유효함. glPointSize(0.5); glLineWidth(5); glShadeModel(GL_SMOOTH); 상태변수 검색 float MyColor[3];                                   임의 배열 glGetFloatv(GL_CURRENT_COLOR, MyColor);     검색 함수 기능관련 상태변수 glEnable(GL_LIGHTING);              조명 모드를 활성화 glDisable(GL_LIGHTING);             조명 모드를 비활성화

33 Test Code: 초기값 설정2 좌표계 설정 : gluOrtho2D ( left, right, bottom, top)
void initialize (void) { glClearColor (1.0f,1.0f,1.0f,0.0f); glMatrixMode (GL_PROJECTION); gluOrtho2D (0.0, 200.0, 0.0, 150.0); } 좌표계 설정 : gluOrtho2D ( left, right, bottom, top) (Left, Top) (Right, Top) y (Left, Bottom) (Right, Bottom) x

34 Test Code: 라인그리기 void myDisplay (void) {
glClear (GL_COLOR_BUFFER_BIT); glColor3f (0.0, 0.0, 1.0); glBegin (GL_LINES); glVertex2i (180, 15); glVertex2i (10, 145); glEnd ( ); glFlush (); }

35 GLUT 윈도우 기능: 프로그램 실행에 필요한 창(Window)을 관리 콜백 기능: 프로그램 실행 중 발생하는 사용자 입력을 처리

36 GLUT의 CALLBACK 타입별 콜백함수

37 GLUT의 CALLBACK 아이들(idle) 콜백 큐에 이벤트가 없을 때 실행 정의되어 있지 않으면 운영체제는 다른 일을 수행
드라이버를 통해 주기적으로 이벤트 검사

38 정리 OpenGL: Graphics API GLUT: OpenGL Utility Toolkit
그래픽스 하드웨어를 다루는 핵심 library로 구성 GLUT: OpenGL Utility Toolkit OpenGL을 보다 쉽게 사용할 수 있기 위한 여러 툴 제공 Windows 제어 사용자 Interaction을 위한 Callback 함수 기능 OpenGL과 GLUT의 명령어는 기계독립적 똑같은 source code를 사용해 Unix, Windows, Mac에서 동작 시킬 수 있다


Download ppt "Sang Il Park Sejong University"

Similar presentations


Ads by Google