Hi, I'm making a basic program in C# wich calls a C++ dll. I give the pannel's handle to the dll so OpenGL knows where to draw.
[DllImport(@"../../../Debug/Model.DLL")]
public static extern void startOpenGL(IntPtr hWindow);
I mashall IntPtr hWindow to HWND hWindow.
after I call draw from C#
[DllImport(@"../../../Debug/Model.DLL")]
public static extern void draw();
In C++ I have a class interface that works (tested it) that calls my OpenGLManager's methods.
#pragma once
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "singleton.h"
class OpenGLManager
{
public:
static OpenGLManager* instance()
{
if ( p_theInstance == 0 )
p_theInstance = new OpenGLManager;
return p_theInstance;
}
void init(HWND hWnd);
void purge();
void reset();
void showSomething();
private:
HWND mhWnd;
HDC mhDC;
HGLRC mhRC;
static OpenGLManager* p_theInstance;
OpenGLManager(void);
~OpenGLManager(void);
};
the .cpp
#include "OpenGLManager.h"
#include <stdio.h>
OpenGLManager* OpenGLManager::p_theInstance = 0;
OpenGLManager::OpenGLManager(void)
{
reset();
}
OpenGLManager::~OpenGLManager(void)
{
purge();
}
void OpenGLManager::showSomething()
{
//MessageBox(NULL,"DRAW","DRAW", MB_OK);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_TRIANGLES);
glVertex3f(-1.0f, -0.5f, -4.0f); // lower left vertex
glVertex3f( 1.0f, -0.5f, -4.0f); // lower right vertex
glVertex3f( 0.0f, 0.5f, -4.0f); // upper vertex
glEnd();
glFlush();
}
void OpenGLManager::init(HWND hWnd)
{
// remember the window handle (HWND)
OpenGLManager::mhWnd = hWnd;
// get the device context (DC)
OpenGLManager::mhDC = GetDC( OpenGLManager::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( OpenGLManager::mhDC, &pfd );
SetPixelFormat( OpenGLManager::mhDC, format, &pfd );
// create the render context (RC)
OpenGLManager::mhRC = wglCreateContext( OpenGLManager::mhDC );
// make it the current render context
wglMakeCurrent( OpenGLManager::mhDC, OpenGLManager::mhRC );
}
void OpenGLManager::purge()
{
if ( OpenGLManager::mhRC )
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( OpenGLManager::mhRC );
}
if ( OpenGLManager::mhWnd && OpenGLManager::mhDC )
{
ReleaseDC( OpenGLManager::mhWnd, OpenGLManager::mhDC );
}
reset();
}
void OpenGLManager::reset()
{
OpenGLManager::mhWnd = NULL;
OpenGLManager::mhDC = NULL;
OpenGLManager::mhRC = NULL;
}
I see that the ShowSomething method is called often with messageBoxes but I see nothing on my C# pannel. (Sorry for wierd indentations!)