Tag: opentk

使用OpenGL-Control的WPF MVVM WinformsHost

我正在使用MVVM开发WPF应用程序。 在这个应用程序中,我需要一个OpenGL控件(我正在使用OpenTK)。 目前在WPF中获取OpenGL的唯一有用方法是使用WindowsFormsHost。 直到这里,没有问题。 要向我的场景添加内容,我需要在我的视图中访问OpenGL-Control。 当然,我想在ViewModel中添加和编辑内容。 那么,如何在不违反MVVM模式的情况下访问OpenGL-Control? 我正在使用一个可以在View中初始化的场景对象,然后需要以某种方式转移到ViewModel。 我尝试使用WindowsFormsHost的Tag-property但没有成功(比较如下)。 ViewModel中的属性未更新。 有任何想法吗? XAML C# public FancyOpenGlControl() { this.InitializeComponent(); this.glControl = new OpenGLControl(); this.glControl.Dock = DockStyle.Fill; this.WindowsFormsHost.Child = this.glControl; this.glControl.HandleCreated += this.GlControlOnHandleCreated; } private void GlControlOnHandleCreated(object sender, EventArgs eventArgs) { this.WindowsFormsHost.Tag = new Scene(this.glControl); // Doesn’t work. //BindingExpression bindingExpression = this.WindowsFormsHost.GetBindingExpression(TagProperty); //if (bindingExpression != null) //{ // […]

精灵/纹理图集:使用OpenTK进行颜色键的GDI + Bitmap.MakeTransparent

我正在编写一个sprite / texture atlasfunction的支持类,使用C#和OpenTK。 到目前为止,大多数function都正常工作(正交视图上的简单2D图块)。 我的问题涉及调用GDI + Bitmap.MakeTransparent()方法设置颜色(品红色/ 0xFFFF00FF)用作颜色键时的意外显示结果。 看起来我对bitmap.LockBits()和GL.TexImage2D()调用使用了不正确的像素格式参数。 我的代码基于确实有效的示例,但共同的是传递给LockBits()的矩形用于整个图像。 与此过程相关的调用是: Bitmap bitmap = new Bitmap(filename); bitmap.MakeTransparent(Color.Magenta); GL.GenTextures(1, out texture_id); GL.BindTexture(TextureTarget.Texture2D, texture_id); // “rect” is initialized for one of: // – the dimensions of the entire image // (0, 0, bitmap.width, bitmap.height) // – the dimensions for a sub-rectangle within the image (for one […]

设置着色器的矩阵

我想绘制实例立方体。 我可以调用GL.DrawArraysInstanced(PrimitiveType.Triangles, 0, 36, 2); 成功。 我的问题是所有的立方体都是在相同的位置和相同的旋转绘制的。 我怎样才能为每个立方体单独更改? 要创建不同的位置等,我需要每个立方体的矩阵,对吧? 我创造了这个: Matrix4[] Matrices = new Matrix4[]{ Matrix4.Identity, //do nothing Matrix4.Identity * Matrix4.CreateTranslation(1,0,0) //move a little bit }; GL.BindBuffer(BufferTarget.ArrayBuffer, matrixBuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * 16 * Matrices.Length), Matrices, BufferUsageHint.StaticDraw); 这应该创建一个缓冲区,我可以存储我的矩阵。 matrixBuffer是指向我缓冲区的指针。 我不确定大小是否正确,我采用浮动* 4(对于Vector4)* 4(对于4个向量)*数组大小。 绘制循环: GL.BindBuffer(BufferTarget.ArrayBuffer, matrixBuffer); GL.VertexAttribPointer(3, 4, VertexAttribPointerType.Float, false, 0, 0); //GL.VertexAttribDivisor(3, ?); GL.EnableVertexAttribArray(3); GL.DrawArraysInstanced(PrimitiveType.Triangles, 0, […]

VBO在C#中使用交错顶点

我正在尝试使用VBO使用OpenTK在C#中绘制我的模型。 在我的在线研究中,我在许多地方读过,优先考虑使交错数据结构的大小为32字节的精确倍数,因此我编写了以下代码: [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Byte4 { public byte R, G, B, A; public Byte4(byte[] input) { R = input[0]; G = input[1]; B = input[2]; A = input[3]; } public uint ToUInt32() { byte[] temp = new byte[] { this.R, this.G, this.B, this.A }; return BitConverter.ToUInt32(temp, 0); } } [Serializable] [StructLayout(LayoutKind.Sequential)] public struct […]

如何在OpenTK中使对象透明

我正在使用OpenTK和C#,我在3D空间中定义了一个平面,如下所示: GL.Begin(BeginMode.Quads); GL.Color3(Color.Magenta); GL.Vertex3(-100.0f, -25.0f, -150.0f); GL.Vertex3(-100.0f, -25.0f, 150.0f); GL.Vertex3( 200.0f, -25.0f, 100.0f); GL.Vertex3( 200.0f, -25.0f, -100.0f); GL.End(); 谁能帮助我让飞机透明?

如何加入重叠的圈子?

我想在视觉上加入两个重叠的圆圈 变 我已经有了部分圆的方法,但现在我需要知道earch圆的重叠角度有多大,我不知道该怎么做。 有人有想法吗?

C#OpenTK – 纹理四边形

我最近下载了OpenTK。 我创建了一个基本的游戏类和四元组。 我尝试在我的四边形中渲染纹理,但它不起作用。 这是我的代码。 这是纹理的加载。 (纹理类只包含一个ID和一个Bitmap.GetWidth()和GetHeight()只返回Bitmap.Width和Bitmap.Height)。 Texture Texture = new Texture (); Texture.Bitmap = new Bitmap (Path); Texture.ID = GL.GenTexture (); GL.BindTexture (TextureTarget.Texture2D, Texture.ID); BitmapData data = Texture.Bitmap.LockBits (new Rectangle (0, 0, Texture.GetWidth (), Texture.GetHeight ()), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Texture.GetWidth(), Texture.GetHeight(), 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.Bitmap, data.Scan0); Texture.Bitmap.UnlockBits (data); GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear); GL.TexParameter […]

OpenGL – 旋转不起作用

背景 我目前有一个我创建的环境,我加载了一些形状(以供我参考)并且我试图让控件向前,向后移动并旋转我正在寻找的位置。 我使用我的观察点和摄像机位置点进行向前和向后计算。 我试图旋转360度,但似乎根据我到目前为止得到了一些奇怪的限制。 我正在输出我的xangle,看看我一直在哪里。 为了旋转,我改变了lookat变量(x,y和z),同时保持位置(x,y,z)相同。 问题 当连续增加角度时,我击中两个reflection点,其中出现的旋转改变方向。 无论出于何种原因,这些似乎发生在60度和300度,如下所示: 显然这些角度是不正确的。 我已经评估了旋转发生时应该发生的行为,并且计算出的笛卡尔坐标似乎是正确的但是角度的显示是关闭的。 我的setupviewport子: Private Sub SetupViewport() Dim w As Integer = GLcontrol1.Width Dim h As Integer = GLcontrol1.Height Dim perspective1 As Matrix4 = cam.GetViewMatrix() * Matrix4.CreatePerspectiveFieldOfView(1.3F, GLcontrol1.Width / CSng(GLcontrol1.Height), 0.1F, 2000.0F) GL.MatrixMode(MatrixMode.Projection) GL.LoadIdentity() GL.Ortho(0, w, h, 0, -1, 1) GL.LoadMatrix(perspective1) GL.MatrixMode(MatrixMode.Modelview) GL.LoadIdentity() GL.Viewport(0, 0, w, h) […]