- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的目标是在 GL_Control(一个 gui 控件)上用 c# 中的 opentk 绘制东西,并在每次调用 paint 事件时将其保存到 Bitmap 对象中。我有这段代码:
private void glControl1_Paint(object sender, PaintEventArgs e)
{
// do lots of drawing here
GL.Finish();
GL.Flush();
glControl1.SwapBuffers();
gl_image = TakeScreenshot();
}
public Bitmap TakeScreenshot()
{
if (GraphicsContext.CurrentContext == null)
throw new GraphicsContextMissingException();
int w = glControl1.ClientSize.Width;
int h = glControl1.ClientSize.Height;
Bitmap bmp = new Bitmap(w, h);
System.Drawing.Imaging.BitmapData data =
bmp.LockBits(glControl1.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
GL.ReadPixels(0, 0, w, h, PixelFormat.Bgr, PixelType.UnsignedByte, data.Scan0);
bmp.UnlockBits(data);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
return bmp;
}
所以在交换缓冲区后的绘画事件中,我拍摄了 schreenshot。问题是捕获的图像是绘图之前的状态。这意味着如果我想捕捉图像,我需要运行两次绘画事件。我试过 GL.flush 和 finish 以及 swapbuffer。有谁知道如何克服这个问题。另请注意,我曾尝试使用异步方式但失败了,因为您无法从另一个线程访问 opentk 图像数据。
最佳答案
我遇到了完全相同的问题,这是我解决它的方法。当您调用 glControl1.Invalidate()
刷新图像时,OpenTK 实际上会在最后完成。因此,如果您在该滴答期间抓取屏幕截图,则缓冲区将在下一个周期之前不会更新。
你需要做的是强制刷新glControl1
,这是代码。
public void GLrefresh()
{
glControl1.Invalidate();
glControl1.Update();
glControl1.Refresh();
}
在抓取屏幕截图之前调用此函数
GLrefresh();
Image I = TakeScreenshot();
//Now Image I should be the image of the current buffer
关于c# - 如何捕获使用opentk绘制的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25173224/
这是顶点着色器: uniform mat4 projection; uniform mat4 view; uniform mat4 model; void main(void) { gl_Po
我有一个问题,我是需要二次幂 (POT) 纹理并且似乎无法使用 NPOT 的幸运者之一。 通常,这不会让我太烦恼,因为我只会确保我需要使用的任何纹理都是 POT。但是,我在尝试将光标 X 和 Y 位置
我最近在我的游戏中实现了视锥体剔除,并且为了从渲染周期中挤出最后一滴,我还决定实现遮挡剔除。它工作得很好,但是,我很痛苦地发现,如果我不看游戏中的任何东西(如果我向虚空看,远离我的游戏对象),我的显卡
我正在寻找一种用颜色“填充”三维几何体的方法,并且很可能在稍后的某个时间填充纹理。 假设你可以将头撞到混凝土墙上,从逻辑上讲你只会看到黑暗。然而,在 OpenGL 中,当您执行此操作时,由于剔除以及几
警告:总的 OpenGL/TK 新手,请善待。我可能咬得太多了。 规范: 2017 年 Visual Studio 社区 C# .Net 4.6.1(使用 WPF、WindowsFormsHost 控
我正在寻找一种跨平台(Win 和 MacOS)方法来检测 C# 中 OpenGL 应用程序的按键。 以下有效,但仅适用于字母数字字符。 protected override void OnKeyPre
我在 http://viewport3d.com/trackball.htm 上使用教程编程轨迹球。我计算了轴和角度,但因为我只是 OpenTK 和 OpenGL 的初学者,所以我不知道如何将旋转应用
我有两张图片。我必须找到第一张图像中强度大于 0.8 的点。同时,我必须在相同点上找到第二张图像的强度,并且需要使用阈值/ slider 值(范围从 0 到 1)调整相同点上第二张图像上的光线。我做了
有没有人知道如何使用 OpenTK 框架滚动(动画化)2D 文本,或者在哪里可以找到一些好的示例。我需要新闻电视 channel 底部(顶部)滚动代码之类的东西。 谢谢。 最佳答案 有许多可能的文本渲
尝试制作游戏,但纹理从未出现在屏幕上。 只为四边形使用颜色是可行的,但是当我尝试为四边形添加纹理时,它只是显示为黑色方 block 。 基本片段着色器: #version 300 es precisi
有没有办法在另一个线程中使用 OpenTK/OpenGL 绘制到屏幕上?我尝试使用的代码是 GL.Clear(ClearBufferMask.ColorBufferBit); GL.ClearColo
它是 tao 框架中已弃用的 OpenTK.Graphics.Glu 的替代品吗?尤其是对几何渲染的需求。 最佳答案 OpenTK 是 Tao 的演变。而且,老实说,我没有听说过 glut 被贬低了。
我是 opengl 的新手,我正在努力让 stencilbuffer 为一个简单的案例工作;我有两种纹理,一种是位图,另一种是“ mask ”,我试图用它来隐藏位图中的某些部分。 我似乎无法让它工作,
我正在尝试在我的 OpenTK 项目中旋转 2D 对象。 发生的事情是旋转对象之后的对象正在旋转,我不希望它们这样做。 我已经旋转了一个对象后如何重置旋转? protected overr
我正在为 OpenGL 和 C# 使用 OpenTK。 我需要使用模板缓冲区,目前想知道如何设置 StencilBuffer 深度。 我之前知道的是 TaoFramework,它的控件具有可以设置此深
我在进行视锥体剔除的方式上遇到了一些问题。当前的方法确实解决了剔除问题,但效果确实很奇怪。当我离我的主要父对象太近时,我正在使用场景图来渲染所有内容,对象开始非常快速地闪烁。当我离开时,它就消失了。我
我正在使用 OpenTK 和 C#,我在 3D 空间中定义了一个平面,如下所示: GL.Begin(BeginMode.Quads); GL.Color3(Color.Magenta); GL.Ver
我不确定为什么这段代码不是简单地在屏幕上绘制一个三角形(正交)。我正在使用与 OpenGL 1.1 相同的 OpenTK 1.1。 List simpleVertices = new List();
我正在尝试找到一种方法来使窗口始终位于顶部。 (必须是窗口模式)我目前正在使用 OpenTk.NetCore 库在 .net 核心中制作一个窗口。是否可以使用 OpenTk 将此窗口保持在顶部或是否有
我目前正在开发一款使用 OpenTK 进行渲染的游戏; C#、.Net 4.0、OpenGL 2。 在 1280x1024 分辨率下最大化运行(不是全屏,而是占用所有可用的屏幕空间),我看到平均帧率为
我是一名优秀的程序员,十分优秀!