I am trying to make a small 2d game in c# using the RLNET library. The RLNET library has OpenTK as a dependency, so I added the latest versions of both RLNET and OpenTK to my project using the NuGet packages manager in Visual Studio. I was following along with a tutorial explaining how to work with these libraries. But, when I got to running the code I ran into a MissingMethodException at run-time.
The tutorial I was following along with is here: https://roguesharp.wordpress.com/2016/03/02/roguesharp-v3-tutorial-creating-the-project/
The Solution Explorer shows both libraries included in the project under the References dropdown. And I also included them in my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RLNET;
using OpenTK;
namespace Rouge_Game
{
class Program
{
private static readonly int _screenWidth = 100;
private static readonly int _screenHeight = 70;
private static RLRootConsole _rootConsole;
static void Main(string[] args)
{
// This must be the exact name of the bitmap font file we are using or it will error.
string fontFileName = "terminal8x8.png";
// The title will appear at the top of the console window
string consoleTitle = "RougeSharp V3 Tutorial - Level 1";
// Tell RLNet to use the bitmap font that we specified and that each tile is 8 x 8 pixels
_rootConsole = new RLRootConsole(fontFileName, _screenWidth, _screenHeight,
8, 8, 1f, consoleTitle);
// Set up a handler for RLNET's Update event
_rootConsole.Update += OnRootConsoleUpdate;
// Set up a handler for RLNET's Render event
_rootConsole.Render += OnRootConsoleRender;
// Begin RLNET's game loop
_rootConsole.Run();
}
// Event handler for RLNET's Update event
private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e)
{
_rootConsole.Print(10, 10, "It worked!", RLColor.White);
}
// Event handler for RLNET's Render event
private static void OnRootConsoleRender(object sender, UpdateEventArgs e)
{
// Tell RLNET to draw the console that we set
_rootConsole.Draw();
}
}
}
The part of the code that has a run time error is this:
// Event handler for RLNET's Render event
private static void OnRootConsoleRender(object sender, UpdateEventArgs e)
{
// Tell RLNET to draw the console that we set
_rootConsole.Draw();
}
When I run the project it compiles with no errors and the program launches, but then throws this exception:
System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'Void
OpenTK.Graphics.OpenGL.GL.BlendFunc(OpenTK.Graphics.OpenGL.BlendingFactorSrc, OpenTK.Graphics.OpenGL.BlendingFactorDest)'.
Source=RLNET
StackTrace:
at RLNET.RLRootConsole.Draw()
at Rouge_Game.Program.OnRootConsoleRender(Object sender, UpdateEventArgs e) in C:\Users\pjmul\source\repos\Rouge Game\Rouge Game\Program.cs:line 45
at RLNET.RLRootConsole.window_RenderFrame(Object sender, FrameEventArgs e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at OpenTK.GameWindow.OnRenderFrame(FrameEventArgs e)
at OpenTK.GameWindow.RaiseRenderFrame(Double elapsed, Double& timestamp)
at OpenTK.GameWindow.DispatchRenderFrame()
at OpenTK.GameWindow.Run(Double updates_per_second, Double frames_per_second)
at OpenTK.GameWindow.Run(Double updateRate)
at RLNET.RLRootConsole.Run(Double fps)
at Rouge_Game.Program.Main(String[] args) in
C:\Users\pjmul\source\repos\Rouge Game\Rouge Game\Program.cs:line 32
I don't understand this error however as when I use the object viewer built into Visual Studio I can find the "missing" function when I open OpenTK.dll. Any suggestions as to how I might fix this error are greatly appreciated. I would also like to thank anyone who takes the time to help me in advance.
There is something wrong with the 3.x branch of OpenTK. Try downgrading your OpenTK package back to 2.x and it will work.
Related
I was trying to change the brightness of my iOS app using a text entry box, and I found some stuff online which showed me how to create a dependency service and use UIScreen to set the brightness of the app so that is what I did.
Here is the interface:
public interface IBrightnessService
{
void SetBrightness(float factor);
}
Here is the code for actually calling the setBrightness, where I'm doing it based on a Xamarin Entry form(text is inputted, and when enter is pressed this method is called).
void Entry_Completed(object sender, EventArgs e) {
var text = ((Entry)sender).Text; //cast sender to access the properties of the Entry
float value = float.Parse(text);
var brightnessService = DependencyService.Get<IBrightnessService>();
brightnessService.SetBrightness((float)value);
}
Here is the implementation in iOS. I tested some stuff, and the value is being sent correctly and the method is being reached, but the line of code UIScreen.MainScreen.Brightness = brightness; doesn't actually change UIScreen.MainScreen.Brightness, and I can't seem to figure out why, so was looking for help for this.
using Xamarin.Forms;
using UIKit;
[assembly: Dependency(typeof (iOSBrightnessService))]
public class iOSBrightnessService : IBrightnessService
{
public void SetBrightness(float brightness)
{
UIScreen.MainScreen.Brightness = brightness;
}
}
The iPhone simulator brightness is not adjustable, you have to try in a real device!
I am working on an application which requires sometimes to display an small error message on the desktop. To some reason which I could not identify yet, I was not able to create a window with a width smaller than 136px (but works fine with any larger widths).
I am running VS Community2019, v16.4.5; using .NET Framework 4.8 (.Net Framework 4.6.2 had the same result). Here's a small code example which reproduces my problem:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
namespace TestWndSize
{
public static class Program
{
public static Form MyForm1;
public static int RqWidth = 120;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MyForm1 = new Form();
MyForm1.MouseEnter += MyForm1_MouseEnter;
MyForm1.SizeChanged += MyForm1_SizeChanged;
MyForm1.AutoSize = false;
MyForm1.FormBorderStyle = FormBorderStyle.None;
MyForm1.StartPosition = FormStartPosition.Manual;
MyForm1.Location = new Point(1400, 100);
Debug.WriteLine("--- Changing Width to " + RqWidth.ToString());
MyForm1.Size = new Size(RqWidth, 100);
Debug.WriteLine("--- Width should be now " + RqWidth.ToString()+"; is "+MyForm1.Width.ToString());
MyForm1.BackColor = Color.LightBlue;
Application.Run(MyForm1);
}
private static void MyForm1_SizeChanged(object sender, EventArgs e)
{
Debug.WriteLine("*** SizeChanged to Width=" + MyForm1.Width.ToString());
}
private static void MyForm1_MouseEnter(object sender, EventArgs e)
{
Debug.WriteLine("§§§ Current Width is " + MyForm1.Width.ToString());
}
}
}
The debug output is
*** SizeChanged to Width=300
--- Changing Width to 120
*** SizeChanged to Width=120
--- Width should be now 120; is 120
*** SizeChanged to Width=136 !!??!!
*** SizeChanged to Width=136 !!??!!
§§§ Current Width is 136 *Execution of MouseEnter*
The Width is changed to the requested value but then changed somehow (???) to 136px but only if the requested value is less than 136px.
As the debug output shows the SizeChanged event is executed two times for the undesired size but I do not see any reason why.
Does anybody have an idea what I am eventually missing?
Probably during the form rendering initialization something changes the size back to a minimum required size. (It seems like the missing borders are not considered).
However you can simply change your size in the Form Load event handler and then the new values are respected
private static void MyForm1_Load(object sender, EventArgs e)
{
Debug.WriteLine("*** FormLoad to Width=" + MyForm1.Width.ToString());
MyForm1.Size = new Size(RqWidth, 100);
}
Of course you need to manually add the event handler
I'm trying to create a window and initializing a device to the window but every time I run the program the window does not load. I am doing this in visual studio 2015 for a windows forms application.
here the form1.cs:
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
namespace DirectXTutorial2
{
public partial class Form1 : Form
{
private Device device;
public Form1()
{
InitializeComponent();
InitializeDevice();
}
public void InitializeDevice()
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
}
private void Render()
{
device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 0, 1);
device.Present();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
Does anyone know of a solution to this?
I don't know if it helps but I am running windows 10, 64 bit, Directx 2010, and I have been added my references before.
okay, i have found a solution to my problem. DirectX for managed code is no longer supported by the devs. the latest framework that works for DirectX is .net Framework 3.5. managed code also does not support 64 bit. to fix this problem go to project properties. in the application tab find target framework and change your .net framework to 3.5 or less. next go to the build tab and find platform target, change this to x86.
First think use try catch in your application, because there is alot of stuff happening in DirectX, so you need to confirm the step, where you are getting error.
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
}
catch (DirectXException)
{
return false;
}
Try to use different device type like DeviceType.Software.
After clearing your device add begin and end scene
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
device.BeginScene();
device.EndScene();
device.Present();
And try calling your 'Render; function in 'Main' function
I'm trying to capture the camera feed from an EasyCap 4 Channel USB DVR Device that i got recently
and i have bought a super Mimi Monochrome/Color Camera and connected it to the DVR Device and managed to correctly setup the device with the driver "SMI Grabber" and installed the software that comes with the Device "SuperViewer"
and i have wrote a simple windows form application that contains a PictureBox to priview the camera feed
(There is an edit in the bottom)
The Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DirectX.Capture;
namespace DirectShowWithCrossbar
{
public partial class Form1 : Form
{
private CrossbarSource crossbar;
private Filters filters;
private Capture capture;
public Form1()
{
InitializeComponent();
filters = new Filters();
capture = new Capture(filters.VideoInputDevices[0], filters.AudioInputDevices[0]);
foreach (Filter device in filters.VideoInputDevices)
{
comboBox1.Items.Add(device);
}
if (comboBox1.Items.Count > 0)
comboBox1.SelectedIndex = 0;
foreach (Filter device in filters.AudioInputDevices)
{
comboBox2.Items.Add(device);
}
if (comboBox2.Items.Count > 0)
comboBox2.SelectedIndex = 0;
foreach (Source source in capture.VideoSources)
{
comboBox3.Items.Add(source);
}
if (comboBox3.Items.Count > 0)
comboBox3.SelectedIndex = 0;
ShowPropertPagesInMenuStrip();
crossbar = (CrossbarSource)capture.VideoSource;
crossbar.Enabled = true;
capture.PreviewWindow = pictureBox1;
}
private void ShowPropertPagesInMenuStrip()
{
foreach (PropertyPage pro in capture.PropertyPages)
{
menusToolStripMenuItem.DropDownItems.Add(new ToolStripMenuItem(pro.Name));
}
}
private void button1_Click(object sender, EventArgs e)
{
capture.Cue();
capture.Start();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
capture.Stop();
capture.Dispose();
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
capture.VideoSource = (Source)comboBox3.SelectedItem;
}
}
}
and i got a black screen in the picture box ??
and by mistake after closing my application i ran the SuperViewer application that comes with the DVR device and then open my application then my picture box began to show me the feed from the camera, strange!!! and the feed from the original software freezes !!
DirectX.Capture Example and Sources tried with the same result http://www.codeproject.com/Articles/3566/DirectX-Capture-Class-Library
and i have also used OpenCV and Touchless and i got the same result :(
Edit:
I have been searching and found that i need to get the filter (IAMCrossbar) i think that is the problem DirectShow USB webcam changing video source and after appling the changes in this link in the DirectX.Capture Wrapper i still get the same results :(
Thanks for any help in advance Yaser
If your capture device has option, to select one from multiple input interfaces, then yes, you are right about, that you needed to use IAMCrossbar.
If you want to stick to Directshow( as others have suggested OpenCV), then I would suggest,
Try building all capturing related code in a C++/CLI dll,
Build all your UI in C#.
You can take this MP3 Player Sample Project as starting point for your dll.
For capturing, AmCap is a detailed example.
What I mean is that you need to get the capturing code out of AmCap into above MP3 Player Sample dll, and expose it to your C# application.
ok i create new project with monodevelp and add this code :
using System;
using Gtk;
using GtkSharp;
using WebKit;
namespace browserapp
{
public class browser
{
public static void Main () {
Application.Init ();
Window window = new Window ("a browser in 12 lines...");
window.Destroyed += delegate (object sender, EventArgs e) {
Application.Quit ();
};
ScrolledWindow scrollWindow = new ScrolledWindow ();
WebView webView = new WebView ();
webView.Open ("http://mono-project.com");
scrollWindow.Add (webView);
window.Add (scrollWindow);
window.ShowAll ();
Application.Run ();
}
}
}
and i add all the reference that code need except for :
using WebKit;
and i search in monodevelop library reference and couldn't find webkit_sharp
so i searched in Google to find the library and i found this :
https://github.com/mono/webkit-sharp
but i couldn't manage how to build it in windows and extract the right dll file for reference so pls if someone can tell me how to build it in windows and i'm using mono develop the windows version thanks
You could download the suse rpm here: http://download.opensuse.org/repositories/openSUSE:/Factory/standard/noarch/webkit-sharp-0.3-7.2.noarch.rpm
It's just an archive. You could extract it and pull the dlls out. I'm not sure what you're trying to do would work though.