hallym university gve lab. 1 graphics and virtual environment laboratory 8 color and shading...

22
Hallym University GVE Hallym University GVE LAB. LAB. 1 Graphics and Virtual Environment Laboratory Graphics and Virtual Environment Laboratory 8 8 COLOR AND SHADING COLOR AND SHADING Palettes Palettes 를 를를를를 를 를를를를

Upload: cecil-fox

Post on 19-Jan-2016

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

1 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

88COLOR AND SHADINGCOLOR AND SHADING

PalettesPalettes 를 중심으로 를 중심으로

Page 2: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

2 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows Palettes

The TRIANGLE and CCUBE example program work reasonably

well regardless of how many colors are available.

그러나 더 높은 depth color 를 사용하는 경우 훨씬 매끄러운

이미지를 만들어 낸다 .

예 ) 그림 8-12a (16 색 ) 와 그림 8-12b(1,600 만개색 )

Page 3: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

3 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows PalettesColor Matching

Windows passes the 24-bit color value to the display driver which

converts the color to a 15- or 16-bit color value before dispalying it.

Page 4: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

4 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows Palettes

Dithering

Color Approximation (dithering) : 4 bit color modes 의 경우 When you specify a color to use for drawing operations using glColor3ub,

- The nearest color of the 16 available to fulfill the request.

- For filling operation, dithering is used.

Page 5: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

5 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows PalettesDithering :

A means of placing different colors close together to produce the

illusion of another composite color.

Ex) If you place yellow and blue squares together in a checkboard

pattern, the pattern will take on a greenish appearance.

glEnable(GL_DITHER)

DITHER.EXE

8 비트 이상 모드에서는 효과가 거의 없다 .

Page 6: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

6 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows Palettes2 가지 경우 :

• Colors are evenly distributed across RGB color space

• Colors are selected to produce smooth shading of a surface

• 바다 , the image of a pipe’s cross section

• Near photographic quality

Palette Arbitration

CreatePalette() : create palette

hPalette : a handle of type HPALETTE

Page 7: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

7 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows PalettesSystem Palette vs Private Palette( 해당 프로그램에서 사용하는 팔레트 ):

All applications must share the same system palette.

WM_QUERYNEWPALETTE :

- When application receives keyboard or mouse input focus.

WM_PALETTECHANGED : This message is sent to window that can

realize their palette but may not have the current focus.

RealizePalette() :

Application copies the palette entries from the private palette to

the system palette.

팔레트를 Realize 한다는 것은 프로그램이 private palette 를 system palette 로

복사하는 것을 의미한다 .

Page 8: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

8 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows Palettes// Windows is telling the application that it may modify// the system palette. This message in essance asks the // application for a new palette.

case WM_QUERYNEWPALETTE:// If the palette was created.if(hPalette)

{int nRet;// Selects the palette into the current device contextSelectPalette(hDC, hPalette, FALSE);// Map entries from the currently selected palette to// the system palette. The return value is the number // of palette entries modified.nRet = RealizePalette(hDC);// Repaint, forces remap of palette in current windowInvalidateRect(hWnd,NULL,FALSE);return nRet;}

break;

Page 9: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

9 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows Palettes // This window may set the palette, even though it is not the // currently active window. case WM_PALETTECHANGED:

// Don't do anything if the palette does not exist, or if// this is the window that changed the palette.if((hPalette != NULL) && ((HWND)wParam != hWnd))

{// Select the palette into the device contextSelectPalette(hDC,hPalette,FALSE);

// Map entries to system paletteRealizePalette(hDC);

// Remap the current colors to the newly realized paletteUpdateColors(hDC);return 0;}

break;

Contains the current window handle

receiving message

Page 10: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

10 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Creating PalettesCreating Palettes

case WM_CREATE:// Store the device contexthDC = GetDC(hWnd);

// Select the pixel formatSetDCPixelFormat(hDC); // 팔레트 만들기hPalette = GetOpenGLPalette(hDC);

// Create the rendering context and make it currenthRC = wglCreateContext(hDC);wglMakeCurrent(hDC, hRC);

break;

Do You Need a Palette?

Page 11: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

11 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Creating PalettesCreating Palettes HPALETTE GetOpenGLPalette(HDC hDC)

{HPALETTE hRetPal = NULL; // Handle to palette to be createdPIXELFORMATDESCRIPTOR pfd; // Pixel Format DescriptorLOGPALETTE *pPal; // Pointer to memory for logical paletteint nPixelFormat; // Pixel format indexint nColors; // Number of entries in paletteint i; // Counting variableBYTE RedRange,GreenRange,BlueRange; // Range for each color entry (7,7,and 3)

// Get the pixel format index and retrieve the pixel format descriptionnPixelFormat = GetPixelFormat(hDC);DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

// Does this pixel format require a palette? If not, do not create a// palette and just return NULLif(!(pfd.dwFlags & PFD_NEED_PALETTE))

return NULL;

Page 12: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

12 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

The Palette’s StructureThe Palette’s Structure

typedef struct tagLOGPALETTE { WORD palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE;

LOGPALETTE *pPal;…..

pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + ncolors * sizeof(PALETTEENTRY));

Page 13: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

13 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

The 3-3-2 PaletteThe 3-3-2 Palette

7 6 5 4 3 2 1 0 8-bit Palette Index

Blueintensity

Greenintensity

Redintensity

Function to Create a palette for OpenGL Device context

Page 14: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

14 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

The 3-3-2 PalettesThe 3-3-2 Palettes

PaletteEntry

Binary(B G R)

Blue Comp GreenComp

RedComp

0 00 000 000 0 0 01 00 000 001 0 0 1*255/7

2 00 000 010 0 0 2*255/7

3 00 000 011 0 0 3*255/7

9 00 001 001 0 1*255/7 1*255/7

10 00 001 010 0 1*255/7 2*255/7

137 10 001 001 2*255/3 1*255/7 1*255/7

138 10 001 010 2*255/3 1*255/7 2*255/7

255 11 111 111 3*255/3 7*255/7 7*255/7

Page 15: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

15 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Building the Palettes (Building the Palettes ( 팔레트 생성팔레트 생성 ))

Function to create a palette for OpenGL

case WM_CREATE:// Store the device contexthDC = GetDC(hWnd); // Select the pixel formatSetDCPixelFormat(hDC); // 팔레트 만들기hPalette = GetOpenGLPalette(hDC);// Create the rendering context and make

it currenthRC = wglCreateContext(hDC);wglMakeCurrent(hDC, hRC);break;

Page 16: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

16 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Palette Disposal

// Window is being destroyed, cleanupcase WM_DESTROY:

// Deselect the current rendering context and delete itwglMakeCurrent(hDC,NULL);wglDeleteContext(hRC);if(hPalette != NULL)

DeleteObject(hPalette);// Tell the application to terminate after the window// is gone.PostQuitMessage(0);break;

Page 17: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

17 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows PalettesColor Index Mode

Why Use Color Index Mode?Why Use Color Index Mode?

• Palette animation without palette H/W• 팔레트의 원소를 바꾸므로써 , 화면의 색을 변화시킴 .

• Overcome your color choice Limits on the 3-3-2 palette system - Support really smooth shading on an 8-bit display • somewhat faster in 8-bit color modes

• 컬러들이 저장된 배열의 인덱스를 사용해서 특정 색을 지정 .

Page 18: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

18 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Windows PalettesWindows PalettesColor Index Mode

Using Color Index ModeUsing Color Index Mode

• void glIndex(GLint c)void glIndex(GLint c)

Disadvantage• limiting color selection (MS 의 경우는 256 개 색만지원 )• does not support some of OpenGL’s other effects

- lighting, shading, fog, anti-aliasing, alpha blending

Page 19: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

19 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Using Color Index ModeUsing Color Index Mode

Index.exe

List 8-6. Index.c 의 GetRedPalette 함수

다양한 명암의 빬간색으로만 구성된 팔레트를 만드는 코드

( 참고 ) Color Index Mode 를 사용하려면 , PIXELFORMATDESCRIPTOR 의 iPixeType 을 PFD_TYPE_COLORINDEX 로 설정하여야 한다 .

Page 20: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

20 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

Using Color Index ModeUsing Color Index Mode

List 8-6. Index.c 의 RenderScene 함수

삼각형의 꼭지점은 밝기가 0( 검은색 ) 인 가장 어두운 색으로 설정함 . 나머지 두 꼭지점은 가장 밝은 빨간색(Index 255) 을 사용함 .

부드럽게 Shading 된 삼각형 (3-3-2 팔레트에서는 불가능 )

Page 21: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

21 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

SummarySummary

• Color, RGB 요소를 사용하여 색 지정 . RGB color cube

• glColor() 의 사용법

• Coloring, Shading, Dithering, Index, Masking

• 3-3-2 팔레트 구성

(8-bit mode 에서 OpenGL 을 사용하는 경우 )

Page 22: Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로

Hallym University GVE LAB.Hallym University GVE LAB.

22 Graphics and Virtual Environment LaboratoryGraphics and Virtual Environment Laboratory

88COLOR AND SHADINGCOLOR AND SHADING

THE END