gpt4 book ai didi

c++ - 为什么这个三角形条只画了屏幕的三分之一?

转载 作者:行者123 更新时间:2023-11-27 22:38:48 26 4
gpt4 key购买 nike

<分区>

我正在尝试制作一个玩具来在整个屏幕上“绘制”片段着色器。为此,我试图用一个三角形 strip “填充”屏幕。我正在为此使用 QT,因为除了 openGL 渲染之外,我还想使用一个 UI。

我基于全屏三角形带技术: https://github.com/Gargaj/Bonzomatic/blob/master/src/platform_glfw/Renderer.cpp

static const char *fragmentShaderSource =
"varying mediump vec4 color;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = vec4(1.0,0.0,0.0,0.0);\n"
"}\n";


static float pFullscreenQuadVertices[] =
{
-1.0, -1.0, 0.5, 0.0, 0.0,
-1.0, 1.0, 0.5, 0.0, 1.0,
1.0, -1.0, 0.5, 1.0, 0.0,
1.0, 1.0, 0.5, 1.0, 1.0,
};

static const char *szVertexShader =
"#version 410 core\n"
"in vec3 in_pos;\n"
"in vec2 in_texcoord;\n"
"out vec2 out_texcoord;\n"
"void main()\n"
"{\n"
" gl_Position = vec4( in_pos.x, in_pos.y, in_pos.z, 1.0 );\n"
" out_texcoord = in_texcoord;\n"
"}";


void DemoRender::initializeGL(){
m_background = qRgb(255,255,255);
initializeOpenGLFunctions();
m_program = new QOpenGLShaderProgram(this);
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, szVertexShader);
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->link();
m_program->log();
m_posAttr = m_program->attributeLocation("in_pos");

m_vao1.create();
m_vao1.bind();



}


void DemoRender::paintGL(){
QPainter painter;
painter.begin(this);

painter.beginNativePainting();
glClearColor(m_background.redF(), m_background.greenF(), m_background.blueF(),0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//glFrontFace(GL_CW);
//glCullFace(GL_FRONT);
//glEnable(GL_CULL_FACE);
//glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT);

m_program->bind();
drawFullScreen();
m_program->release();
//glDisable(GL_DEPTH_TEST);
//glDisable(GL_CULL_FACE);

painter.endNativePainting();

painter.end();

update();


}

void DemoRender::drawFullScreen(){

m_vao1.bind();

m_vbo1.create();
m_vbo1.bind();
m_vbo1.allocate(pFullscreenQuadVertices,sizeof(pFullscreenQuadVertices)*sizeof(float));
m_vbo1.write(0,pFullscreenQuadVertices,sizeof(pFullscreenQuadVertices));


m_program->enableAttributeArray(m_posAttr);

//m_vbo1.release();
//I suspect you are the culprit, but I don't know how to fix it.
m_program->setAttributeBuffer(m_posAttr, GL_FLOAT, 0, 3);

m_vbo1.release();

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);


m_program->disableAttributeArray(m_posAttr);

}

作为一种调试技术,我告诉片段着色器将每个像素设为红色。现在,我的困惑是:为什么只有大约三分之一的屏幕变红了?

顶点着色器似乎没有覆盖整个屏幕空间。我该怎么做才能解决这个问题?

我目前的理论是,由于顶点数组设置的一些细节,三角形带没有正确渲染,但因为 qt 不允许我做这种 C 风格,我不能按照原作者的代码一一个。

Something is definitely wrong here

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