wglcreatecontext c# unwell nonetheless managed c++
i'm perplexing opengl c#. i have following formula fails blunder 2000 error_invalid_pixel_format
first definitions:
[dllimport("user32.dll", charset = charset.auto, setlasterror = true, exactspelling = true)]
public stationary extern intptr getdc(intptr hwnd);
[structlayout(layoutkind.sequential)]
open struct pixelformatdescriptor
{
open vacant init()
{
nsize = (ushort) marshal.sizeof(typeof (pixelformatdescriptor));
nversion = 1;
dwflags = pfd_flags.pfd_draw_to_window | pfd_flags.pfd_support_opengl | pfd_flags.pfd_doublebuffer | pfd_flags.pfd_support_composition;
ipixeltype = pfd_pixel_type.pfd_type_rgba;
ccolorbits = 24;
credbits = credshift = cgreenbits = cgreenshift = cbluebits = cblueshift = 0;
calphabits = calphashift = 0;
caccumbits = caccumredbits = caccumgreenbits = caccumbluebits = caccumalphabits = 0;
cdepthbits = 32;
cstencilbits = cauxbuffers = 0;
ilayertype = pfd_layer_types.pfd_main_plane;
breserved = 0;
dwlayermask = dwvisiblemask = dwdamagemask = 0;
}
ushort nsize;
ushort nversion;
pfd_flags dwflags;
pfd_pixel_type ipixeltype;
byte ccolorbits;
byte credbits;
byte credshift;
byte cgreenbits;
byte cgreenshift;
byte cbluebits;
byte cblueshift;
byte calphabits;
byte calphashift;
byte caccumbits;
byte caccumredbits;
byte caccumgreenbits;
byte caccumbluebits;
byte caccumalphabits;
byte cdepthbits;
byte cstencilbits;
byte cauxbuffers;
pfd_layer_types ilayertype;
byte breserved;
uint dwlayermask;
uint dwvisiblemask;
uint dwdamagemask;
}
[flags]
open enum pfd_flags : uint
{
pfd_doublebuffer = 0x00000001,
pfd_stereo = 0x00000002,
pfd_draw_to_window = 0x00000004,
pfd_draw_to_bitmap = 0x00000008,
pfd_support_gdi = 0x00000010,
pfd_support_opengl = 0x00000020,
pfd_generic_format = 0x00000040,
pfd_need_palette = 0x00000080,
pfd_need_system_palette = 0x00000100,
pfd_swap_exchange = 0x00000200,
pfd_swap_copy = 0x00000400,
pfd_swap_layer_buffers = 0x00000800,
pfd_generic_accelerated = 0x00001000,
pfd_support_directdraw = 0x00002000,
pfd_direct3d_accelerated = 0x00004000,
pfd_support_composition = 0x00008000,
pfd_depth_dontcare = 0x20000000,
pfd_doublebuffer_dontcare = 0x40000000,
pfd_stereo_dontcare = 0x80000000
}
open enum pfd_layer_types : byte
{
pfd_main_plane = 0,
pfd_overlay_plane = 1,
pfd_underlay_plane = 255
}
open enum pfd_pixel_type : byte
{
pfd_type_rgba = 0,
pfd_type_colorindex = 1
}
[dllimport("gdi32.dll", charset = charset.auto, setlasterror = true, exactspelling = true)]
open stationary extern int choosepixelformat(intptr hdc, [in] ref pixelformatdescriptor ppfd);
[dllimport("gdi32.dll", charset = charset.auto, setlasterror = true, exactspelling = true)]
open stationary extern bool setpixelformat(intptr hdc, int ipixelformat, ref pixelformatdescriptor ppfd);
[dllimport("opengl32.dll", charset = charset.auto, setlasterror = true, exactspelling = true)]
open stationary extern intptr wglcreatecontext(intptr hdc);
and formula fails:
intptr dc = win.getdc(hwnd);
var pixelformatdescriptor = new gl.pixelformatdescriptor();
pixelformatdescriptor.init();
var pixelformat = gl.choosepixelformat(dc, ref pixelformatdescriptor);
if(!gl.setpixelformat(dc, pixelformat, ref pixelformatdescriptor))
pitch new win32exception(marshal.getlastwin32error());
intptr hglrc;
if((hglrc = gl.wglcreatecontext(dc)) == intptr.zero)
pitch new win32exception(marshal.getlastwin32error()); //<----- here i have exception
the same formula managed c++ working
hdc dc = getdc(hwnd);
pixelformatdescriptor pf;
pf.nsize = sizeof(pixelformatdescriptor);
pf.nversion = 1;
pf.dwflags = pfd_draw_to_window | pfd_support_opengl | pfd_doublebuffer | pfd_support_composition;
pf.ccolorbits = 24;
pf.credbits = pf.credshift = pf.cgreenbits = pf.cgreenshift = pf.cbluebits = pf.cblueshift = 0;
pf.calphabits = pf.calphashift = 0;
pf.caccumbits = pf.caccumredbits = pf.caccumgreenbits = pf.caccumbluebits = pf.caccumalphabits = 0;
pf.cdepthbits = 32;
pf.cstencilbits = pf.cauxbuffers = 0;
pf.ilayertype = pfd_main_plane;
pf.breserved = 0;
pf.dwlayermask = pf.dwvisiblemask = pf.dwdamagemask = 0;
int ipf = choosepixelformat(dc, &pf);
setpixelformat(dc, ipf, &pf);
hglrc hglrc = wglcreatecontext(dc);
i've attempted perspective 64-bit ati distinguished tag windows xp 32-bit nvidia same outcome both cases.
also i wish plead i don't wish any already combined horizon it.
can anyone arrangement me where bug c# formula causing exception?
Comments
Post a Comment