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.

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

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.

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

Have you remembered to swap buffers after drawing? If you write:

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.

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.