Author Topic: Is this normal?  (Read 5290 times)

Cybrid

  • Guest
Is this normal?
« 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??

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Is this normal?
« Reply #1 on: February 12, 2006, 12:51:36 pm »
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."

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Is this normal?
« Reply #2 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 };

Cybrid

  • Guest
Re: Is this normal?
« Reply #3 on: February 12, 2006, 01:35:11 pm »
God, thanks kkez, it solved the problem, I didn't know that.

Many thanks.

Cybrid

  • Guest
Re: Is this normal?
« Reply #4 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??

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Is this normal?
« Reply #5 on: February 12, 2006, 01:59:52 pm »
As you can see here and here, you need to include windows.h and link to gdi32.lib (libgdi32.a).

Cybrid

  • Guest
Re: Is this normal?
« Reply #6 on: February 12, 2006, 02:15:26 pm »
Thanks, problem solved. I'm just too much used to MSVC ;)

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Is this normal?
« Reply #7 on: February 12, 2006, 04:05:27 pm »
Uh, i read too rapidly, you need to include wingdi.h  :)