Git Product home page Git Product logo

opengl4csharp's People

Contributors

giawa avatar rdpbooooooom avatar signalwalker avatar theaibot avatar therealnoig avatar wardbenjamin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opengl4csharp's Issues

Shader Uniform Arrays

Is there any way to set a shaders uniform arrays.
e.g.
glsl:
uniform vec3 lightPositions[10];

c#:
i can reference the array using shaderProgram["lightPositions[0]"], but i can only set the first value.
shaderProgram["lightPositions[1]"] or shaderProgram["lightPositions[]"] returns null.

Unable to find an entry point named 'glGenBuffers' in DLL 'opengl32.dll

Hello again,
After not being able to fix my previous issue, losing my project, and deciding to use Glut, i began a new project. In this i have gotten no issues until i try to create a VBO. Any time i do i get this error "Unable to find an entry point named 'glGenBuffers' in DLL 'opengl32.dll"

Here is the code i have been using:
vertices = new VBO<Vector3>( new Vector3[] { new Vector3(-0.5f, 0.5f, 0f), new Vector3(0.5f, 0.5f, 0) , new Vector3(0.5f, -0.5f, 0), new Vector3(-0.5f, -0.5f, 0) } );

Thanks in advanced!!!

EDIT: I have search online for a solution and updated my graphics card drivers.

EDIT2: it was a stupid mistake. I forgot to put GL.ReloadFunctions and Gl.ReloadExtensions after i created the window.

Unhandled Exception when closing program

Hello Giawa,
I seem to have run into the same problem as issue #13 using Visual Studio 2019 and the example code in a console application. It happens when the application is closed and i am not sure but when I try to step into the Delegates.glDeleteVertexArray(n, arrays) function I get the System.AccessViolationException. Since Delegates is a class of internal delegates I have no idea where they are pointing to. Since jchand99 has not published any solution I am a bit in the dark here about what is happening.

Could you please be of any assistance?

With regards,
Michel

Program.txt

P.S. it seems to start acting up when I add the line for the new ShaderProgram. If I don't attach those and not paint the cube nothing is wrong. If I add the line for the ShaderProgram it gives this exception. I don't need to draw the cube to trigger it.

P.P.S. sorry for also adding this to the old issue, as I later realised it isn't proper practice to revive old issues.

Unable to run on Linux with Mono

Unable to run my program in Linux using mono.
I get an exception that OpenGL cannot find systemDLL opnegl32.dll

/Debug$ mono Test2.exe
Creating OpenGL instance

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'OpenGL.Gl' threw an exception. ---> System.DllNotFoundException: opengl32.dll
  at (wrapper managed-to-native) OpenGL.Gl+NativeMethods.glxGetProcAddress(string)
  at OpenGL.Gl+GetProcAddressX11.GetProcAddress (System.String function) [0x00000] in <118e14bf4e6e43458e7031331eb2b4d0>:0 
  at OpenGL.Gl.GetAddress (System.String function) [0x0005a] in <118e14bf4e6e43458e7031331eb2b4d0>:0 
  at OpenGL.Gl.GetExtensionDelegate (System.String name, System.Type signature) [0x00000] in <118e14bf4e6e43458e7031331eb2b4d0>:0 
  at OpenGL.Gl.GetDelegate (System.String name, System.Type signature) [0x00000] in <118e14bf4e6e43458e7031331eb2b4d0>:0 
  at OpenGL.Gl.ReloadFunctions () [0x0007b] in <118e14bf4e6e43458e7031331eb2b4d0>:0 
  at OpenGL.Gl..cctor () [0x0007f] in <118e14bf4e6e43458e7031331eb2b4d0>:0 
   --- End of inner exception stack trace ---
  at OpenGL.Platform.Window.CreateContextFromWindow (System.IntPtr window, System.Boolean fullscreen) [0x00049] in <1a9c11f978ab4564b09d050cd056057e>:0 

rendering more than one shape with out writing them separately

How do you render more than on shape with out writing them out separately like in the tutorial. I made a class to handle what you wrote out manually for each shape and it does not work only one shape shows in the window. I am trying to eventually fill the whole window with baby blue textures as a background with an algorithm. I dont see that possible.

Shape2d image

Shapefactory image

draw shape image

draw shapes image

createDisplay

More than one shape

Shadowmapping

Hi, great job !!. There is an example of How to make Shadows with your engine. I mean Shadowmapping. I been trying without any success. Thank you.

Create More than one screen

It seems Glut and Platform can only create one instance of a window because they are singletons. Is there anyway to instantiate more than one window?

How to subscribe key events to special keys?

Most games use special keys to do certain actions, like sprinting with the left shift key.
How can I bind an event to a special key? I tried binding the event to every key from 0 to 256 using OpenGL.Platform.Input.Subscribe, but shift still did nothing.

animating a prism

I intend to animate my rectangle I noticed you were using Visual Studio 2015 and I am using VS2022 and the interface and layout is different but using the following matrices as an example
Matrix4 model = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-55.0f));
Matrix4 view = Matrix4.CreateTranslation(0.0f, 0.0f, -3.0f);
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45.0f), Width / Height, 0.1f, 100.0f);

I have a rectangle and I want to transform it into a 3D, for a start I want to animate it as you did in your tutorial 4 and then change it to 3D as a cube or cuboid. I want to know where I need to which class store the view, model, and projection matrices and how to bind them and send them to the shader. Let me know if I can share my code with you.

Glut Window Dimensions is not scaled to Vector2 or Vector3

The top right corner of a window with width 1200 and height of 720 has a vector2 coordinate at about (36, 21). is this correct? If Vector2.Zero is the center of the window shouldnt the top right corner be Vector2(600, 360)? If the origin of the Window was at the the bottom left corner wouldn't the top right corner be Vector2(1200, 720)?

VAO support for instanced drawing.

Currently the VAO class only supports drawing with Gl.DrawElements. I would like a way to draw instanced. Because it's hardcoded into the VAO that there is an indice buffer(i like this btw) you would need to call Gl.DrawElementsInstanced to support it.

I made a working solution that uses the VAO class to draw instanced but in doing so i came across a design issues i think should be thought out some more.

To begin with a VBO needs to have concept of a division factor which is used when drawing instanced. So to solve this i added the divisor as a constructor argument like this.
public VBO(T[] Data, uint Divisor, BufferTarget Target = OpenGL.BufferTarget.ArrayBuffer, BufferUsageHint Hint = BufferUsageHint.StaticDraw)
The problem is that there already exists a constructor like this.
public VBO(T[] Data, int Length, BufferTarget Target = BufferTarget.ArrayBuffer, BufferUsageHint Hint = BufferUsageHint.StaticDraw)
The only difference between these two constructors is the second argument. In the first one it's an uint and in the second one it's an int. It would be extremely easy to mix up those two which would cause some hard to catch bugs. If the divisor should be part of the constructor then it should set itself more apart than that but i am not sure how i would go about doing it.
Not sure if the divisor should even be part of the constructor, but if it isn't then that causes its own problems.

Adding Windows code to Gl class

I want to add WGL/GDI/User32 code to the Gl class, separated by a conditional symbol, ISWINDOWS, so that you can create an OpenGL window without having to use someone else's context.
Inside of OpenGL.Platform or the OpenGL.Constructs folder, we could add a default Win32 context window.
Other people would have to add GLX/CGL for Mac/Linux support, as I don't have a Mac or Linux system to test it on.

What do you think of me adding it and making a pull request? I want to see what you guy's think of it before I take the effort to write it.

Updating a VBO?

Hi,
I have been following all of your tutorials and using your library with freeglut. It's been great for a C# programmer. However I have now run into something I cannot figure out.
I am using your program to draw a pyramid for an example. I would like to update the vertices of the pyramid on a regular basis. I cannot figure out how to do this. I know I have to change the pyramid VBO, but how does one do this? Also how do I call glMapBuffer which I believe I need to use to update only the VBO? I figure if I can solve this, your library will do everything I need.
Thanks, Tom

Detect if platform is not supported

Hey Giawa,

I've been working on a game development framework using SDL and your OpenGL bindings, and was wondering if you had any input on detecting if any OpenGL features are not supported on a device. Essentially, is there a way to detect if any of the dll references that you do here fail, without crashing? I'm asking this because I want to support GL3 as well as GL4, so some of the methods here in my case would be allowed to not exist.

Missing ImageSharp

Hi! I am trying to load a texture, with new Texture() and when i do that i get an error that says that it cannot load ImageSharp verison="1.0.0.0". I have tried with including both ImageSharp latest and verison 1.0.0, why doesnt it work?

Need fixes

  1. GlDelegates.cs
#pragma warning disable 0649
  1. IntPtr GetString(...) -> String GetString(...)

How to deal with 1D Textures?

Hi, I'm having great success with your c# libraries. I am stuck on something though. I have a heightmap where I need the heights colored according to a gradient I created. This is

        //here is the texture 
        myTextureData[0].X = 0x00;      //blue
        myTextureData[0].Y = 0x00;
        myTextureData[0].Z = 0xFF;
        myTextureData[0].W = 0xFF;

        myTextureData[0].X = 0xFF;      //yellow
        myTextureData[0].Y = 0xFF;
        myTextureData[0].Z = 0x00;
        myTextureData[0].W = 0xFF;

        myTextureData[0].X = 0xFF;      //red
        myTextureData[0].Y = 0x00;
        myTextureData[0].Z = 0x00;
        myTextureData[0].W = 0xFF;

I want to feed this to a fragment shader so that colors are assigned to my vertices. COuld you please give a hint as to how I would accomplish this? I understand I do not need texture coordinates defined for this.
Thanks a bunch!

Switch to automatic generated version

Hello giawa, Victor here ;)

I suggest to switch to an automatic generator for the bindings which should be produced with CppSharp. It's perfect for such purposes (I'm a contributor).

If automatic bindings are used things would follow this scheme:

  1. Automatic bindings generated and saved into one file
  2. Second file self written which contains object oriented wrappers for the functions.

Shader compile error "undefined variable in_position"

Why would this code return error c1008: undefined variable \ "in_position\" when using genericVAOs
This error doesn't seem to make sense. OpenGL dose not have a variable called in_position so why would the compiler be looking for it while creating the shader program.
The only place I can find using githubs search that uses in_position is the VAO class. However, in my code I am creating my own VAO that inheritance from GenericVAO that is not looking for a variable named in_position.

        public Shader(string source, ShaderType type)
        {
            this.ShaderType = type;
            this.ShaderID = Gl.CreateShader(type);

            Gl.ShaderSource(ShaderID, source);
            Gl.CompileShader(ShaderID);

            //Check whether the shader compiled successfully.
            //If not then throw an error with the compile error.
            if (!Gl.GetShaderCompileStatus(ShaderID))
            {
                throw new Exception(ShaderLog);
            }
        }

Here is my VAO class but I dont know why this would effect the creation of the shaderprogram because the shader program is created first.

    public class SpriteVAO : GenericVAO
    {
        public SpriteVAO(ShaderProgram program, VBO<Vector2> vertex, VBO<uint> element)
            : base(program)
        {
            List<IGenericVBO> vbos = new List<IGenericVBO>();
            vbos.Add(new GenericVBO<Vector2>(vertex, "position"));
            vbos.Add(new GenericVBO<uint>(element));
            Init(vbos.ToArray());
        }

        public static SpriteVAO CreateQuad(ShaderProgram program, Vector3 size)
        {
            Vector2[] vertices = new Vector2[] { Vector2.Zero, new Vector2(size.X, 0),
                new Vector2(size.X, size.Y), new Vector2(0, size.Y) };
            uint[] indices = new uint[] { 0, 1, 2, 2, 3, 0 };

            return new SpriteVAO(program, new VBO<Vector2>(vertices), new VBO<uint>(indices, BufferTarget.ElementArrayBuffer, BufferUsageHint.StaticRead));
        }
    }

Anisotropic filtering not supported

I know it's not a core extension but it is present in most drivers and it really improves texture quality. It's also easy to implement (two enums, TEXTURE_MAX_ANISOTROPY_EXT and MAX_TEXTURE_MAX_ANISOTROPY_EXT, see spec)

FileLoadException when starting program

I'm using a .NET Core 3.1 console application as a base for a small OpenGL playground.
When setting it up, I just followed the steps outlined in the readme:

  1. Install Giawa.OpenGL and Giawa.OpenGL.Platform
  2. Insert the example cube code:
using System;
using System.Numerics;
using OpenGL;

namespace Shady
{
	internal class Program
	{
		private const int WIDTH = 800;
		private const int HEIGHT = 480;

		private static VAO cube;

		private static void Main(string[] args)
		{
			// create an OpenGL window
			OpenGL.Platform.Window.CreateWindow("Shady", WIDTH, HEIGHT);

			var vertexShader = Resources.LoadTextResource("Shady.shaders.example.vsh");
			var fragShader = Resources.LoadTextResource("Shady.shaders.example.fsh");

			var shaderProgram = new ShaderProgram(vertexShader, fragShader);

			cube = Geometry.CreateCube(shaderProgram, new Vector3(-1, -1, -1), new Vector3(1, 1, 1));

			// handle events and render the frame
			while (OpenGL.Platform.Window.Open)
			{
				OpenGL.Platform.Window.HandleEvents();
				OnRenderFrame();
			}
		}

		private static void OnRenderFrame()
		{
			Gl.Viewport(0, 0, WIDTH, HEIGHT);
			Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

			cube.Program.Use();
			cube.Draw();

			OpenGL.Platform.Window.SwapBuffers();
		}
	}
}

Every time I run the app, it crashes on the CreateWindow line with this message:

System.IO.FileLoadException: 'Could not load file or assembly 'OpenGL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)'

I have no idea what Visual Studio is trying to tell me. I assumed using nuget would spare me obtuse error messages like this

Unhandled Exception

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at OpenGL.Gl.DeleteTextures(Int32 n, UInt32[] textures)
at OpenGL.Texture.Dispose(Boolean disposing)
at OpenGL.Texture.Finalize()

That is the error message recieved.

Issues about OpenGL.dll file

hello sir,

I'm learning on Youtube C# OpenGL Tutorial 1 : Opening a Window.
At 4:16, you mentioned that release and solution build , there will be new file named
OpenGL.dll config file and application extends.
But I didnt got config file , i got application file (430KB), json file(5KB), pdb file(90KB), xml file(996KB). those 4files.
How can I get the config file, is there any problem since i using the visual studio 2022?

ShaderProgram.Use() fails under multiple contexts.

When ShaderProgram.Use() is called under 2nd context, Gl.UseProgram(this.ProgramID) would not be called, as the ProgramID is the same as in the 1st context.
But ProgramID is actually context-specific, Gl.UseProgram(this.ProgramID) still needs to be called under 2nd context even if the ProgramID is the same.

Unable to find an entry point named 'SDL_Init' in DLL 'SDL2.dll'

Hello,
I am new to OpenGl in c# so sorry is this is a beginner issue. I got the above error when trying to run the following code.

OpenGL.Platform.Window.CreateWindow("OpenGL", 100, 100);

I have searched online to no avail. I have the OpenGL.dll, OpenGL.Platform.dll, and SDL2-DS.dll libraries included. When i try to add the SD2.dll that you link in your example it also gives me an error. Any help would be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.