Thread: ChoosePixelFormat blues...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    22

    ChoosePixelFormat blues...

    I'm trying to create an OpenGL window wrapper class and ChoosePixelFormat is giving me on heck of time. In the attached code (OpenGLWindow.cpp, OpenGLWindow::CreateOGLWindow() ), I create my base window, get an HDC, fill out the pixel format description struct and send it off to ChoosePixelFormat. However, ChoosePixelFormat just returns 0 and GetLastError returns 126 (which is module not found or some such). The thing is that I can use any PFD and this happens (including PFDs from tutorial code I've downloaded and successfully compiled and executed). Does anyone here have any ideas (I've two forums at gamedev, but no luck)?

    Secondly, and far less important, is it possible for me to modify my BaseWindow class (also in the attach zip file) to be used for creating more than one window? IE making one instance of the window class (as shown in WinMain) will create a perfectly good window, but adding a second instance fails as RegisterWindowEx fails. Like I said, its not important but could be useful down the line.

    Just for FYI, this code is the base of OpenFlight/OpenSceneGraph viewer.

    Thanks,
    Arrow
    Last edited by Arrow Mk 84; 08-14-2002 at 02:36 PM.
    Never give an Ewok a thermial detonator

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    22
    Well I figured out how to get my program to display more than one window, but still no luck with ChoosePixelFormat. Anybody have any suggestions? Please?
    Never give an Ewok a thermial detonator

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    22
    Ok, this problem is still a MAJOR pain. Now I'm trying to use LoadLibrary to call the function (someone over at gamedev said that it looked like the gdi32 library was being unloaded before I called ChoosePixelFormat and that LoadLibrary would let me make sure that it was loaded). I'm having a problem with the following code:

    int format = 0;

    HINSTANCE gdilib = LoadLibrary("gdi32.dll");

    FARPROC cpf_func = GetProcAddress(gdilib, "ChoosePixelFormat");

    format = ((int (*)(HDC, CONST PIXELFORMATDESCRIPTOR *))cpf_func)(window_hDC, &pfd);//::ChoosePixelFormat(window_hDC, &pfd);


    The error I get is: "The value of ESP was not properly saved across a function call. This is usually the result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."

    As far as I can tell, I've properly casted the function arguments. Anybody have any ideas?

    Thanks.
    Never give an Ewok a thermial detonator

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    In your project settings you are attempting to link with opengl.lib glu.lib. This of course should be opengl32.lib glu32.lib.

    I couldn't compile your code until I sorted that out.

    The return value from SetPixelFormat is fine.

    I'd ignore the 'gdi32.dll unloading' advice as it seems to me to be wildly speculative; so no need to go through the hassle of run-time loading of functions.

    Try changing the lib names in the link settings as I have described and see whether that solves your problem or not.

    Speculate: It may also be that you are attempting to get a pixelformat not supported by your hardware; tweaking the params of the PIXELFORMATDESCRIPTOR struct to something more generic may clarify that speculation.
    Last edited by Ken Fitlike; 08-19-2002 at 03:27 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    22
    DOH! You nailed right on the head. That little typo was frustrating. Thanks for the catch (that's two problems of mine that you've solve). I've been the project settings lots of times too and never saw the error (oddly enough it compiled). Thanks again!
    Never give an Ewok a thermial detonator

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Boost Blues
    By CodeMonkey in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2008, 02:13 AM
  2. .NET Blues
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 02-26-2003, 07:56 PM
  3. bitmap blues
    By Invincible in forum Game Programming
    Replies: 1
    Last Post: 05-12-2002, 07:43 AM
  4. two dimensional array blues.
    By Brian in forum C Programming
    Replies: 4
    Last Post: 02-07-2002, 07:41 PM
  5. clrscr() blues...
    By CodeMonkey in forum Windows Programming
    Replies: 1
    Last Post: 01-17-2002, 03:20 PM