User forums > General (but related to Code::Blocks)

Is this normal?

(1/2) > >>

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.

kkez:
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 };
--- End code ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version