I am using Pencil.Gaming as the C# Wrapper for the OpenGL functions. I wanted to write a quite application to get the OpenGL renderer and version information but I can't seem to find the Macros for these (GL_RENDERER and GL_VERSION).
Has anyone used Pencil.Gaming or another C# wrapper before and used these or similar macros? Where are they located? Or is there another way to get this information with the wrapper?
Here's the code I have so far:
using System;
using Pencil.Gaming;
using Pencil.Gaming.Graphics;
using GLubyte = System.Byte;
namespace C_Sharp_OpenGL
{
class Program
{
static void Main(string[] args)
{
if (!Glfw.Init()){
Console.WriteLine("ERROR: Could not start GLFW3");
Console.WriteLine("Press Any Key to Continue...");
Console.ReadKey();
Environment.Exit(-1);
}
GlfwWindowPtr window = Glfw.CreateWindow(640, 480, "Hello Triangle", GlfwMonitorPtr.Null, GlfwWindowPtr.Null);
Glfw.MakeContextCurrent(window);
//Get Version Info
GLubyte renderer = GL.GetString(GL_RENDERER); //Doesn't Work
Glubyte version = GL.GetString(GL_VERSION); //Doesn't Work
}
}
}
Related
I am developing .net maui app that measures sound volume and sends it with bluetooth to pc that logs data and makes graph as a hobby project. My problem is accesing microphone input. There seems to be no multiplatform way to do this in maui. So i tried to do it using platform specific android api, but when I tried so, it seemed like class that I needed was not fully implemented in maui Android namespace.
The part of my code I have trouble with is this:
using Android.Media;
using Java.Util;
public static class MicIn
{
static MediaRecorder mRecorder;
// Other functions
public static void startRecorder()
{
if (mRecorder == null)
{
mRecorder = new MediaRecorder();
mRecorder.SetAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.SetOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.SetAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.SetOutputFile("/dev/null");
try
{
mRecorder.Prepare();
}
catch (Java.IO.IOException ioe)
{
Debug.WriteLine("IO exception");
}
catch (Java.Lang.SecurityException e)
{
Debug.WriteLine("Security exception");
}
try
{
mRecorder.Start();
}
catch (Java.Lang.SecurityException e)
{
Debug.WriteLine("Security exception");
}
}
}
}
Visual studio gives me errors on MediaRecorder.AudioSource.MIC, MediaRecorder.OutputFormat.THREE_GPP and MediaRecorder.AudioEncoder.AMR_NB
It says that these classes do not have definition for MIC, THREE_GPP and AMR_NB constants, even if they are in official android api documentation.
Do you have any ideas what might be error or other ways of taking microphone input in .net maui? Thank you for help.
according to the docs
AudioSource Mic
OutputFormat ThreeGpp
AudioEncoder AmrNb
This is my current code, it works but it restarts the Explorer process and that's kinda weird.
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32;
namespace MyApp
{
class Program
{
static async Task Main(string[] args)
{
ShowSmallTaskbarIcons();
// ShowLargeTaskbarIcons();
Console.WriteLine("Press a key to exit...");
Console.ReadKey();
}
static void ShowSmallTaskbarIcons()
{
Registry.SetValue(#"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSmallIcons", "1", RegistryValueKind.DWord);
RefreshExplorer();
}
static void ShowLargeTaskbarIcons()
{
var key = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", writable: true);
key.DeleteValue("TaskbarSmallIcons", throwOnMissingValue: false);
key.Close();
RefreshExplorer();
}
static void RefreshExplorer()
{
Process.Start("taskkill.exe", "/f /im explorer.exe");
Thread.Sleep(2000);
Process.Start("explorer.exe");
Thread.Sleep(10000);
}
}
}
I would like to do the same as with the "Use small taskbar buttons" toggle switch from Settings.
How to do the same with C#?
How to change Windows 10 taskbar icon size programmatically
This post has an example about how to send WM_SETTINGCHANGE message in c++.
However, there is no easy way to do it in c# wrapped function. You have to do it through p/invoke
Following post will help you do it in c#
convert C++ code to C#: SendMessageTimeout()
I have these requirements coming from client every week for some new logic or verification. For which I have to code new logic (basically some if-else and loops) and launch a new build for him. I want to avoid it by simply coding my logic in visual studio then writing a utility to export it to XML or something and send it to client via e-mail. He just have to place this file in some appropriate folder and the application will behave considering this logic.
Please suggest some solutions. My platform is C# Asp.Net.
Thanks
Using .NET 4.6 and the NuGetPackage Microsoft.CodeAnalysis.Scripting you could implement a scripting engine to run your c# code residing in a textfile without building an assembly.
Install NuGet Package:
Install-Package Microsoft.CodeAnalysis.Scripting.CSharp
Implement TestClass with some basic C#-Code-Content:
class Program
{
static void Main(string[] args)
{
TestScript();
}
private static async void TestScript()
{
// Code snippet: a class with one string-property.
string codeContent = #" using System;
public class ScriptedClass
{
public string HelloWorld { get; set; }
public ScriptedClass()
{
HelloWorld = ""Hello Roslyn!"";
}
}
new ScriptedClass().HelloWorld";
// Instanciate CSharpScriptEngine
var engine = new CSharpScriptEngine();
// Execute code and return string property (HelloWorld)
var scriptingState = await engine.ExecuteAsync(codeContent);
// Print return value from CSharpScript
Console.WriteLine("Returned from CSharpScript: {0}", scriptingState.ReturnValue);
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
}
Implement a ScriptingEngine:
internal sealed class CSharpScriptEngine
{
public async Task<ScriptState<object>> ExecuteAsync(string codeContent)
{
// Add references from calling assembly
ScriptOptions options = ScriptOptions.Default.AddReferences(Assembly.GetExecutingAssembly());
// Run codeContent with given options
return await CSharpScript.RunAsync(codeContent, options);
}
}
Read ScriptCode from textfile:
So basically you could read some csharpcode from a textfile of your choice and run them on the fly:
private static async void TestScript()
{
// Read in script file
string codeContent = File.ReadAllText(#"C:\Temp\CSharpScriptTest.cs");
var engine = new CSharpScriptEngine();
// Run script
var scriptingState = await engine.ExecuteAsync(codeContent);
Console.WriteLine("Returned from CSharpScript: {0}", scriptingState.ReturnValue);
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
In case you are wondering how all of this works under the hood, Roslyn will create a so called submission from your script code. A submission is an in memory assembly containing the types generated around your script code, which can be identified among the assemblies in the current AppDomain by a ℛ prefix in the name.
The precise implementation details are not important here (though, for example, scriptcs heavily relies on understanding in detail how Roslyn works to provide its extra features), but it's important to know that submissions can be chained together. When they are chained, variables, methods or classes defined in an earlier submission are available to use in subsequent submissions, creating a feature of a C# REPL (read-evaluate-print loop).
C# and Visual Basic - Use Roslyn to Write a Live Code Analyzer for Your API
Hope it helps
after along time of searching via google, I decided to poste my problem here.
First: I am total C# Noob. I am using a Macro Recorder from Jitbit and I have no choice to use a different. The Problem is in the Macro Recorder, it is missing some essential things.
Like reading a text file into a variable and paste this variable via Clipboard :-(
However the good thing is, the tool support "some" type of native C# Code
If I open the C# Command I get this:
public class Program
{
public static void Main()
{
System.Windows.Forms.MessageBox.Show("test");
}
}
And the C# program has to follow also these rules:
=> This Code MUST contain a class named "Program" with a static method "Main"
I already used google and found code that should do the job but I get errors, I guess the
code doesn`t follow the above rules.
This is what I found and tried:
using System;
using System.IO;
public class Program
{
public static void Main()
{
// Read the file as one string.
System.IO.StreamReader myFile =
new System.IO.StreamReader("Counter.txt");
string counter = myFile.ReadToEnd();
myFile.Close();
// Load string into clipboard
Clipboard.SetDataObject( counter, true );
}
}
I always get the error : "Line 15: The Name Clipboard is not existing in the context"?!?
I hope that someone can explain a noob (me) what is wrong and what is the correct code.
Thanks.
add reference to System.Windows.Forms
using System;
using System.IO;
using System.Windows.Forms;
public class Program
{
[STAThread]
public static void Main()
{
Clipboard.SetDataObject(File.ReadAllText("Counter.txt"), true);
}
}
Note that to Avoid the ThreadStateException you need to applying the STAThread attribute to your Main() function
I want to run the Skeinforge slicer program written in Python inside my Windows Phone 8 C# application. I have determined that I should probably use IronPython to do this, I have already determined that I can run Skeinforge inside the ipy.exe terminal I got when I installed IronPython. My problem though is that I am struggling to figure out how to host and run a Python script with IronPython inside Windows Phone 8. I have also already managed to get a simple hello world script running inside a Desktop Windows Forms application that transfers the applications console output to the Debug console with the following 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 System.Diagnostics;
using System.IO;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DebugWriter debugW = new DebugWriter();
Console.SetOut(debugW);
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter tw = new StreamWriter("Test.py");
tw.Write(scriptBox.Text);
tw.Close();
try
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("Test.py");
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
}
}
And this is the DebugWriter:
class DebugWriter : TextWriter
{
private StringBuilder content = new StringBuilder();
public DebugWriter()
{
Debug.WriteLine("Writing console to debug");
}
public override void Write(char value)
{
base.Write(value);
if (value == '\n')
{
Debug.WriteLine(content.ToString());
content = new StringBuilder();
}
else
{
content.Append(value);
}
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
I have no idea how to even add the IronPython libraries to my Windows Phone 8 application though as the standard libraries won't import. I have though tried compiling the apparently now defunct Windows Phone 7 libraries with the master source code and I can import these libraries, but I get absolutely no response on the debug terminal when I try to run my hello world script.
Do any of you have any idea how to get this woring in Windows Phone 8, if you know how to do this in Windows 8/Metro/RT then that would also probably work for WP8.
UPDATE:
I have looked at the debug output again and I seem to get this error when trying to use the WP7 libraries to run a hello world script:
A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.Scripting.DLL
Error: The method or operation is not implemented.
I managed to get Skeinforge running on a modified version of IPY. You can get the source for my application here: http://skeinforgewp8.codeplex.com/