Hello everyone I have problem with C# and passing arguments like I want pass arguments from command line or shortcut’s parameter like mygame.exe -w 1200 -h 720 -windowed
-w / -width is width of glfwWindow
-h / -height is height of glfwWindow
-windowed is glfwWindow runs in windowed mode ( like normal windowed game launcher )
Since Monday I tried to resolve glfw by Chman And I want switch fullscreen and windowed mode.
And width and height can not work.
But Console.WriteLine(); shows correct but glfwWindow doesn’t work with. Why does it happen - If I use passed arguments.
WARNING ONLY C#!
Because I am C# coder. I hate C++ because it is hard to understand with C++.
glfwWindow.cs
using Glfw3; using System; using System.Windows.Forms; namespace HL { public class glfwWindow { private int width, height; private bool fullscreen; private Glfw.Window window; private Glfw.VideoMode vid; public glfwWindow() { // lwjgl: GLFWErrorCallback.createPrint(System.err).set(); Glfw.SetErrorCallback(ErrorCallBack); if (!Glfw.Init()) throw new InvalidOperationException("Unable to initialize GLFW"); Glfw.DefaultWindowHints(); Glfw.WindowHint(Glfw.Hint.Visible, false); Glfw.WindowHint(Glfw.Hint.Resizable, false); Glfw.WindowHint(Glfw.Hint.Maximized, false); setSize(640, 480); } private void ErrorCallBack(Glfw.ErrorCode error, string description) { MessageBox.Show(description, "Error: Glfw is not initalized."); } public void createWindow(string title) { window = Glfw.CreateWindow(width, height, title, // lwjgl: "0" from fullscreen ? glfwPrimaryMonitor() : 0 in C# ´doesn't support "0" or "null" => IntPtr.Zero fullscreen ? Glfw.GetPrimaryMonitor() : Glfw.Monitor.None, null); if (window == null) { throw new InvalidOperationException("Error: Failed to create window!"); } if(!fullscreen) { // windowed mode vid = Glfw.GetVideoMode(Glfw.GetPrimaryMonitor()); Glfw.SetWindowPos(window, (vid.Width - width)/2, (vid.Height - height) / 2); }else { // fullscreen mode Glfw.SetWindowSize(window, vid.Width, vid.Height); Glfw.SetWindowPos(window, 0, 0); } Glfw.ShowWindow(window); Glfw.MakeContextCurrent(window); } public bool ShouldClose() { return Glfw.WindowShouldClose(window); } public void SwapBuffer() { Glfw.SwapBuffers(window); Glfw.PollEvents(); } public void setSize(int width, int height) { this.width = width; this.height = height; // Glfw.SetWindowSize(window, width, height); } public void setFullscreen(bool fullscreen) { this.fullscreen = fullscreen; if (!fullscreen) { // windowed mode vid = Glfw.GetVideoMode(Glfw.GetPrimaryMonitor()); Glfw.SetWindowPos(window, (vid.Width - width) / 2, (vid.Height - height) / 2); } else { // fullscreen mode vid = Glfw.GetVideoMode(Glfw.GetWindowMonitor(window)); Glfw.SetWindowPos(window, 0, 0); } } public int getWidth { get { return width; } set { width = value; } } public int getHeight { get { return height; } set { height = value; } } public bool getFullscreen { get { return fullscreen; } set { fullscreen = value; } } } }
And MyApp.cs
using OpenGL; using System; namespace HL { public class MyApp { private static glfwWindow win; private static int glfwWidth; private static int glfwHeight; private static string glfwWindowed; [STAThread] static void Main() { string[] args = Environment.GetCommandLineArgs(); win = new glfwWindow(); win.setFullscreen(true); win.createWindow("My App"); for (int i = 1; i < args.Length; i++) { switch (args[i]) { case "-width": case "-w": glfwWidth = Int32.Parse(args[i + 1]); win.setSize(glfwWidth, win.getHeight); Console.WriteLine("argument width/w is " + win.getWidth.ToString() + " " + glfwWidth); break; case "-height": case "-h": glfwHeight = Int32.Parse(args[i + 1]); win.setSize(win.getWidth, glfwHeight); Console.WriteLine("argument height/h is " + win.getHeight.ToString() + " " + glfwHeight); break; case "-windowed": glfwWindowed = "False"; if(!win.getFullscreen) { win.setFullscreen(bool.Parse(glfwWindowed)); } Console.WriteLine("argument windowed is "+win.getFullscreen.ToString()+" "+glfwWindowed); break; default: break; } } while (!win.ShouldClose()) { Gl.ClearColor(1.0f, 1.0f, 0.0f, 1.0f); win.SwapBuffer(); } } } }
If i use passed argument than console.writeline() output:
argument w/width is 1200 1200
argument h/height is 720 720
argument windowed is False False . It means win.setFullscreen(false);
If I don’t use passed argument -windowed than glfwWindow will switch into fullscreen windowed mode.
How do I fix? Thanks! I am searching very lonnger But. I don’t know glfw has forum now. I am surprised. That is why GameDev forces me.
Sorry my bad English.