/* Stef TEST for ChoosePixelFormat PB */ /* from glinfo.c in demos */ #include #include #include #include #include #include "windows.h" typedef HWND Window; /* from glutinit */ char *__glutProgramName = NULL; int __glutArgc = 0; char **__glutArgv = NULL; char *__glutGeometry = NULL; /* * Display *__glutDisplay = NULL; */ int __glutScreen; Window __glutRoot; int __glutScreenHeight; int __glutScreenWidth; unsigned int __glutDisplayMode = 0; char *__glutDisplayString = NULL; int __glutConnectionFD; int __glutInitWidth = 300, __glutInitHeight = 300; /* int __glutInitX = -1, __glutInitY = -1; */ int __glutInitX = 100, __glutInitY = 50; /* *INDENT-ON* */ Window XHWND; HDC XHDC; LONG WINAPI dummyWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { return DefWindowProc(hwnd, msg, wParam, lParam); } void dummyError(void) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ (LPTSTR) &lpMsgBuf, 0, NULL ); /* Display the string. */ MessageBox( NULL, lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION ); /* Free the buffer. */ LocalFree( lpMsgBuf ); } PIXELFORMATDESCRIPTOR * dummyChooseVisual(int rgb, int dble) { int pf; PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR *match = NULL; int stereo = 0; memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = (sizeof(PIXELFORMATDESCRIPTOR)); pfd.nVersion = 1; /* Defaults. */ pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; pfd.iPixelType = PFD_TYPE_COLORINDEX; pfd.cColorBits = 32; pfd.cDepthBits = 0; if (rgb) { /* GLX_RGBA: */ pfd.iPixelType = PFD_TYPE_RGBA; fprintf(stderr," ChoosePixel RGBA %d\n",pfd.iPixelType); /* GLX_RED_SIZE */ pfd.cRedBits = 8; /* Try to get the maximum. */ fprintf(stderr," ChoosePixel RED size %d\n",pfd.cRedBits); /* GLX_GREEN_SIZE */ pfd.cGreenBits = 8; /* Try to get the maximum. */ fprintf(stderr," ChoosePixel GREEN size %d\n",pfd.cGreenBits); /* GLX_BLUE_SIZE */ pfd.cBlueBits = 8; /* Try to get the maximum. */ fprintf(stderr," ChoosePixel BLUE size %d\n",pfd.cBlueBits); } else { /* GLX_BUFFER_SIZE */ pfd.cColorBits = 8; /* intermediary stuff */ fprintf(stderr," ChoosePixel BufferSize %d\n",pfd.cColorBits); } if (dble) { /* GLX_DOUBLEBUFFER */ pfd.dwFlags |= PFD_DOUBLEBUFFER; fprintf(stderr," ChoosePixel DoubleBuff %x\n",pfd.dwFlags); } SetLastError(ERROR_SUCCESS); fprintf(stderr," ChoosePixel call ChoosePixelFormat(%x ...)\n",XHDC); pf = ChoosePixelFormat(XHDC, &pfd); if (pf > 0) { fprintf(stderr," ChoosePixel called >0 == %x\n",pf); match = (PIXELFORMATDESCRIPTOR *) malloc(sizeof(PIXELFORMATDESCRIPTOR)); DescribePixelFormat(XHDC, pf, sizeof(PIXELFORMATDESCRIPTOR), match); /* ChoosePixelFormat is dumb in that it will return a pixel format that doesn't have stereo even if it was requested so we need to make sure that if stereo was selected, we got it. */ if (stereo) { if (!(match->dwFlags & PFD_STEREO)) { fprintf(stderr," ChoosePixel called stereao failed\n"); free(match); return(NULL); } } /* XXX Brad's Matrix Millenium II has problems creating color index windows in 24-bit mode (lead to GDI crash) and 32-bit mode (lead to black window). The cColorBits filed of the PIXELFORMATDESCRIPTOR returned claims to have 24 and 32 bits respectively of color indices. 2^24 and 2^32 are ridiculously huge writable colormaps. Assume that if we get back a color index PIXELFORMATDESCRIPTOR with 24 or more bits, the PIXELFORMATDESCRIPTOR doesn't really work and skip it. -mjk */ if (match->iPixelType == PFD_TYPE_COLORINDEX && match->cColorBits >= 24) { fprintf(stderr," ChoosePixel called cColorsBit > 24 failed\n"); free(match); return(NULL); } } else { fprintf(stderr," ChoosePixel FAILED %s %s %x\n", (rgb) ? "RGB" : "INDEX" , (dble) ? "double": "single", pf); dummyError(); } return match; } int main( int argc, char *argv[] ) { /* initwin32connection */ static char *classname = NULL; WNDCLASS wc; HINSTANCE hInstance; /* inittime */ /* glutcreatewindow */ static int firstWindow = 1; Window win_win32; /* also for =__glutcreateWindow !!! */ HDC win_hdc; Window win; /* __glutcreateWindow */ int i; WNDCLASS wc_1; int style; /* * glutInit( &argc, argv ); */ /* arg processing removed */ /* __glutOpenWin32Connection(display); */ hInstance = GetModuleHandle(NULL); fprintf(stderr, " GetModuleHandle(NULL); => %x\n", hInstance); classname = "GLUT"; /* correct ??? strdup("CLUT"); */ /* Clear (important!) and then fill in the window class structure. */ memset(&wc, 0, sizeof(WNDCLASS)); wc.style = CS_OWNDC; wc.lpfnWndProc = (WNDPROC)dummyWindowProc; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, "GLUT_ICON"); wc.hCursor = LoadCursor(hInstance, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = classname; /* Fill in a default icon if one isn't specified as a resource. */ if(!wc.hIcon) { fprintf(stderr,"Didnot get ressorce ICON load default\n"); wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); if(!wc.hIcon) fprintf(stderr,"ICON failed to load default\n"); } if(!RegisterClass(&wc)) { fprintf( stderr, "RegisterClass() failed: Cannot register GLUT window class.\n"); } fprintf(stderr, "RegisterClass() succeed\n"); __glutScreenWidth = GetSystemMetrics(SM_CXSCREEN); __glutScreenHeight = GetSystemMetrics(SM_CYSCREEN); fprintf(stderr, " System Metric Wdth %d Hght %d\n", __glutScreenWidth, __glutScreenHeight); /* Set the root window to NULL because windows creates a top-level window when the parent is NULL. X creates a top-level window when the parent is the root window. */ __glutRoot = NULL; /* Set the display to 1 -- we shouldn't be using this anywhere (except as an argument to X calls). */ /* __glutDisplay = (Display*)1; */ /* There isn't any concept of multiple screens in Win32, therefore, we don't need to keep track of the screen we're on... it's always the same one. */ __glutScreen = 0; /* glutInitWindowSize(__glutInitWidth, __glutInitHeight); * Not relevent skipped */ /* glutInitWindowPosition(__glutInitX, __glutInitY); * Not Relevent skipped */ /* __glutInitTime(&unused); */ #if 0 if (!beenhere) { fprintf(stderr," inittime not been here yet \n"); GETTIMEOFDAY(&genesis); fprintf(stderr," inittime get time of day ok \n"); beenhere = 1; } *beginning = genesis; #endif /* END GLUT_INIT */ /* * glutInitDisplayMode( GLUT_RGB ); */ #if 0 __glutDisplayMode = GLUT_RGB; #endif fprintf(stderr, " GLUT INITIALISED \n"); /* * glutCreateWindow(argv[0]); */ /* window = __glutCreateWindow(NULL(==parent), * __glutSizeHints.x, __glutSizeHints.y, * __glutInitWidth, __glutInitHeight, */ if (!GetClassInfo(GetModuleHandle(NULL), "GLUT", &wc_1)) { fprintf(stderr," GOT PROBLEM in glutInit shouldnot failed\n"); } else fprintf(stderr,"CreateWin: Got GLUT ClassInfo OK\n"); /* getUnusedWindowSlot(); * SKIPPED */ /* init skipped */ /* __glutAdjustCoords(parent ? parent->win : NULL, * &x, &y, &width, &height); * Skipped */ /* A standard toplevel window with borders and such. */ style = WS_OVERLAPPEDWINDOW; fprintf(stderr, "call CreateWindow(\"GLUT\",\"GLUT\", %x, %d,%d, %d,%d,%x %c..\n", WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style, __glutInitX, __glutInitY, __glutInitWidth, __glutInitHeight, __glutRoot, 'R'); win_win32 = CreateWindow("GLUT", "GLUT", WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style, __glutInitX, __glutInitY, __glutInitWidth, __glutInitHeight, __glutRoot, NULL, GetModuleHandle(NULL), 0); fprintf(stderr," CREATED WINDOW %x \n", win_win32); win_hdc = GetDC(win_win32); fprintf(stderr," CREATED HDC %x \n", win_hdc); /* Must set the XHDC for fake glXChooseVisual & fake glXCreateContext & fake XAllocColorCells. */ XHDC = win_hdc; XHWND = win_win32; if (!dummyChooseVisual(1,0)) { fprintf(stderr," Failed To Choose Visual RGB \n"); } if (!dummyChooseVisual(1,1)) { fprintf(stderr," Failed To Choose Visual RGB Dble\n"); } if (!dummyChooseVisual(0,0)) { fprintf(stderr," Failed To Choose Visual CMAP \n"); } if (!dummyChooseVisual(0,1)) { fprintf(stderr," Failed To Choose Visual CMAP Dble\n"); } }