0

i am trying to attach window to opengl (wglCreateContext) but before doing it, i need to set a pixel format for it. ChoosePixelFormat succeeds but SetPixelFormat returns always 0xFFFFFFFF (-1). Calling GetLastError returns 0 (success) so i am confused about what is wrong. MSDN says that SetPixelFormat should return only 0 or 1 (not -1). Im doing it in asm but here is pseudo c code:

hdc = GetDC(CreateWindowExA(0, "edit", 0, WS_POPUP | WS_MAXIMIZE | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0)); //window is successfully created
SetPixelFormat(hdc, ChoosePixelFormat(hdc, ppfd), ppfd); //ChoosePixelFormat returns 7
//returned value is -1
//GetLastError returns 0
wglMakeCurrent(hdc, wglCreateContext(hdc)); //both fails and GetLastError = 0x7D0 (The pixel format is invalid)

its based on reverse engineering so the pixel format descriptor is in bytes, sorry:

db 0x28,0x00,0x01,0x00,0x25,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

Thank you for any help

--EDIT: The pixel format descriptor rewrited to c:

LPPIXELFORMATDESCRIPTOR ppfd;
::memset(ppfd, 0x0, 0x28);
ppfd->nSize = 0x28;
ppfd->nVersion = 1;
ppfd->dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
ppfd->iPixelType = 0x0;
ppfd->cColorBits = 32;
ppfd->cDepthBits = 16;
Segy
  • 213
  • 2
  • 12
  • Note that SetPixelFormat returns 0 on error. Maybe it succeeds? – Dietrich Epp Nov 01 '19 at 14:50
  • no, because than wglCreateContext fails with GetLastError 7D0 = The pixel format is invalid – Segy Nov 01 '19 at 14:53
  • try to mimic this [What is the proper OpenGL initialisation on Intel HD 3000?](https://stackoverflow.com/q/19099162/2521214) it tries all the listed configurations from best to worst and stops on first valid one. Also are you sure the size is `0x28`? wrong size might cause this too – Spektre Nov 04 '19 at 09:33
  • yes, size is correct (0x28) – Segy Feb 22 '20 at 14:00

0 Answers0