gpt4 book ai didi

c - glFlush() 不显示任何内容

转载 作者:太空宇宙 更新时间:2023-11-04 07:55:54 25 4
gpt4 key购买 nike

当我在 Windows 7 的 Codeblocks 中运行过剩项目时,我的 OpenGL glFlush() 没有显示任何内容。这是我的主要功能。

#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>

float Color1=0.0, Color2=0.0, Color3=0.0;
int r,p,q;


void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27: // ESCAPE key
exit (0);
break;

case 'r':
Color1=1.0, Color2=0.0, Color3=0.0;
break;
case 'g':
Color1=0.0, Color2=1.0, Color3=0.0;
break;
case 'b':
Color1=0.0, Color2=0.0, Color3=1.0;
break;
}
glutPostRedisplay();

}

void Init(int w, int h)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glViewport(0,0, (GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D( (GLdouble)w/-2,(GLdouble)w/2, (GLdouble)h/-2, (GLdouble)h/2);

}

static void display(void)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int i=0;
glColor4f(0,0,0,1);
glPointSize(1);
glBegin(GL_POINTS);
for( i=-320;i<=320;i++)
glVertex2f(i,0);
for( i=-240;i<=240;i++)
glVertex2f(0,i);
glEnd();

glColor4f(Color1,Color2, Color3,1);
glPointSize(1);
glBegin(GL_POINTS);
int x=0, y = r;
int d= 1-r;
while(y>=x)
{
glVertex2f(x+p, y+q);
glVertex2f(y+p, x+q);
glVertex2f(-1*y+p, x+q);
glVertex2f(-1*x+p, y+q);

glVertex2f(-1*x+p, -1*y+q);
glVertex2f(-1*y+p, -1*x+q);
glVertex2f(y+p, -1*x+q);
glVertex2f(x+p, -1*y+q);

if(d<0)
d += 2*x + 3;
else
{
d += 2*(x-y) + 5;
y--;
}
x++;
}

glEnd();
glFlush();
//glutSwapBuffers();
}


int main(int argc, char *argv[])
{

printf("Enter the center point and radius: ");
scanf("%d %d %d",&p,&q,&r);
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

glutCreateWindow("Circle drawing");

Init(640, 480);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);


glutMainLoop();

return 0;
}

但是当我更改这两行时,它就可以正常工作了。

glFlush();到 glutSwapBuffers();和glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);到 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

谁能告诉我我的代码有什么问题以及为什么 glFlush() 不起作用?

最佳答案

现代图形系统(Windows DWM/Aero、MacOS Quartz Extreme、X11 Composite)都是围绕合成的概念构建的。合成总是意味着双缓冲,因此依赖于缓冲区交换来启动合成刷新。

您可以在 Windows 上禁用 DWM/Aero 并限制在 X11 上使用合成窗口管理器,然后单缓冲 OpenGL 应该会按预期工作。

但您究竟为什么需要单缓冲绘图?现代 GPU 实际上假定使用双缓冲来有效地泵送其演示管道。单缓冲的好处为零。

关于c - glFlush() 不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50161822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com