Download presentation
Presentation is loading. Please wait.
Published byCecil Fox Modified over 9 years ago
1
Hallym University GVE LAB. 1 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING Palettes 를 중심으로 8 COLOR AND SHADING Palettes 를 중심으로
2
Hallym University GVE LAB. 2 Graphics and Virtual Environment Laboratory Windows 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 만개색 )
3
Hallym University GVE LAB. 3 Graphics and Virtual Environment Laboratory Windows Palettes Color 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.
4
Hallym University GVE LAB. 4 Graphics and Virtual Environment Laboratory Windows 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.
5
Hallym University GVE LAB. 5 Graphics and Virtual Environment Laboratory Windows Palettes Dithering : 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 비트 이상 모드에서는 효과가 거의 없다.
6
Hallym University GVE LAB. 6 Graphics and Virtual Environment Laboratory Windows Palettes 2 가지 경우 : 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
7
Hallym University GVE LAB. 7 Graphics and Virtual Environment Laboratory Windows Palettes System 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 로 복사하는 것을 의미한다.
8
Hallym University GVE LAB. 8 Graphics and Virtual Environment Laboratory Windows 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 context SelectPalette(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 window InvalidateRect(hWnd,NULL,FALSE); return nRet; } break;
9
Hallym University GVE LAB. 9 Graphics and Virtual Environment Laboratory Windows 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 context SelectPalette(hDC,hPalette,FALSE); // Map entries to system palette RealizePalette(hDC); // Remap the current colors to the newly realized palette UpdateColors(hDC); return 0; } break; Contains the current window handle receiving message
10
Hallym University GVE LAB. 10 Graphics and Virtual Environment Laboratory Creating Palettes case WM_CREATE: // Store the device context hDC = GetDC(hWnd); // Select the pixel format SetDCPixelFormat(hDC); // 팔레트 만들기 hPalette = GetOpenGLPalette(hDC); // Create the rendering context and make it current hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); break; Do You Need a Palette?
11
Hallym University GVE LAB. 11 Graphics and Virtual Environment Laboratory Creating Palettes HPALETTE GetOpenGLPalette(HDC hDC) { HPALETTE hRetPal = NULL;// Handle to palette to be created PIXELFORMATDESCRIPTOR pfd;// Pixel Format Descriptor LOGPALETTE *pPal;// Pointer to memory for logical palette int nPixelFormat;// Pixel format index int nColors;// Number of entries in palette int i;// Counting variable BYTE RedRange,GreenRange,BlueRange;// Range for each color entry (7,7,and 3) // Get the pixel format index and retrieve the pixel format description nPixelFormat = 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 NULL if(!(pfd.dwFlags & PFD_NEED_PALETTE)) return NULL;
12
Hallym University GVE LAB. 12 Graphics and Virtual Environment Laboratory The Palette’s Structure typedef struct tagLOGPALETTE { WORD palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE; LOGPALETTE *pPal; ….. pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + ncolors * sizeof(PALETTEENTRY));
13
Hallym University GVE LAB. 13 Graphics and Virtual Environment Laboratory The 3-3-2 Palette 7 6 5 4 3 2 1 0 8-bit Palette Index Blue intensity Green intensity Red intensity Function to Create a palette for OpenGL Device context
14
Hallym University GVE LAB. 14 Graphics and Virtual Environment Laboratory The 3-3-2 Palettes
15
Hallym University GVE LAB. 15 Graphics and Virtual Environment Laboratory Building the Palettes ( 팔레트 생성 ) Function to create a palette for OpenGL case WM_CREATE: // Store the device context hDC = GetDC(hWnd); // Select the pixel format SetDCPixelFormat(hDC); // 팔레트 만들기 hPalette = GetOpenGLPalette(hDC); // Create the rendering context and make it current hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); break;
16
Hallym University GVE LAB. 16 Graphics and Virtual Environment Laboratory Palette Disposal // Window is being destroyed, cleanup case WM_DESTROY: // Deselect the current rendering context and delete it wglMakeCurrent(hDC,NULL); wglDeleteContext(hRC); if(hPalette != NULL) DeleteObject(hPalette); // Tell the application to terminate after the window // is gone. PostQuitMessage(0); break;
17
Hallym University GVE LAB. 17 Graphics and Virtual Environment Laboratory Windows Palettes 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 컬러들이 저장된 배열의 인덱스를 사용해서 특정 색을 지정.
18
Hallym University GVE LAB. 18 Graphics and Virtual Environment Laboratory Windows Palettes Color Index Mode Using 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
19
Hallym University GVE LAB. 19 Graphics and Virtual Environment Laboratory Using Color Index Mode Index.exe List 8-6. Index.c 의 GetRedPalette 함수 다양한 명암의 빬간색으로만 구성된 팔레 트를 만드는 코드 ( 참고 ) Color Index Mode 를 사용하려면, PIXELFORMATDESCRIPTOR 의 iPixeType 을 PFD_TYPE_COLORINDEX 로 설정하여야 한다.
20
Hallym University GVE LAB. 20 Graphics and Virtual Environment Laboratory Using Color Index Mode List 8-6. Index.c 의 RenderScene 함수 삼각형의 꼭지점은 밝기가 0( 검은색 ) 인 가장 어두운 색으로 설정함. 나머지 두 꼭지점은 가장 밝은 빨간색 (Index 255) 을 사용함. 부드럽게 Shading 된 삼각형 (3-3-2 팔레트에서는 불가능 )
21
Hallym University GVE LAB. 21 Graphics and Virtual Environment Laboratory Summary Color, RGB 요소를 사용하여 색 지정. RGB color cube glColor() 의 사용법 Coloring, Shading, Dithering, Index, Masking 3-3-2 팔레트 구성 (8-bit mode 에서 OpenGL 을 사용하는 경우 )
22
Hallym University GVE LAB. 22 Graphics and Virtual Environment Laboratory 8 COLOR AND SHADING 8 COLOR AND SHADING THE END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.