Using a C# form on windows

This topic contains 4 replies, has 3 voices, and was last updated by  earthquakeproof 8 years, 8 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #29667

    Hi,
    I’m wondering if someone already tried to use a window handle coming from a C# UserControl in order to use OpenGLES in a C# application. I’m currently building a UserControl in C++/CLI, all my steps are successful (eglGetDisplay, eglInitialize, eglChooseConfig, eglCreateWindowSurface, eglCreateContext) until  eglMakeCurrent, where I get a BAD_ALLOC error code.

    What could make eglMakeCurrent fail ?

    Thanks in advance,
    Earth.

    #32578

    Hello,

     

    I have to reckon that we do not use C# and we really do not know why eglMakeCurrent is failing. Possibly the context is invalid. Are you talking about WinCE or our Windows PCEmulation libraries?

     

    Regards.

     

    Carlos.
    #32579

    prabindh
    Member

    Can you please share the code that makes this happen ? Also the different threads if any.

    #32580

    prabindh
    Member

    I think you probably are not using the handles properly – Note that the device contexts are valid only within certain contexts in C#.

     

    You can try the below approach:

     

    – Do your paint handler like the below:

     

    private void pictureBox_Paint(object sender, PaintEventArgs e)

    {

    IntPtr hdc;

    hdc = e.Graphics.GetHdc();

    if(egl is not initialised)

    {

       //STEP1 – One time – Use the above HDC context for eglinitialisation

    }

    //STEP2 – Periodic draw to the window – use the above HDC again

     

    //FINAL STEP – End the context – outside this, HDC is not valid so cannot be used

    e.Graphics.ReleaseHdc(hdc);

     

    }

     

     

    Let me know if you see issues with this approach.

     
    #32581

    Thanks for all the answers!
    I already used C# handles in order to initialize DirectX rendering, and if I remember well, I used something like (hwnd) Control.Handle.IntPtr. I was not aware of valid or not device context.

    I’ll check this in a few days, back to work, and upload a csproj.

    @carlos, I’m currently testing WindowsEmulation library.
    earthquakeproof2009-02-07 11:07:04

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.