Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Render in a selected control

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    3

    Render in a selected control

    Hi, I am new in openGl. How can I render my glut scene in selected windows form control. For instance I have a panel in my form and I want my scene to shown in that panel.

  2. #2
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    98
    hi,

    the answer would be longer then you may expect.
    but the basic is: you need a DeviceContect propperbly set up for Open GL .. so a opengl Context.
    You may google this topic to find a complex introduction.

    cu
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    3
    I have googled the topic. I tried many things but nothing shown on my panel. Here is the part of my code


    mhWnd = (HWND)mainControlToRender.ToPointer();

    mhDC = GetDC( mhWnd );

    // set the pixel format for the DC
    PIXELFORMATDESCRIPTOR pfd;
    ZeroMemory( &pfd, sizeof( pfd ) );
    pfd.nSize = sizeof( pfd );
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
    PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    int format = ChoosePixelFormat( mhDC, &pfd );
    SetPixelFormat( mhDC, format, &pfd );

    // create the render context (RC)
    Class1::mhRC = wglCreateContext( mhDC );

    // make it the current render context
    wglMakeCurrent( mhDC, mhRC );


    Could anyone say what is wrong? I am developing my OpenGL class in C++/CLR and use that dll in my C# project.

  4. #4
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    98
    Hi,

    this looks basicly right, but there are so many OpenGL settings that may leed to the fact that you canīt see anything.
    my hint would be.
    cut out your opengl part into a simple c++ / opengl programm running in the full window.
    when you are shure its showing correctly in this version move it back to the programm that should only show in a pannel.
    we could help you mutch better with this 'only opengl' version.

    cu
    uwi

    btw.
    say hello to Hugo: http://www.facebook.com/photo.php?fbid=170009159810295
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  5. #5
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    455
    Have you remembered to swap buffers after drawing? If you write:
    Code :
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    SwapBuffers(mhDC);

    does the control turn red? If not have you checked that the context is created successfully? i.e. Is mhRC != NULL ?

    Also, SetPixelFormat can only be called once for a window so if it's called elsewhere and sets a pixel format that doesn't support OpenGL, then you will need to recreate the window to set a pixel format that does support OpenGL.



  6. #6
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    3
    In my c# app I call my cli method as myObject.initWin(panel1.Handle);
    I gave my code above. It seems correct but nothing happens in panel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •