Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Tao.Platform.Windows on Linux?

Started by Kwizatz Jan 2, 2007 at 12:39 AM 8 replies 6.9k views
Original Post
Kwizatz
Kwizatz
So, I decided to learn some C# and make a level editor at the same time. Being a cross platform entusiast, I decided to use Mono and Tao for OpenGL access, I created the prototype app on Visual Studio, later managed to compile and run it unsing Mono on Cygwin, then switched to Linux to try my luck. Initially I had problems with System.Windows.Forms, after updating Mono from 1.1.7 to 1.2 the program compiled, but when run I get this exception thrown:
Quote:
Unhandled Exception: System.EntryPointNotFoundException: GetDC at (wrapper managed-to-native) Tao.Platform.Windows.User:GetDC (intptr) at Tao.Platform.Windows.SimpleOpenGlControl.InitializeContexts () [0x00000] ...
So, after a while it hit me that it was looking for a gdi32 function (GetDC) that obviously does not exist on Linux, so this is entirelly logical, but I NEED 4 Tao.Platform.Windows.SimpleOpenGlControl objects on my form (1 perspective view, 3 ortho, the standard 3D editor layout), SDL can't do more than one window, so that is not an option, so the question is: am I doing something wrong? am I going to have to use gtk#? is there a workaround for this? I guess implementing something along the line of Tao.Platform.X11 or Tao.Platform.Mono is an option, but if I don't have to, it would be great, after all one of the reasons to use C# was to cut development time. Thanks for your time.
Rob Loach
Rob Loach
You could use SDL, or GLFW, or FreeGLUT, to make the OpenGL context, and then just render 4 different camera positions on screen.
Rob Loach [Website] [Projects] [
Kwizatz
Kwizatz
Quote:
Original post by Rob Loach
You could use SDL, or GLFW, or FreeGLUT, to make the OpenGL context, and then just render 4 different camera positions on screen.


Hi Rob,

Yes, I know that, but I rather not, thats why I mentioned SDL being able to only do one window/context at a time.

I think I'll either contribute some Xgl code or dust off a template for exactly this kind of stuff on wxWidgets that I have.

Thanks!.
vermilion_wizard
vermilion_wizard
You might take a look at OpenTK: http://sourceforge.net/projects/opentk/
It has GLX bindings and a GLContext class you can attach to a panel or something.
blanky
blanky
If you do use Gtk#, check this out.
Kwizatz
Kwizatz
Thanks guys, I think that the proper way to go about it would involve modifying both Tao.Platform and mono-winforms, I have no idea where to start beyond that, so I am gonna shelve this project for a while since currently I should really be working on my XSI model exporter anyway.

I might use Gtk# when I pick this back up, though I cringe at the thought of my LE being like GtkRadiant [headshake].
dug
dug
Yeah I asked mono folks about allowing us to to create custom winforms controls that work cross-platform and they weren't interested in that. Mono.winforms is for running plain jane windows apps, period.

So opengl controls (simpleopenglcontrol) are out unless like you said you hack your own copy of mono winforms into your custom control, or give up and use java or gtk#.
Kwizatz
Kwizatz
Quote:
Original post by dug
Yeah I asked mono folks about allowing us to to create custom winforms controls that work cross-platform and they weren't interested in that. Mono.winforms is for running plain jane windows apps, period.

So opengl controls (simpleopenglcontrol) are out unless like you said you hack your own copy of mono winforms into your custom control, or give up and use java or gtk#.


Well, I was thinking (and actually trying to get Tao to compile on my system) about moving the OpenGL Control from Tao.Platform.Windows to Tao.OpenGl, then implement Tao.Platform.X11 and have the control use one or the other depending on what platform its running on, I need help figuring out the OS at runtime though.

If anything, there is an idea [smile].
Thevenin
Thevenin
Well, this answers my question on whether the Tao.Platform library was portable.

I was about to make this very same mistake -- perhaps the Mono group should address this...

FreeGlut will not allow me to make a non-resizable window, so I cannot use that. But, I have the option of using SDL.
Kwizatz
Kwizatz
As a follow up, I finally decided to move to OpenTK, writing the code or moving it over from mono-winforms and OpenTK was too much of a hassle.

Here is the code for my custom control, I already tested the code on Linux, it works, there is a lot of testing code in, but you should be able to spot it easily:

using System;using System.ComponentModel;using System.Drawing;using System.Data;using System.Text;using System.Windows.Forms;using OpenTK.OpenGL;namespace BrickAndMortar{    public partial class GLView : UserControl    {        enum ViewType        {            Perspective,            Top,            Bottom,            Right,            Left,            Front,            Back        }        #region Private Variables        private OpenTK.OpenGL.ColorDepth cd = new OpenTK.OpenGL.ColorDepth(24);        private OpenTK.OpenGL.GLContext glc=null;        private ViewType viewType=ViewType.Perspective;        #endregion        public GLView()        {            InitializeComponent();        }        protected override void OnLoad(EventArgs e)        {            base.OnLoad(e);            if (this.DesignMode) return;            glc = OpenTK.OpenGL.GLContext.Create(this, cd, 8, 0);            glc.MakeCurrent();            OpenTK.OpenGL.GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);            OpenTK.OpenGL.GL.ShadeModel(OpenTK.OpenGL.Enums.ShadingModel.SMOOTH);            OpenTK.OpenGL.GL.Enable(OpenTK.OpenGL.Enums.EnableCap.DEPTH_TEST);            OpenTK.OpenGL.GL.Enable(OpenTK.OpenGL.Enums.EnableCap.CULL_FACE);            OpenTK.OpenGL.GL.Viewport(0, 0, Size.Width, Size.Height);            OpenTK.OpenGL.GL.MatrixMode(OpenTK.OpenGL.Enums.MatrixMode.PROJECTION);            OpenTK.OpenGL.GL.Frustum(-1.0, 1.0, -1.0, 1.0, 1.5, 40.0);            OpenTK.OpenGL.GL.MatrixMode(OpenTK.OpenGL.Enums.MatrixMode.MODELVIEW);        }        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)        {            if (this.DesignMode)            {                e.Graphics.Clear(this.BackColor);                e.Graphics.Flush();                return;            }            base.OnPaint(e);            glc.MakeCurrent();            OpenTK.OpenGL.GL.Clear(OpenTK.OpenGL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | OpenTK.OpenGL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);            OpenTK.OpenGL.GL.LoadIdentity();            OpenTK.OpenGL.GL.Translatef(-1.5f, 0.0f, -6.0f);            OpenTK.OpenGL.GL.Begin(OpenTK.OpenGL.Enums.BeginMode.TRIANGLES);            OpenTK.OpenGL.GL.Color3f(1.0f, 0.0f, 0.0f);			// Set The Color To Red            OpenTK.OpenGL.GL.Vertex3f(0.0f, 1.0f, 0.0f);			// Move Up One Unit From Center (Top Point)            OpenTK.OpenGL.GL.Color3f(0.0f, 1.0f, 0.0f);			// Set The Color To Green            OpenTK.OpenGL.GL.Vertex3f(-1.0f, -1.0f, 0.0f);			// Left And Down One Unit (Bottom Left)            OpenTK.OpenGL.GL.Color3f(0.0f, 0.0f, 1.0f);			// Set The Color To Blue            OpenTK.OpenGL.GL.Vertex3f(1.0f, -1.0f, 0.0f);			// Right And Down One Unit (Bottom Right)            OpenTK.OpenGL.GL.End();						// Done Drawing A Triangle            OpenTK.OpenGL.GL.Translatef(3.0f, 0.0f, 0.0f);			// From Right Point Move 3 Units Right            OpenTK.OpenGL.GL.Color3f(0.5f, 0.5f, 1.0f);				// Set The Color To Blue One Time Only            OpenTK.OpenGL.GL.Begin(OpenTK.OpenGL.Enums.BeginMode.QUADS);					// Start Drawing Quads            OpenTK.OpenGL.GL.Vertex3f(-1.0f, 1.0f, 0.0f);			// Left And Up 1 Unit (Top Left)            OpenTK.OpenGL.GL.Vertex3f(-1.0f, -1.0f, 0.0f);			// Left And Down One Unit (Bottom Left)            OpenTK.OpenGL.GL.Vertex3f(1.0f, -1.0f, 0.0f);			// Right And Down One Unit (Bottom Right)            OpenTK.OpenGL.GL.Vertex3f(1.0f, 1.0f, 0.0f);			// Right And Up 1 Unit (Top Right)            OpenTK.OpenGL.GL.End();						// Done Drawing A Quad            OpenTK.OpenGL.GL.Flush();            glc.SwapBuffers();        }        private void OnLoad(object sender, EventArgs e)        {        }        private void DrawGrid()        {            switch (viewType)            {                case ViewType.Top:                    break;                default:                    break;            }        }    }}


Also you'll need the following OpenTK.OpenGL.dll.config file to map the functions from opengl32.dll and glu32.dll to libGL.so and libGLU.so respectively on Linux (I copied it from Tao):
<configuration>    <dllmap dll="opengl32.dll" target="libGL.so.1" />    <dllmap dll="glu32.dll" target="libGLU.so.1" /></configuration>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.