PDA

View Full Version : Render in a selected control



frozeneye
11-18-2012, 05:32 AM
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.

uwi2k2
11-18-2012, 12:27 PM
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

frozeneye
11-19-2012, 12:50 AM
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.

uwi2k2
11-19-2012, 06:04 AM
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 (http://www.facebook.com/photo.php?fbid=170009159810295&set=pb.150179405126604.-2207520000.1353329393&type=3&theater)

Dan Bartlett
11-19-2012, 07:06 AM
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.

frozeneye
11-21-2012, 04:56 AM
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.