While i learned OpenGL, i never checked for any errors. Now im writing a "shell" app to use that will check for as many error as possible. When i wasnt checking for errors, ChoosPixelFormat would work. Or at least if it failed i didnt know it, and the OpenGL app would still work. Now that i check to make sure it doesnt fail, it always does. Ill post the code i use to choose a pixel format, maybe theres something wrong in it. Is there anywhere else in a windows opengl app that would affect choosing a pixel format? Like somthing in the window class structure or something?

int choosePixelFormat()

{
PIXELFORMATDESCRIPTOR pfd;

pfd.cColorBits = 16;
pfd.cDepthBits = 16;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
if((pixelFormatWndGL = ::ChoosePixelFormat(hDCWndGL, &pfd)) == 0)
{
::MessageBox(NULL, "Failure choosing pixel format.", appTitle, MB_OK | MB_ICONERROR);
return(1);
}

return(0);
}
Posted on 2002-06-26 12:23:39 by ChimpFace9000
By the way, im doing all the opengl initilization in the WM_CREATE message, should it be done some where else?
Posted on 2002-06-26 13:31:07 by ChimpFace9000
We are doing all inits before message loop is started in HE but we use DX, OpenGL window init and/or switch context has always been unreliable IMO
Posted on 2002-06-26 18:14:16 by BogdanOntanu
Actually i think its a problem with windows 98. Ill post the code and the binary. Could people give it a try and tell me what version of windows they are using, and if they got any errors. Thanks.

Code deleted


Just get rid of the .txt on the exe. Id post the whole project, but i dont have winzip.

[ Attachment deleted ]
Posted on 2002-06-26 18:57:06 by ChimpFace9000
Ok, i download winzip and heres the whole project.
Posted on 2002-06-27 04:46:37 by ChimpFace9000
Afternoon, ChimpFace9000.

I used GetLastError just after ChoosePixelFormat.
It returned 126 as the error code.
My docs says that this means "The specified module could not be found.".

I wouldn't have a clue as to what "module" it's talking about :grin:

Cheers,
Scronty
Posted on 2002-06-27 06:56:39 by Scronty
I looked at the game dev forums, and people who had the same problem said get last error returned that and none of them had any idea what that meant.

I wrote to NeHe about the problem, he said try changing the bit depth of my desktop to match the bit depth in my code. And update my drivers. So im off to try that.
Posted on 2002-06-27 13:02:12 by ChimpFace9000
Matching the bit depth didnt work, and updating my drivers screwed up my whole computer. Oh well.
Posted on 2002-06-27 13:53:36 by ChimpFace9000
Posted on 2002-06-28 04:09:41 by ChimpFace9000
Ditch OpenGL and go D3D? :)
Posted on 2002-06-28 04:26:16 by f0dder
Posted on 2002-06-28 04:35:30 by bazik
This wasnt an OpenGL problem, this was a Visual C++ problem.
Posted on 2002-06-28 04:54:48 by ChimpFace9000
It's not Visual C++ problem. It's gdi32.dll problem. There are two versions of ChoosePixelFormat, ChoosePixelFormat exported in gdi32.dll and "hidden" wglChoosePixelFormat exported in opengl32.dll (hidden means that is not defined in header files). When the call to ChoosePixelFormat is made, first it's trying to find is it opengl32.dll loaded in the memory (GetModuleHandle), then if it's loaded, finds the adress of wglChoosePixelFormat (with GetProcAddress), and he calls wglChoosePixelFormat.

So, if opengl32.dll it's not loaded ChoosePixelFormat fails.

Using GetModuleHandle to finds is it opengl32.dll loaded explains why "The specified module could not be found." error is showing...

Solution: use any kind of gl or wgl functions, at least once function, just compiler to link to the opengl32.dll...
Posted on 2002-06-28 06:28:14 by minimoog
so ChimpFace was doing OpenGL with no other calls than
ChoosePixelFormat? :). Ok, perhaps using GetModuleHandle instead
of LoadLibrary isn't the best approach, but at least that way you
don't get crazy reference counts to opengl32.dll ...

And btw, the linker discarding unused libs it not a "problem" - its
an optimization. Otherwise boy you'd have some bloated executables.
Posted on 2002-06-28 06:47:22 by f0dder
ChoosePixelFormat is windows opengl specific, why this function is "mapped" in gdi32.dll I don't know.

Here are wgl functions that are linked to gdi32.dll:

ChoosePixelFormat
DescribePixelFormat
GetPixelFormat
SetPixelFormat
SwapBuffers

I guess that they all require opengl32.dll to be loaded or they fail...
Posted on 2002-06-28 09:54:28 by minimoog
1. from what i have experienced, it is not good idea to initialize opengl during WM_CREATE (it crashes a lot on my win98SE, creates bugs on stack (ESP points to wrong place), ogl doesn't initialize at all, or initializes wrongly (for example: 16bpp when i have chose 32 etc.)).

so it's better to initialize ogl AFTER returning from CreateWindow.

2. on some nVidia's cards open gl requires CS_OWNDC flag to be set when registering window class.

it is good idea then to set that flag, even if u r not sure wheter a card is nvidia's or not.


------------------------------------------------------
The only way to achieve the goal is fight....
...but i always forget about it.
Posted on 2002-07-13 10:30:34 by ti_mo_n
I use win98se and ogl starts perfectly under wm_create. Theres probably a problem with your code.
Posted on 2002-07-13 15:27:24 by ChimpFace9000