
Leadwerks integration (was: I need help converting method from Tao to OpenTK.)
Posted Wednesday, 20 May, 2009 - 23:53 by enablerbr inthis is the method i'm trying to convert from Tao to OpenTK.
public static void MakeCurrent() { Wgl.wglMakeCurrent(Wgl.wglGetCurrentDC(), Wgl.wglGetCurrentContext()); }
what is the OpenTK versions of the above Tao Wgl methods? if it helps i'm using a gamewindow.
forgot to mention i'm using svn version of OpenTK and coding in c#.


Comments
Re: I need help converting method from Tao to OpenTK.
GameWindow.MakeCurrent();OpenTK does not give you raw access to OS-specific functionality (e.g. WGL). This ensures your code remains cross-platform.
Re: I need help converting method from Tao to OpenTK.
that might be why i'm having issues with a game engine c dll. i want to us OpenTK as the OpenGL context. however this means i need to use the following command to create a buffer.
CreateCustomBuffer(byte* getsize, byte* makcurrent); <-- from the game engine c dll.i'm currently trying a safe approach by doing the following.
CreateCustomBuffer(IntPtr getsize, IntPtr makcurrent);or maybe i should do it as follows.
CreateCustomBuffer(int[] getsize, int[] makcurrent);the thing is the makecurrent part is the issue i'm having the most trouble with. if i wasn't using OpenTK for my OpenGL conext. i could use the following command from the game engine c dll.
CreateBuffer(int width, int height, BUFFER_COLOR0 | BUFFER_DEPTH | BUFFER_NORMAL);Re: I need help converting method from Tao to OpenTK.
What values do you need to pass to these parameters (getsize and makcurrent)?
In any case, you can still use the game engine to create and manage the context. On the OpenTK side, you will have to call
GraphicsContext.CreateDummyContext, which I guess is similar to CreateCustomBuffer from the C dll. You'll also won't be able to use MakeCurrent() / SwapBuffers() from OpenTK, but the C dll should be able to handle those.Disclaimer: CreateDummyContext may be slightly broken. If OpenTK complains or crashes, post the error message here and I will fix the issue. (In that case, line numbers appreciated - use the debug version of OpenTK.dll / OpenTK.pdb to obtain them.)
Re: I need help converting method from Tao to OpenTK.
i'm not sure where i would place GraphicsContext.CreateDummyContext. heres an example of how the code would look. if i was simply running a console app.
heres the code trying to do it from within the OnRenderfame.
i should add i'm trying to do this with the gamewindow example code and only changed the OnRenderframe part of it.
Re: I need help converting method from Tao to OpenTK.
A few suggestions:
OpenTK.Graphics.GLandOpenTK.Audio.AL: the code would look exactly like your first example.Here is how the code should look if you use the GameWindow:
Re: I need help converting method from Tao to OpenTK.
thanks for your time and help. the above code doesn't work in creating a custom buffer. this game engine is all about using shaders and deferred lighting renderer. the need for buffers is a must. so not being able to create them won't allow the engine to run. i really hoped it would work. so i could use window forms for creating engine tools. which would allow me to see the results as they would appear in the game engine. i'm to new to coding to go about creating my own similar game engine from scratch using OpenGL or C#.
OpenTK grabbed my attetion cause it was constantly being worked on and kept upto date compared to Tao.
Re: I need help converting method from Tao to OpenTK.
You'll have to explain more clearly what you wish to do. What is a "custom buffer"? Are you talking about an FBO? What fails? Is there an error message?
It *is* possible to make it work, but we need more information before we can help you.
Re: I need help converting method from Tao to OpenTK.
well theres no error message as such apart from "System.AccessViolationException" after the createcustom buffer part of the code. which tells me that the buffer wasn't created. as i'm new to this. explaining it maybe hard for me.
when i use createworld() that starts the game engine rendering. therefore buffers are created after that command.
here is the introduction giving by the game engine for buffers. you might understand what it is i'm trying to do with the code from this introduction.
"Render buffers are a powerful part of the Leadwerks Engine 2 renderer. Rendering is always performed on a buffer. This can take the form of a texture-based buffer with optional color, depth, and normal components, a custom buffer the user creates and manages, or the graphics window back buffer. Texture-based buffers can be drawn onto other buffers to perform post-processing effects like bloom and depth-of-field. Texture-based buffers can also be used as textures and applied to materials. This technique can be used to render reflections, or a closed-circuit camera system. "
here is what info says about CreateCustomBuffer.
"CreateCustomBuffer
NOTE: CreateCustomBuffer can vary based on which language you use.
CustomBuffers must be managed by the user. Leadwerks will only handle rendering to that buffer.
C: TBuffer CreateCustomBuffer( byte* getsize, byte* makecurrent)
C++:
virtual void Buffer::Create( int width, int height, int type = BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL)
virtual void Buffer::CreateCustom( byte* getsize, byte* makecurrent)
Pascal: function CreateCustomBuffer ( GetSize:Pointer; MakeCurrent:Pointer ): THandle;
Creates and returns a new custom buffer. GetSize and MakeCurrent are callback functions for the buffer. "
Re: I need help converting method from Tao to OpenTK.
Ok, it seems that you have to create a custom buffer. The engine API is a little strange (callback functions), but the following should work:
I've only listed the parts you need to change, according to the Leadwerks docs. The API is quite involved and the stuff with the callbacks is ugly, but I think this should work.
Re: I need help converting method from Tao to OpenTK.
is there a safe way of doing that? as i was using IntPtr instead of byte*. i hoped to avoid compiling unsafe code.
BTW OpenTK.GameWindow does not contain a definition for MakeCurrent(). least thats what VS2008 is saying.