Mixed Language Programming-C # use native Directx and OpenGL

Source: Internet
Author: User

Extern "C" _ declspec (dllexport) HRESULT InitD3D (HWND hWnd );

Extern "C" _ declspec (dllexport) VOID Render ();

HWND handle = this. button1.Handle;

InitD3D (handle );

Private void Draw ()

{

For (;;)

{

Render ();

}

}

Extern "C" _ declspec (dllexport) void Init (HWND hWnd );

Extern "C" _ declspec (dllexport) void Render ();

 

Void Init (HWND hWnd)

{

Int PixelFormat;

Int bits = 16;

 

HDC = GetDC (hWnd );

 

Static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be

{

Sizeof (PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor

1, // Version Number

PFD_DRAW_TO_WINDOW | // Format Must Support Window

PFD_SUPPORT_OPENGL | // Format Must Support OpenGL

PFD_DOUBLEBUFFER, // Must Support Double Buffering

PFD_TYPE_RGBA, // Request An RGBA Format

Bits, // Select Our Color Depth

0, 0, 0, 0, 0, 0, // Color Bits Ignored

0, // No Alpha Buffer

0, // Shift Bit Ignored

0, // No Accumulation Buffer

0, 0, 0, 0, // Accumulation Bits Ignored

16, // 16Bit Z-Buffer (Depth Buffer)

0, // No stencel Buffer

0, // No Auxiliary Buffer

PFD_MAIN_PLANE, // Main Drawing Layer

0, // Reserved

0, 0, 0 // Layer Masks Ignored

};

 

PixelFormat = ChoosePixelFormat (hDC, & pfd );

 

SetPixelFormat (hDC, PixelFormat, & pfd );

 

HRC = wglCreateContext (hDC );

}

 

Void Render ()

{

WglMakeCurrent (hDC, hRC );

 

Draw ();

 

SwapBuffers (hDC );

 

WglMakeCurrent (NULL, NULL );

}

Init (this. pictureBox1.Handle );

 

// Start drawing

Var timer = new System. Timers. Timer ();

Timer. Interval = 100;

Timer. Elapsed + = (tsender, te) =>

{

Render ();

};

Timer. AutoReset = true;

Timer. Enabled = true;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.