
OpenTK + ASP.NET (C#)
Posted Thursday, 16 July, 2009 - 12:15 by Dani inHi,
I am new to OpenTK and programming stuff. :) I'd like to know if someone already has experience in using OpenTK and ASP.NET together. What I'm trying to do is writing an ASP.NET Web application (using C#) that renders a scene and then shows a snapshot (e.g. in gif format) in web browser. But I can't get how to write the OpenGL code so that it runs within the web application since there is no main() function there and Form in a web applications seems to be something different than Windows.Form.
Is it possible at all to use OpenGL in this context? I'll appreciate any ideas and suggestions.


Comments
Re: OpenTK + ASP.NET (C#)
To the best of my knowledge, this hasn't been done before. You are exploring new ground here!
OpenTK requires two things to work: full trust (for platform invokes) and access to the window manager (GUI process). In other words, you should be able to host OpenTK inside an ASP.Net process iff the process runs under full trust and the server is not headless. Additionally, the process must not run as a Windows service (Vista and newer OSs do not allow services to access the window manager).
First of all, you will have to create an OpenGL context. The easiest solution is to create an empty GLControl:
The next step is to create a framebuffer object to render into. Check out the FBO OpenGL example in Examples.exe for sample code. The idea is that you create a texture, create a FBO, attach the texture to the FBO and bind the FBO for rendering.
Once the FBO is bound, you will be able to use OpenGL normally. Call
GL.Finish()once rendering is complete and readback the data from the context. The simplest solution is this (the logic is slightly more complex if you need multisampled FBOs):You can now display the resulting Bitmap or save it to disk.
Caveats:
This may sound complicated, but the actual setup is less than 20 lines of code (including error checking). Feel free to post for clarifications or additional help!
Re: OpenTK + ASP.NET (C#)
Hehe... My master's thesis was about this approach to the 3d visualization. :)
I've made applications based on:
Tomcat + Java servlets + JOGL,
Tomcat + Java servlets + LWJGL,
IIS + ASP.NET + Tao,
Apache (mod_mono) + Mono + Tao
and I've tested it on Windows and Linux... :) Lot of work but I have gained 100% for my thesis.
Best Regards