Moin,
also ich beschäftige mich grade mit Native Code. Nun habe wollte ich von C++ aus, OpenGL initialisieren und dann in Java als Eclipse Plugin aufrufen, leider klappt das nicht, da er wenn er die Funktion schon aufruft, mit einem Unhandle Event loop Exception nervt.
Hier ist mal der etwas gekürzte Java Code:
Nun der C++ Code:
Wenn er nun die Methode InitOpenGL aufrufen soll kommt die Exception, eine Log Datei wird erstellt, aber es wird nichts reingeschrieben. Das ganze wird via JNi und dem neusten Java SDK gemacht.
MFG Lars
also ich beschäftige mich grade mit Native Code. Nun habe wollte ich von C++ aus, OpenGL initialisieren und dann in Java als Eclipse Plugin aufrufen, leider klappt das nicht, da er wenn er die Funktion schon aufruft, mit einem Unhandle Event loop Exception nervt.
Hier ist mal der etwas gekürzte Java Code:
Code:
public class NativeRenderContext
{
public native void Render(int ViewHandle);
//Load later Velox3D Dll
static
{
System.loadLibrary("JavaTest");
}
}
public void createPartControl(Composite Parent)
{
Handle = Parent.handle;
IActionBars Bar = getViewSite().getActionBars();
Action = new Action()
{
public void run()
{
Context = new NativeRenderContext();
Context.Render(Handle);
}
};
Action.setText("Velox3D Renderer");
Action.setToolTipText("Velox3D Rederer");
Bar.getToolBarManager().add(Action);
}
Nun der C++ Code:
Code:
#define WIN32_LEAN_AND_MEAN
//Includes
#include <fstream>
#include <windows.h>
#include <GL\Gl.h>
#include <GL\Glu.h>
#include "NativeRenderContext.h"
::HDC DeviceContext = 0;
::HGLRC RenderContext = 0;
std::ofstream LogFile("LogFile.log");
/*
* create OpenGL Driver
*/
void InitOpenGL(int hwnd)
{
//create Device Context
if(!(DeviceContext = ::GetDC((::HWND)&hwnd)))
{
::MessageBox(0, "OpenGL Device Context wasn't created!", "Error:", MB_OK | MB_ICONEXCLAMATION);
LogFile << "Error: OpenGL Device Context wasn't created!\n";
return;
}
else
{
LogFile << "OpenGL Device Context was created!\n";
}
::PIXELFORMATDESCRIPTOR PixelFormat;
memset(&PixelFormat, 0, sizeof(::PIXELFORMATDESCRIPTOR));
PixelFormat.nSize = sizeof(::PIXELFORMATDESCRIPTOR);
PixelFormat.nVersion = 1;
PixelFormat.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
PixelFormat.iPixelType = PFD_TYPE_RGBA;
PixelFormat.cColorBits = 32;
PixelFormat.cDepthBits = 16;
PixelFormat.iLayerType = PFD_MAIN_PLANE;
//set Pixel Format
if(!(::SetPixelFormat(DeviceContext, ::ChoosePixelFormat(DeviceContext, &PixelFormat), &PixelFormat)))
{
::MessageBox(0, "Pixel Format wasn't created and set!", "Error:", MB_OK | MB_ICONEXCLAMATION);
LogFile << "Error: Pixel Format wasn't created and set!\n";
return;
}
else
{
LogFile << "PixelFormat was created and set!\n";
}
//create Render Context
if(!(RenderContext = ::wglCreateContext(DeviceContext)))
{
::MessageBox(0, "OpenGL Render Context wasn't created!", "Error:", MB_OK | MB_ICONEXCLAMATION);
LogFile << "Error: OpenGL Render Context wasn't created!\n";
return;
}
else
{
LogFile << "OpenGL Render Context was created!\n";
}
//set Render Context
if(!(::wglMakeCurrent(DeviceContext, RenderContext)))
{
::MessageBox(0, "OpenGL Render Context wasn't set!", "Error:", MB_OK | MB_ICONEXCLAMATION);
LogFile << "Error: OpenGL Render Context wasn't set!\n";
return;
}
else
{
LogFile << "OpenGL Render Context was created!\n";
}
//Hier kommt nur unwichtiges Zeugs
}
/*
* Callback Function for Java Code
*/
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_NativeRenderContext_Render(JNIEnv *Env, jobject Object, jint Handle)
{
//create OpenGL Driver
InitOpenGL(Handle);
}
#ifdef __cplusplus
}
#endif
Wenn er nun die Methode InitOpenGL aufrufen soll kommt die Exception, eine Log Datei wird erstellt, aber es wird nichts reingeschrieben. Das ganze wird via JNi und dem neusten Java SDK gemacht.
MFG Lars