PDA

View Full Version : C# and volume render with glTexImage3D



szamil
01-12-2009, 01:23 PM
Hi

Can anyone provide me with any example of volume rendering in C# using glTexImage3D method? I've tried to do it myself, but stucked with exception, that nothing says to me... :sorrow:

I'm using Visual Studio 2008 (Windows XP), tried Tao, csgl and NeHe codes...
I'm sure to have support of volume render. My video card is nVidia Quadro FX 1600M.

I found the http://gpwiki.org/index.php/OpenGL:Tutorials:3D_Textures , which is something I need, but I couldn't rewrite it to C#...

I'd be really grateful for any help.

PS.

Hello to everyone! :)

martinsm
01-12-2009, 02:09 PM
With what kind an exception do you have stucked? And on what code?

szamil
01-12-2009, 02:49 PM
Exception:

System.Reflection.TargetInvocationException was unhandled
Message="Obiekt docelowy wywołania zgłosił wyjątek."
Source="mscorlib"
StackTrace:
w System.RuntimeMethodHandle._InvokeMethodFast(Objec t target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
w System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
w System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
w System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
w System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
w System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
w NeHe.NeHe.SelectExample() w C:\Program Files\TaoFramework\source\examples\NeHe\NeHe.cs:wi ersz 73
w NeHe.NeHe.lstExamples_SelectedIndexChanged(Object sender, EventArgs e) w C:\Program Files\TaoFramework\source\examples\NeHe\NeHe.cs:wi ersz 79
w System.Windows.Forms.Control.OnDoubleClick(EventAr gs e)
w System.Windows.Forms.ListBox.WndProc(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
w System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
w System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
w System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
w System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.Run(Form mainForm)
w NeHe.Program.Main() w C:\Program Files\TaoFramework\source\examples\NeHe\Program.cs :wiersz 44
w System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
w System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
w Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
w System.Threading.ThreadHelper.ThreadStart_Context( Object state)
w System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
w System.Threading.ThreadHelper.ThreadStart()
InnerException:
Message="BŁĄD!\r\n w Tao.OpenGl.Gl.Imports.ActiveTexture(Int32 texture)\r\n w Tao.OpenGl.Gl.glActiveTexture(Int32 texture)\r\n w NeHe.Lesson05.build_texture() w C:\\Program Files\\TaoFramework\\source\\examples\\NeHe\\Lesso n05.cs:wiersz 460"
Source="NeHe"
StackTrace:
w NeHe.Lesson05.build_texture() w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 476
w NeHe.Lesson05.InitGL() w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 420
w NeHe.Lesson05.CreateGLWindow(String title, Int32 width, Int32 height, Int32 bits, Boolean fullscreenflag) w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 317
w NeHe.Lesson05.Run() w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 136
InnerException:

I was editing some NeHe tutorials.
Message = "Target object of the call throws an exception"

Debugger report it here:

private void SelectExample()
{
if (lstExamples.SelectedItem != null)
{
Type example = Assembly.GetExecutingAssembly().GetType("NeHe." + lstExamples.SelectedItem.ToString(), true, true);
example.InvokeMember("Run", BindingFlags.InvokeMethod, null, null, null); /*Highlighted by debugger*/
}
}

but after investigation I found that problem is line when i try to generate texture3d:


Gl.glTexImage3D(Gl.GL_TEXTURE_3D, 0, (int)Gl.GL_RGB8, 1, 1, 1, 1, Gl.GL_BGR_EXT, Gl.GL_UNSIGNED_BYTE, IntPtr.Zero);

I hope all parameters are alright... Otherwise exception would point it.

But anyway I would prefer just a simple example of glTexImage3D.

Thanks for replying!

martinsm
01-12-2009, 03:47 PM
Are you sure it is glTexImage3D which is guilty?
Your exception has following information on InnerException member:

Message="BŁĄD!\r\n w Tao.OpenGl.Gl.Imports.ActiveTexture(Int32 texture)\r\n w Tao.OpenGl.Gl.glActiveTexture(Int32 texture)\r\n w NeHe.Lesson05.build_texture() w C:\\Program Files\\TaoFramework\\source\\examples\\NeHe\\Lesso n05.cs:wiersz 460"
Source="NeHe"
StackTrace:
w NeHe.Lesson05.build_texture() w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 476

What is on 476 line in Lesson05.cs ?
I think you have there some problem with glActiveTexture call.

szamil
01-13-2009, 05:49 AM
Oh.. sorry.. I'v been doing some changes and put wrong exception stack trace.. :stupid:

This one comes exacly when I uncomment the line with glTexImage3D


System.Reflection.TargetInvocationException was unhandled
Message="Obiekt docelowy wywołania zgłosił wyjątek."
Source="mscorlib"
StackTrace:
w System.RuntimeMethodHandle._InvokeMethodFast(Objec t target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
w System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
w System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
w System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
w System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
w System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
w NeHe.NeHe.SelectExample() w C:\Program Files\TaoFramework\source\examples\NeHe\NeHe.cs:wi ersz 73
w NeHe.NeHe.lstExamples_SelectedIndexChanged(Object sender, EventArgs e) w C:\Program Files\TaoFramework\source\examples\NeHe\NeHe.cs:wi ersz 79
w System.Windows.Forms.Control.OnDoubleClick(EventAr gs e)
w System.Windows.Forms.ListBox.WndProc(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
w System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
w System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
w System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
w System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.Run(Form mainForm)
w NeHe.Program.Main() w C:\Program Files\TaoFramework\source\examples\NeHe\Program.cs :wiersz 44
w System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
w System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
w Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
w System.Threading.ThreadHelper.ThreadStart_Context( Object state)
w System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
w System.Threading.ThreadHelper.ThreadStart()
InnerException:
Message="BŁĄD!\r\n w Tao.OpenGl.Gl.Imports.TexImage3D(Int32 target, Int32 level, Int32 internalformat, Int32 width, Int32 height, Int32 depth, Int32 border, Int32 format, Int32 type, IntPtr pixels)\r\n w Tao.OpenGl.Gl.glTexImage3D(Int32 target, Int32 level, Int32 internalformat, Int32 width, Int32 height, Int32 depth, Int32 border, Int32 format, Int32 type, IntPtr pixels)\r\n w NeHe.Lesson05.build_texture() w C:\\Program Files\\TaoFramework\\source\\examples\\NeHe\\Lesso n05.cs:wiersz 461"
Source="NeHe"
StackTrace:
w NeHe.Lesson05.build_texture() w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 476
w NeHe.Lesson05.InitGL() w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 420
w NeHe.Lesson05.CreateGLWindow(String title, Int32 width, Int32 height, Int32 bits, Boolean fullscreenflag) w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 317
w NeHe.Lesson05.Run() w C:\Program Files\TaoFramework\source\examples\NeHe\Lesson05.c s:wiersz 136
InnerException:


Realy noone have done some 3d texturing??

szamil
01-16-2009, 01:01 AM
OK, I manage to compile program with TexImage3D in C++, but I realy hope somehow it's possible also in C#. Any ideas?

Maybe the problem is the last parameter, texel data, IntPtr pixels? But would it throw different exception?

Brolingstanz
01-16-2009, 07:59 AM
Sorry, szamil, but what was your question again?

There's lots of info on interop marshaling in the MSDN docs if you're having trouble in that area. There are also several open source .NET libraries that wrap all this stuff up for you, like Tao.

Stephen A
01-16-2009, 09:25 AM
Make sure you are using the latest version of Tao.OpenGl.dll (2.1.0.12, IIRC), because older ones didn't marshal TexImage3D correctly.