Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: PIXELFORMATDESCTIPTOR problem

  1. #1
    Newbie Newbie
    Join Date
    Apr 2013
    Posts
    2

    PIXELFORMATDESCTIPTOR problem

    Hi everyone,

    I'm relatively new to OpenGL programming. I successfully wrote an application with freeGLUT and GLEW displaying some triangles and some textures.
    Now I wanted to create an application without freeGLUT.
    The problem is that "ChoosePixelFormat()" always returns 0 instead of some matching number.
    Here is my PIXELFORMATDESCRIPTOR:
    Code :
    PIXELFORMATDESCRIPTOR pfd = {
    		sizeof(PIXELFORMATDESCRIPTOR),
    		1, 
    		PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
    		PFD_TYPE_RGBA,
    		32, 
    		0, 0, 0, 0, 0, 0, 
    		0, 
    		0, 
    		0, 
    		0, 0, 0, 0, 
    		24, 
    		0, 
    		0, 
    		PFD_MAIN_PLANE, 
    		0, 
    		0, 0, 0
    	};
     
            int matchingPFD;
    	matchingPFD = ChoosePixelFormat(hdc, &pfd);

    I really have no idea what I am doing wrong here so I hope someone can help me out.
    For your information I'm using Windows 8 and Visual Studio 2010.

    Thanks and greetz
    sikkiv

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    9
    At least, as MSDN says, you can call GetLastError() after ChoosePixelFormat() to retrieve something to start with.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    I know you can only call SetPixelFormat once for a window; this may be true for ChoosePixelFormat as well.

  4. #4
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,146
    First of all, use PIXELFORMATDESCRIPTOR as a structure, and set parameters by name.
    Second, unlike setting pixel format, choosing is not "malicious" operation and you can call it unlimited number of times without any convenience.
    Third, what's GetLastError saying?

    Try the following form of your setting:
    Code :
    PIXELFORMATDESCRIPTOR pfd ;
       	memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
       	pfd.nSize  = sizeof(PIXELFORMATDESCRIPTOR);
       	pfd.nVersion   = 1; 
       	pfd.dwFlags    = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;   
       	pfd.iPixelType = PFD_TYPE_RGBA; 
       	pfd.cColorBits = 32;
       	pfd.cDepthBits = 24; 
       	pfd.iLayerType = PFD_MAIN_PLANE;

  5. #5
    Newbie Newbie
    Join Date
    Apr 2013
    Posts
    2
    First thanks for your replies

    I set the parameters by name and called GetLastError, here is the error message:
    "ChoosePixelFormat failed with error 6: the handle is invalid"
    So it's clear what I've done wrong, I didn't retrieve the device context properly
    Now it's working just fine.
    I should get more comfortable with the Win32 API I think

    But thanks to all for the effort.
    greetz sikkiv

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •