- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 OpenGL 时遇到了一些问题。首先,我有一个正在构建的自定义控件,它封装了 OpenGL。我遇到一个问题,它快速闪烁,就像它在“闪烁”一样。该控件太大且复杂,无法在此处发布,因此我制作了一个新的小型演示应用程序来演示和重新创建相同的场景。
现在的问题:我没有得到任何图像。在我的自定义控件中,事情会显示得很好,但由于我已经复制了代码并在一个小型演示应用程序中将其剥离,因此它不会显示图像。所以这里我手头有两个问题:闪烁(或闪烁),现在图像甚至不显示。以前不会出现闪烁,但是经过一些重大代码修改后,它开始闪烁。代码更改太多,无法解释到底更改了什么,几乎所有内容。
背景显示了,所以我知道它正在绘制一些东西(它是彩色的)。出于演示目的,它应该只绘制一个立方体,但我没有看到任何东西。我必须将其从大约 1,000 行代码精简到不到 300 行。
这不是您通常所说的闪烁,它实际上更像是闪烁或闪烁,想象一下汽车闪光灯的闪烁。这肯定与计时器有关,因为我设置的计时器间隔越大,它闪烁的速度就越慢。
为什么我什么也没看到?一旦解决了这个问题,为什么它会闪烁得那么厉害?
这是单个表单的代码,不需要 DFM:
unit uMain;
interface
uses
Winapi.Windows, Winapi.Messages, Winapi.OpenGL,
System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormResize(Sender: TObject);
private
FDrawing: Bool;
FDC: HDC;
FRC: HGLRC;
FDL: glUint;
FTimer: TTimer;
procedure Draw;
procedure SetDC(const Value: HDC);
procedure SetRC(const Value: HGLRC);
procedure SetDL(const Value: glUint);
public
property DC: HDC read FDC write SetDC;
property RC: HGLRC read FRC write SetRC;
property DL: glUint read FDL write SetDL;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
PixelFormat: glUint;
pfd: TPIXELFORMATDESCRIPTOR;
begin
FDrawing := False;
FDC := GetDC(Handle);
with pfd do begin
nSize := SizeOf(TPIXELFORMATDESCRIPTOR);
nVersion := 1; // The version of this data structure
dwFlags := PFD_DRAW_TO_WINDOW // Buffer supports drawing to window
or PFD_SUPPORT_OPENGL // Buffer supports OpenGL drawing
or PFD_DOUBLEBUFFER; // Supports double buffering
iPixelType := PFD_TYPE_RGBA; // RGBA color format
cColorBits := 32; // OpenGL color depth
cRedBits := 0; // Number of red bitplanes
cRedShift := 0; // Shift count for red bitplanes
cGreenBits := 0; // Number of green bitplanes
cGreenShift := 0; // Shift count for green bitplanes
cBlueBits := 0; // Number of blue bitplanes
cBlueShift := 0; // Shift count for blue bitplanes
cAlphaBits := 0; // Not supported
cAlphaShift := 0; // Not supported
cAccumBits := 0; // No accumulation buffer
cAccumRedBits := 0; // Number of red bits in a-buffer
cAccumGreenBits := 0; // Number of green bits in a-buffer
cAccumBlueBits := 0; // Number of blue bits in a-buffer
cAccumAlphaBits := 0; // Number of alpha bits in a-buffer
cDepthBits := 16; // Specifies the depth of the depth buffer
cStencilBits := 0; // Turn off stencil buffer
cAuxBuffers := 0; // Not supported
iLayerType := PFD_MAIN_PLANE; // Ignored
bReserved := 0; // Number of overlay and underlay planes
dwLayerMask := 0; // Ignored
dwVisibleMask := 0; // Transparent color of underlay plane
dwDamageMask := 0; // Ignored
end;
PixelFormat := ChoosePixelFormat(FDC, @pfd);
SetPixelFormat(FDC, PixelFormat, @pfd);
FRC := wglCreateContext(FDC);
wglMakeCurrent(FDC, FRC);
FormResize(nil);
wglMakeCurrent(FDC, FRC);
glClearColor(0.8, 0.8, 0.9, 0.0);
glShadeModel(GL_FLAT);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.4);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_TEXTURE_2D);
glNewList(FDL, GL_COMPILE);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0, 0.0);
glVertex3f(-2.0, -1.0, 1.0);
glTexCoord2f(2.0, 0.0);
glVertex3f(2.0, -1.0, 1.0);
glTexCoord2f(2.0, 1.0);
glVertex3f(2.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(-2.0, 1.0, 1.0);
// Back Face
glTexCoord2f(2.0, 0.0);
glVertex3f(-2.0, -1.0, -1.0);
glTexCoord2f(2.0, 1.0);
glVertex3f(-2.0, 1.0, -1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(2.0, 1.0, -1.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(2.0, -1.0, -1.0);
// Top Face
glTexCoord2f(0.0, 1.0);
glVertex3f(-2.0, 1.0, -1.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(-2.0, 1.0, 1.0);
glTexCoord2f(2.0, 0.0);
glVertex3f(2.0, 1.0, 1.0);
glTexCoord2f(2.0, 1.0);
glVertex3f(2.0, 1.0, -1.0);
// Bottom Face
glTexCoord2f(2.0, 1.0);
glVertex3f(-2.0, -1.0, -1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(2.0, -1.0, -1.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(2.0, -1.0, 1.0);
glTexCoord2f(2.0, 0.0);
glVertex3f(-2.0, -1.0, 1.0);
// Left Face
glTexCoord2f(0.0, 0.0);
glVertex3f(2.0, -1.0, -1.0);
glTexCoord2f(1.0, 0.0);
glVertex3f(2.0, -1.0, 1.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(2.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(2.0, 1.0, -1.0);
glEnd();
glEndList();
FTimer:= TTimer.Create(nil);
FTimer.OnTimer:= Timer1Timer;
FTimer.Interval:= 100;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FTimer.Free;
if (not wglMakeCurrent(FDC, 0)) then
MessageBox(0, 'Release of DC and RC failed!', 'Error', MB_OK or MB_ICONERROR);
if (not wglDeleteContext(FRC)) then begin
MessageBox(0, 'Release of rendering context failed!', 'Error', MB_OK or MB_ICONERROR);
FRC := 0;
end;
if ((FDC > 0) and (ReleaseDC(Handle, FDC) = 0)) then begin
MessageBox(0, 'Release of device context failed!', 'Error', MB_OK or MB_ICONERROR);
FDC := 0;
end;
end;
procedure TForm1.Draw;
var
I: Integer;
begin
if not FDrawing then begin
FDrawing := TRUE;
try
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glEnable(GL_NORMALIZE);
glShadeModel(GL_FLAT);
glCullFace(GL_BACK);
glLoadIdentity;
glPushMatrix();
glCallList(DL);
glPopMatrix();
SwapBuffers(wglGetCurrentDC);
finally
FDrawing := False;
end;
end;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, Width / Height, 0.1, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
end;
procedure TForm1.SetDC(const Value: HDC);
begin
FDC := Value;
end;
procedure TForm1.SetDL(const Value: glUint);
begin
FDL := Value;
end;
procedure TForm1.SetRC(const Value: HGLRC);
begin
FRC := Value;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Draw;
end;
end.
现在上面的代码与我原来的代码的工作方式有很大不同。原始的 Draw
过程对对象列表进行迭代,每个对象都包含自己的 Draw
过程。因此,控件的绘制过程准备整个场景,然后逐一绘制每个“项目”,如下所示:
procedure TGLImage.Draw;
var
X: Integer;
begin
if not FDrawing then begin
FDrawing := TRUE;
try
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glEnable(GL_NORMALIZE);
glShadeModel(GL_FLAT);
glCullFace(GL_BACK);
glLoadIdentity();
glRotatef(FElapsedTime / 70, 0, 0, 1);
glRotatef(90, 0, 1, 0);
glTranslatef(-FElapsedTime / 400, 0, 0);
if FInitialized then begin
for X := 0 to FItems.Count - 1 do begin
FItems[X].Draw;
end;
end;
SwapBuffers(wglGetCurrentDC);
finally
FDrawing := False;
end;
end;
end;
这是它绘制的其中一个项目...
constructor TGLBeam.Create(AOwner: TGLItems);
begin
inherited;
glNewList(DL, GL_COMPILE);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0, 0.0);
glVertex3f(-2.0, -1.0, 1.0);
glTexCoord2f(2.0, 0.0);
glVertex3f(2.0, -1.0, 1.0);
glTexCoord2f(2.0, 1.0);
glVertex3f(2.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(-2.0, 1.0, 1.0);
// Back Face
glTexCoord2f(2.0, 0.0);
glVertex3f(-2.0, -1.0, -1.0);
glTexCoord2f(2.0, 1.0);
glVertex3f(-2.0, 1.0, -1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(2.0, 1.0, -1.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(2.0, -1.0, -1.0);
// Top Face
glTexCoord2f(0.0, 1.0);
glVertex3f(-2.0, 1.0, -1.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(-2.0, 1.0, 1.0);
glTexCoord2f(2.0, 0.0);
glVertex3f(2.0, 1.0, 1.0);
glTexCoord2f(2.0, 1.0);
glVertex3f(2.0, 1.0, -1.0);
// Bottom Face
glTexCoord2f(2.0, 1.0);
glVertex3f(-2.0, -1.0, -1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(2.0, -1.0, -1.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(2.0, -1.0, 1.0);
glTexCoord2f(2.0, 0.0);
glVertex3f(-2.0, -1.0, 1.0);
// Left Face
glTexCoord2f(0.0, 0.0);
glVertex3f(2.0, -1.0, -1.0);
glTexCoord2f(1.0, 0.0);
glVertex3f(2.0, -1.0, 1.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(2.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(2.0, 1.0, -1.0);
glEnd();
glEndList();
end;
procedure TGLBeam.Draw;
var
I: Integer;
begin
glRotatef(Directions.X, 1.0, 0.0, 0.0);
glRotatef(Directions.Y, 0.0, 1.0, 0.0);
glRotatef(Directions.Z, 0.0, 0.0, 1.0);
for I := 1 to 10 do begin
//Main Center
glPushMatrix();
glTranslatef(I * 4 + Owner.Owner.ClockTime * 4, 0, 0);
glCallList(DL);
glPopMatrix();
//Above
glPushMatrix();
glTranslatef(I * 4 + Owner.Owner.ClockTime * 4, 6, 0);
glCallList(DL);
glPopMatrix();
end;
end;
最佳答案
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glEnable(GL_NORMALIZE);
glShadeModel(GL_FLAT);
glCullFace(GL_BACK);
glLoadIdentity;
glPushMatrix();
glCallList(DL);
glPopMatrix();
SwapBuffers(wglGetCurrentDC);
首先将 () 添加到对
的调用中glLoadIdentity
您加载单位矩阵,然后推送它,然后渲染并弹出它,而无需实际执行任何转换。
删除 3 行
glLoadIdentity;
glPushMatrix();
glPopMatrix();
或将glPushMatrix()
移动到glLoadIdentity()
我还建议关闭着色和剔除,以确保它们不会干扰。即使您不希望从前面剔除它们,以稍微错误的顺序声明的四边形并启用背面剔除也会剔除它们。
关于delphi - OpenGL 快速闪烁问题 - 现在不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10729526/
如何更改循环中变量的名称?比如 number1 、 number2 、 number3 、 number4 ? var array = [2,4,6,8] func ap ( number1: Int
我想设置 View 的背景颜色并在一定延迟后将其更改为另一种颜色。这是我的尝试方式: print("setting color 1") self.view.backgroundColor = UICo
我在使用 express-session 时遇到问题。 session 数据不会在请求之间持续存在。 正如您在下面的代码中看到的那样,/join 路由设置了一些 session 属性,但是当 /sur
我试图从叶渲染器获得一个非常简单的结果,用于快速 Steam 的 for 循环。 我正在上传叶文件 HTML,因为它不接受此处格式正确的代码 - 下面的pizza.swift代码- import
你们中有人有什么好的链接可以与我分享吗?我正在寻找一个 FAST 程序员编辑器,它可以非常快速地打开包含超过 100, 000 行代码的文件?我目前正在使用记事本自动取款机,打开一个 29000 行长
我现在正在处理眼动追踪数据,因此拥有一个巨大的数据集(想想数百万行),因此希望有一种快速的方法来完成此任务。这是它的简化版本。 数据告诉您眼睛在每个时间点正在查看的位置以及我们正在查看的每个文件。 X
我是新手,想为计时器或其他设备选择提示音。 如何打开此列表,以选择其中一种声音? Alert sound list 最佳答案 您将无法在应用中使用系统声音。 但是,您可以包括自己的声音文件,并将其显示
我编写了以下代码来构建具有顺序字符串的数组。 它的工作方式与我预期的一样,但我希望它能更快地运行。有没有更有效的方法在PowerShell中产生我想要的结果? 我是PowerShell的新手,非常感谢
我有一个包含一些非唯一行的矩阵,例如: x 尝试 y <- rle(apply(x, 1, paste, collapse = " ")) # y$lengths is the vector con
我的函数“keyboardWillShown”有问题。所以我想要的是菜单打开时,菜单正好出现在键盘上方。它可以在Iphone 8 plus,8、7、6上完美运行。但是,当我在模拟器上运行Iphone
我正在尝试通过Swift 5中的HTTP get方法从API提取数据。它在启动时成功加载了数据,但是当我刷新页面时,它说“索引超出范围”,这是因为数据是不再会在我的日志中读取,因此索引中没有任何内容。
我想做什么: 从我的数据库中获取时间戳并将其转换为用户的时区。 我的代码: let tryItNow = "\(model.timestampName)" let format = D
给定字体名称和字体大小,如何查找字符串的宽度(CGFloat)? (目标是将UIView的宽度设置为足以容纳字符串的宽度。) 我有两个字符串:一个重复“1”,重复36次,另一个重复“M”,重复36次。
我正在尝试解析此JSON ["Items": ( { AccountBalance = 0; AlphabetType = 3; Description = "\U0631\U
我在UINavigationBar内放置了一个UILabel。 我想根据navigationBar的高度增加该标签的字体大小。当navigationBar很大时,我希望字体大小更大;当滚动并缩小nav
我想将用户输入限制为仅有效数字并使用以下内容: func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, rep
目前我有一个包含超过 100.000 张图像的数据库,它们大小不一或类似,但我想为我的公司制作以下内容: 我插入/上传一张图片,系统返回最有可能相同的图片。我不知道使用什么算法,但它需要快速。我可以预
在我的 swift 项目中,我有一个按钮,我想在标签上打印按下该按钮的时间。 如何解决这个问题? 最佳答案 添加到DHEERAJ的答案中,您只需在func press(sender: UIButton
我必须发表评论,尝试在解析中导入数组。然而,有一个问题。 当我尝试从 Parse 加载数组时,我的输出是 ("Blah","Blah","Blah")这是一个元组...而不是一个数组 TT... 如何
我的应用程序有一个名为 MyDevice 的类,我用它来与硬件通信。该硬件是可选的,实例变量也是可选的: var theDevice:MyDevice = nil 然后,在应用程序中,我必须初始化设备
我是一名优秀的程序员,十分优秀!