void COpenGLInit::InitOpenGL()
{
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|
PFD_SUPPORT_OPENGL|
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24, //24-bit color
0,0,0,0,0,0,
0,0,0,0,0,0,0,
32, //32 bit depth buffer
0,0,
PFD_MAIN_PLANE, //Main layer type
0,
0,0,0
};
HWND wnd= GetDlgItem(hWnd, IDC_OPENGL);
HDC hDC = GetDC(wnd);
GLuint PixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC,PixelFormat,&pfd);
HGLRC hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
}
Is this ok so far? I call this function in my OnInitDialog. But what is next?
Simple OpenGL / MFC Tutorial
I´m looking for hours now for a simple way to add an OpenGL control to my existing app. This app is a CDialog and I want the 3D control inside a GroupBox (IDC_OPENGL). With all tutorials I have found so far I have two problems:
1. they explain how to use the whole window as the 3D canvas
2. they are to big with lots of features I don´t need
There must be a very short and simple way. So far I created a class OpenGLInit with a standard constructor and an Init-function:
Its been a while since I've done this...
You can attach your OpenGL render context to anything with a device context. Once you have your render context attached you need to initialize your context and then draw to it. Initialization depends on what you want to draw but you must at least setup your projection matrix (see the resize code in the first tutorial). This must be done whenever your window is resized (if you dont intend on resizing your control then you only need to do this once).
After your window is initialized, you need to draw to it. How frequently you draw to it depends on how complex your control is. If there is animation, you will need to draw to it in real time. If not, you can just wait for the window repaining messages. In order to draw, you will have to override your OnPaint method and use OpenGL commands instead.
Every time you invoke gl commands you need to ensure they are directed at the correct context; this means binding the RC at the start of draw and resize calls. This is sort of a general overview, but it should get you on the right track. If you need more detail, just ask.
Cheers,
- llvllatrix
You can attach your OpenGL render context to anything with a device context. Once you have your render context attached you need to initialize your context and then draw to it. Initialization depends on what you want to draw but you must at least setup your projection matrix (see the resize code in the first tutorial). This must be done whenever your window is resized (if you dont intend on resizing your control then you only need to do this once).
After your window is initialized, you need to draw to it. How frequently you draw to it depends on how complex your control is. If there is animation, you will need to draw to it in real time. If not, you can just wait for the window repaining messages. In order to draw, you will have to override your OnPaint method and use OpenGL commands instead.
Every time you invoke gl commands you need to ensure they are directed at the correct context; this means binding the RC at the start of draw and resize calls. This is sort of a general overview, but it should get you on the right track. If you need more detail, just ask.
Cheers,
- llvllatrix
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement