gve, hallym university, song, chang geun, ph.d. 컴퓨터 그래픽스 응용 한림대학교...
TRANSCRIPT
GVE, Hallym University, Song, Chang Geun, Ph.D.
컴퓨터 그래픽스 응용
한림대학교 컴퓨터공학부송 창근
GVE, Hallym University, Song, Chang Geun, Ph.D.
Chap 1. What is OpenGL?
한림대학교컴퓨터 공학부
송 창근
GVE, Hallym University, Song, Chang Geun, Ph.D.
What is OpenGL?
1) OpenGL
• a software interface to graphics hardware
• 3D graphics and modeling library
• extremely portable and very fast
• developed and optimized by SGI (Silicon Graphics, Inc.)
2) Windows Graphics APIs
• GDI(Graphics Device Interface) : H/W independent graphics
• WinG : functions that got bitmaps to display much faster, but still slow
• Direct Draw DirectX
GVE, Hallym University, Song, Chang Geun, Ph.D.
A History of OpenGL
(1) GL or IRIS GL
• Silicon Graphics.
• 3D programming API for high-end IRIS graphics workstation
• 특별한 하드웨어를 가정하여 개발되었으므로 , 다른 platform 에는 적당하지 않음
(2) OpenGL
• to improve IRIS GL’s portability
• Version 1.0 ( July 1, 1992 )
• SGI and Microsoft were working together to bring OpenGL to Windows NT
• OpenGL Architecture Review Board (ARB) : SGI, DEC, IBM, Intel, Microsoft
• 2 times per year
• newsgroup : comp.graphics.api.openg
• Version 1.1 (Dec. 1995)
GVE, Hallym University, Song, Chang Geun, Ph.D.
How OpenGL works• Procedural
• 120 commands and functions :
• draw graphics primitives (points, lines, polygons)
• support lighting, shading, texture mapping, animation, and other special effects
• Does not include any functions for
• window management, user interaction, or file I/O
OpenGL under Windows• Windows NT 3.5
• A set of DLLs was made available to add support for OpenGL to Windows 95
• “wiggle” functions : the glue that enables the OpenGL to work with GDI.
GVE, Hallym University, Song, Chang Geun, Ph.D.
GVE, Hallym University, Song, Chang Geun, Ph.D.
Graphics Architecture: Software versus HardwareGDI device context ( pen, brush, font, other GDI objects)
OpenGL rendering context
GDI, Direct Draw and OpenGL(1) GDI calls -> ( WINSRV.DLL) -> Win 32 Device Driver Interface(DDI)
-> Graphics Card Device Driver
(2) Direct Draw calls -> Graphics hardware
: used for games and animation. It bypasses the GDI.
(3) OpenGL calls -> 3DDI -> Graphics Card Device Driver
Limitations - No printing to a monochrome or less than 16-color printer
- No stereoscopic images, auxiliary buffers, and alpha bit planes
GVE, Hallym University, Song, Chang Geun, Ph.D.
Windows Programming
GVE, Hallym University, Song, Chang Geun, Ph.D.
( 예 1) 가장 간단한 윈도우 프로그램
#include <windows.h>int WINAPI WinMain(HINSTANCE d1, HINSTANCE d2, LPSTR d3, int d4){ MessageBox(NULL, "Hello, World!", "", MB_OK);}
GVE, Hallym University, Song, Chang Geun, Ph.D.
GVE, Hallym University, Song, Chang Geun, Ph.D.
( 예 2) 메시지 루프 (Message Loop) 와 윈도우 핸들 용어 : Message loop, Message Queue
GetMessage : 메시지가 WM_QUIT 이면 False, 그렇치 않으면 TRUE
DestroyWindow : 응용 프로그램의 윈도우가 파괴 , WM_DESTROY 생성
PostQuitMessage : WM_QUIT message 를 post 함 .
DispatchMessage : Default Window procedure 로 메시지가 전달됨 .
GVE, Hallym University, Song, Chang Geun, Ph.D.
WM_LBUTTONDOWNWM_PAINTWM_LBUTTONUPWM_PAINTWM_WINDOWPOSCHANGINGWM_WINDOWPOSCHANGEDWM_NCACTIVATEWM_KILLFOCUSWM_DESTROYWM_NCDISTROY
Message Type 들
GVE, Hallym University, Song, Chang Geun, Ph.D.
#include <windows.h>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE d2, LPSTR d3, int d4){ MSG msg; HWND hwnd; hwnd = CreateWindow("BUTTON", "Hello, World!", WS_VISIBLE | BS_CENTER, 100, 100, 100, 80, NULL, NULL, hInstance, NULL); while (GetMessage(&msg, NULL, 0, 0)) { if (msg.message == WM_LBUTTONUP) { DestroyWindow(hwnd); PostQuitMessage(0); } DispatchMessage(&msg); } return msg.wParam;}
( 예 2) “ Hello, World 95!” 프로그램 .
GVE, Hallym University, Song, Chang Geun, Ph.D.
( 예 3) "Hello, Window 95!" 프로그램 .
1) Windows Function Calls
LoadIcon, LoadCursor, GetStockObject RegisterClassEx, CreateWindow ShowWindow, UpdateWindow GetMessage, TranslateMessage DispatchMessage, PlaySound BeginPaint, GetClientRect DrawText, EndPaint PostQuitMessage, DefWindowProc.
GVE, Hallym University, Song, Chang Geun, Ph.D.
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ;
switch (iMsg) { case WM_CREATE : PlaySound ("hellowin.wav", NULL, SND_FILENAME | SND_ASYNC) ; return 0 ;
case WM_PAINT : hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, "Hello, Windows 95!", -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ;
case WM_DESTROY : PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
GVE, Hallym University, Song, Chang Geun, Ph.D.
Example 1: “Hello Windows 95”
GVE, Hallym University, Song, Chang Geun, Ph.D.
void DrawBezier (HDC hdc, POINT apt[]) { PolyBezier (hdc, apt, 4) ; MoveToEx (hdc, apt[0].x, apt[0].y, NULL) ; LineTo (hdc, apt[1].x, apt[1].y) ;
MoveToEx (hdc, apt[2].x, apt[2].y, NULL) ; LineTo (hdc, apt[3].x, apt[3].y) ; }
2. Bezier Splines
GVE, Hallym University, Song, Chang Geun, Ph.D.
case WM_MOUSEMOVE: if (wParam & MK_LBUTTON || wParam & MK_RBUTTON) { hdc = GetDC (hwnd) ; SelectObject (hdc, GetStockObject (WHITE_PEN)) ; DrawBezier (hdc, apt) ; if (wParam & MK_LBUTTON) { apt[1].x = LOWORD (lParam) ; apt[1].y = HIWORD (lParam) ; } if (wParam & MK_RBUTTON) { apt[2].x = LOWORD (lParam) ; apt[2].y = HIWORD (lParam) ; } SelectObject (hdc, GetStockObject (BLACK_PEN)) ; DrawBezier (hdc, apt) ; ReleaseDC (hwnd, hdc) ; } return 0 ;
GVE, Hallym University, Song, Chang Geun, Ph.D.
Example 2: Bezier Curve 그리기
GVE, Hallym University, Song, Chang Geun, Ph.D.
OpenGL 프로그램의 예
The bouncing square ( Window Version)
GVE, Hallym University, Song, Chang Geun, Ph.D.
// Called by AUX library to draw scene void RenderScene(void)
{// Set background clearing color to blueglClearColor(0.0f, 0.0f, 1.0f, 1.0f);
// Clear the window with current clearing colorglClear(GL_COLOR_BUFFER_BIT);
// Set drawing color to Red, and draw rectangle // at current position.
glColor3f(1.0f, 0.0f, 0.0f);glRectf(x1, y1, x1+rsize, y1+rsize);
glFlush();}
GVE, Hallym University, Song, Chang Geun, Ph.D.
// The painting function. This message sent by // Windows whenever the screen needs updating.
case WM_PAINT:{// Call OpenGL drawing codeRenderScene();
// Call function to swap the buffersSwapBuffers(hDC);
// Validate the newly painted client areaValidateRect(hWnd,NULL);}break;
GVE, Hallym University, Song, Chang Geun, Ph.D.
Example 3: Bouncing square