Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: Cybrid on February 12, 2006, 12:11:34 pm

Title: Is this normal?
Post by: Cybrid on February 12, 2006, 12:11:34 pm
I receive this error during building in this function, is it normal?

void SetDCPixelFormat(HDC hDC)
{
    PIXELFORMATDESCRIPTOR pfd;
    int nPixelFormat;
    pfd = {                                         /ERROR IS HERE
        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,
        16,
        0,
        0,
        0,
        0,
        0,0,0 };
    nPixelFormat = ChoosePixelFormat(hDC, &pfd);
    SetPixelFormat(hDC, nPixelFormat, &pfd);
}

error: expected primary-expression before '{' token
error: expected ';' before '{' token.

I think the code is ok, do you see any error??
Title: Re: Is this normal?
Post by: thomas on February 12, 2006, 12:51:36 pm
The error is very likely in a header file included before that.
Title: Re: Is this normal?
Post by: kkez on February 12, 2006, 01:27:23 pm
The initialization by { } can be done only when you declare your variable:
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,
        16,
        0,
        0,
        0,
        0,
        0,0,0 };
Title: Re: Is this normal?
Post by: Cybrid on February 12, 2006, 01:35:11 pm
God, thanks kkez, it solved the problem, I didn't know that.

Many thanks.
Title: Re: Is this normal?
Post by: Cybrid on February 12, 2006, 01:52:35 pm
Errr, just another question...

I receive undefined references in the same code above regarding "SetPixelFormat" and "ChoosePixelFormat" calls.
I've added:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>

and glu32 and opengl32 to the linker's options, do I need any lib more to get this working??. Am I missing something??
Title: Re: Is this normal?
Post by: kkez on February 12, 2006, 01:59:52 pm
As you can see here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/ntopnglr_3q5w.asp) and here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/ntopnglr_2qb8.asp), you need to include windows.h and link to gdi32.lib (libgdi32.a).
Title: Re: Is this normal?
Post by: Cybrid on February 12, 2006, 02:15:26 pm
Thanks, problem solved. I'm just too much used to MSVC ;)
Title: Re: Is this normal?
Post by: kkez on February 12, 2006, 04:05:27 pm
Uh, i read too rapidly, you need to include wingdi.h  :)