Dibujo de Opengl en Visual C++
Publicado por J.A (1 intervención) el 28/09/2001 18:55:10
Me gustaria saber si es posible mostrar 2 opengl distintos en un mismo cuadro de dialogo simultaneamente.
Valora esta pregunta


0
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <afxwin.h>
class CMyOpenGLView : public CWnd {
public:
HGLRC m_hRC; // OpenGL Rendering Context
HDC m_hDC; // Device Context
CMyOpenGLView() {
// Constructor
}
BOOL CreateOpenGLContext() {
// Crear el contexto OpenGL
m_hDC = GetDC(m_hWnd);
PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int pixelFormat = ChoosePixelFormat(m_hDC, &pfd);
SetPixelFormat(m_hDC, pixelFormat, &pfd);
m_hRC = wglCreateContext(m_hDC);
wglMakeCurrent(m_hDC, m_hRC);
return TRUE;
}
void Render() {
// Renderizar OpenGL
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Aquí va tu código de renderizado
SwapBuffers(m_hDC);
}
void Cleanup() {
// Limpiar el contexto OpenGL
wglMakeCurrent(m_hDC, NULL);
wglDeleteContext(m_hRC);
ReleaseDC(m_hWnd, m_hDC);
}
protected:
afx_msg void OnPaint() {
Render();
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMyOpenGLView, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
class CMyDialog : public CDialog {
public:
CMyOpenGLView m_view1;
CMyOpenGLView m_view2;
CMyDialog() : CDialog(IDD_MY_DIALOG) {}
BOOL OnInitDialog() {
CDialog::OnInitDialog();
// Crear los controles OpenGL
m_view1.Create(NULL, CRect(10, 10, 300, 300), _T("OpenGL View 1"), WS_CHILD | WS_VISIBLE, this->m_hWnd);
m_view1.CreateOpenGLContext();
m_view2.Create(NULL, CRect(310, 10, 600, 300), _T("OpenGL View 2"), WS_CHILD | WS_VISIBLE, this->m_hWnd);
m_view2.CreateOpenGLContext();
return TRUE;
}
void OnDestroy() {
m_view1.Cleanup();
m_view2.Cleanup();
CDialog::OnDestroy();
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_WM_DESTROY()
END_MESSAGE_MAP()
class CMyApp : public CWinApp {
public:
BOOL InitInstance() {
CMyDialog dlg;
m_pMainWnd = &dlg;
dlg.DoModal();
return FALSE;
}
};
CMyApp theApp;