enablerbr's picture

Leadwerks integration (was: I need help converting method from Tao to OpenTK.)

this 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#.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

To follow a slightly different approach, what *is* the difference between a custom and a plain buffer? Is there a reason why you cannot use a plain buffer (which has a more straightforward API)? The documentation doesn't make the distinction clear.

On another note, a quick google search reveals other users that have encountered the exact same issue with the Tao framework. Not sure where this leaves us, but at least the issue is not isolated.

I'll post if I can think of anything else to try.

enablerbr's picture

i have no idea but like i said before. for some reason i had used the plain buffer version on OpenTK v.0.9.6. however i deleted that code when i decided to use the svn version. i don't have the released v0.9.6 version of OpenTK. so i can't see what i did to get it working before or what has changed with the svn version.
thanks again for taking the time to try and help.

the Fiddler's picture

You can download 0.9.6 from sourceforge or get it through svn ('tags/0.9.6' instead of 'trunk'). I'd try to replace Buffer.CreateCustom with Buffer.Create(640, 480, ...) and see what happens. Other than that I'm out of ideas. Maybe someone from the Leadwerks forums could give you a pointer.

enablerbr's picture

one last thing. sometimes the code will crash at this part of the code.

public Game()
            : base()
            Window = this;

error about access violation. which is very random.

enablerbr's picture

this is the suggestion from the author of the game engine.

glBindFramebufferEXT GL_FRAMEBUFFER_EXT,Current.framebuffer 
glReadBuffer GL_BACK
glviewport 0,0,GetBuffer().width(),GetBuffer().height()
glOrtho 0,GetBuffer().width(),GetBuffer().height(),0,-1,1 
glPixelStorei GL_PACK_ROW_LENGTH,width()
glPixelStorei GL_UNPACK_ROW_LENGTH,width()

i'm now trying to convert that OpenTk. i'll assume this code goes in the OnLoad part?

convertion code.

GL.BindFramebuffer(FramebufferTarget.FramebufferExt, Current.framebuffer);  <-- not sure what to do for Current.framebuffer
            GL.Viewport(0, 0, Window.Width, Window.Height);
            GL.Ortho(0, Window.Width, Window.Height, 0, -1, 1);
            GL.PixelStore(PixelStoreParameter.PackRowLength, Window.Width);
            GL.PixelStore(PixelStoreParameter.UnpackRowLength, Window.Width);
the Fiddler's picture

I don't understand his suggestion. This code only makes sense when you create a FBO manually. The only value that makes sense for Current.framebuffer is 0, which gives you the main buffer of the context.

This doesn't really look like the code for the CreateCustomBuffer function, but rather like something SetBuffer would do.

enablerbr's picture

after i tried that. i realised it wasn't what i thought it was for.

enablerbr's picture

i just had a thought. when GameWindow creates the OpenGL context. is it creating a OpenGL V3.x context? if so would this cause issues with the engine dll. as it doesn't use OpenGL V3.x.

the Fiddler's picture

Nope, it creates a GL2.1 context by default. You have to request a 3.0+ context explicitly (there are relevant constructors).

the Fiddler's picture

The post in the Leadwerks forum may have uncovered something. Try declaring the delegates like this:

[UnmanagedFunctionPointer(CallingConvention = CallingConvention.Stdcall)]
public delegate void GetSize(int* width, int* height);
[UnmanagedFunctionPointer(CallingConvention = CallingConvention.Stdcall)]
public delegate void MakeCurrent();
[DllImport(ENGINE_DLL, EntryPoint = "CreateCustomBuffer", CallingConvention = CallingConvention.StdCall)]
internal static extern IntPtr TCreateCustomBuffer(GetSize getsize, MakeCurrent makecurrent);

In other words, apply the Stdcall calling convention to the delegates and pass the delegates directly to the TCreateCustomBuffer method.