This topic is now archived and is closed to further replies.


PixelFormat (Whats wrong?)

Recommended Posts

The problem is that no matter what i do, this function is unable to find a suitable pixelformat. The funny thing, is that if I include the file "gl.h" and use any function from it and put it anywhere in the code, magically, i get the damn PixelFormat. So whats wrong? This bug is seems magical to me? Who the hell put this curse on me? =O) For example, if i put the line... glColor3f(0.0f,0.0f,0.0f); just after the return, i get a pixelformat and the window setups perfectly? what is going on here? is it a compilerbug? i had another incredible bug yesterday. I had the function with beginning with the two lines... KernelClass::~KernelClass() { but it have an error on the { (something about the old stile for headers. But I know it all right, so I copypasted the same two lines from somewhere else. It looked perfectly the same, but this time... it magically worked. Im going crazy. Thanks a lot I apreciate any help. Alejandro Martínez LOOK AT THIS FUNCTION... bool KernelClass::Init() { bool Error = false; WNDCLASSEX WndClass; WndClass.cbSize = sizeof(WNDCLASSEX); = CS_DBLCLKS | CS_OWNDC; WndClass.lpfnWndProc = WinProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = *hAplication; WndClass.hIcon = LoadIcon(*hAplication, MAKEINTRESOURCE(IDI_ENGINE)); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); WndClass.lpszMenuName = NULL; WndClass.lpszClassName = "Engine 2"; WndClass.hIconSm = LoadIcon(*hAplication, MAKEINTRESOURCE(IDI_ENGINE)); if (!RegisterClassEx(&WndClass)) { MessageBox(NULL,"WindowClass could not be registered.","INITIALIZATION",MB_OK|MB_ICONEXCLAMATION); Error = true; } static PIXELFORMATDESCRIPTOR PixelFD = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; RECT rWindow; =(long)0; rWindow.left =(long)0; rWindow.right =(long)Width; rWindow.bottom =(long)Height; DWORD dwExStyle = WS_EX_APPWINDOW; DWORD dwStyle = WS_POPUP | WS_VISIBLE; if (!AdjustWindowRectEx(&rWindow, dwStyle, FALSE, dwExStyle)) MessageBox(NULL,"Window rectangle could not be adjusted.","INITIALIZATION WARNING",MB_OK|MB_ICONEXCLAMATION); hWindow = new HWND; hDeviceContext = new HDC; PixelFormat = new int; if (!(*hWindow = CreateWindowEx(dwExStyle, WndClass.lpszClassName, "Main Window", dwStyle, rWindow.left,, rWindow.right, rWindow.bottom, 0, 0, *hAplication, 0))) { Error = true; MessageBox(NULL,"Window could not be created.","INITIALIZATION ERROR",MB_OK|MB_ICONEXCLAMATION); } else if (!(*hDeviceContext = GetDC(*hWindow))) { Error = true; MessageBox(NULL,"DeviceContext could not be created.","INITIALIZATION ERROR",MB_OK|MB_ICONEXCLAMATION); } else if (!(*PixelFormat = ChoosePixelFormat(*hDeviceContext,&PixelFD))) { Error = true; MessageBox(NULL,"Couldn´t find a suitable PixelFormat.","INITIALIZATION ERROR",MB_OK|MB_ICONEXCLAMATION); } else if(!SetPixelFormat(*hDeviceContext, *PixelFormat,&PixelFD)) { Error = true; MessageBox(NULL,"The PixelFormat could not be set.","INITIALIZATION ERROR",MB_OK|MB_ICONEXCLAMATION); } else { ShowWindow(*hWindow,SW_SHOW); SetForegroundWindow(*hWindow); SetFocus(*hWindow); ShowCursor(false); } return !Error; }

Share this post

Link to post
Share on other sites