News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Is this normal?

Started by Cybrid, February 12, 2006, 12:11:34 PM

Previous topic - Next topic

Cybrid

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??

thomas

The error is very likely in a header file included before that.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

kkez

The initialization by { } can be done only when you declare your variable:
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 };

Cybrid

God, thanks kkez, it solved the problem, I didn't know that.

Many thanks.

Cybrid

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??

kkez

As you can see here and here, you need to include windows.h and link to gdi32.lib (libgdi32.a).

Cybrid

Thanks, problem solved. I'm just too much used to MSVC ;)

kkez

Uh, i read too rapidly, you need to include wingdi.h  :)