本文整理汇总了C++中QOpenGLFunctions::glUniform1i方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLFunctions::glUniform1i方法的具体用法?C++ QOpenGLFunctions::glUniform1i怎么用?C++ QOpenGLFunctions::glUniform1i使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLFunctions
的用法示例。
在下文中一共展示了QOpenGLFunctions::glUniform1i方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveTexture
//.........这里部分代码省略.........
{
static const char *vertexShaderSource =
"attribute vec4 vertexCoordsArray; \n"
"attribute vec2 textureCoordArray; \n"
"varying vec2 textureCoords; \n"
"void main(void) \n"
"{ \n"
" gl_Position = vertexCoordsArray; \n"
" textureCoords = textureCoordArray; \n"
"} \n";
static const char *fragmentShaderSource =
"varying vec2 textureCoords; \n"
"uniform sampler2D texture; \n"
"void main() \n"
"{ \n"
" gl_FragColor = texture2D(texture, textureCoords); \n"
"} \n";
GLuint vertexShader = functions->glCreateShader(GL_VERTEX_SHADER);
GLuint fragmentShader = functions->glCreateShader(GL_FRAGMENT_SHADER);
if (vertexShader == 0 || fragmentShader == 0) {
GLenum error = functions->glGetError();
qWarning("QSGDistanceFieldGlyphCache::saveTexture: Failed to create shaders. (GL error: %x)",
error);
return;
}
functions->glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
functions->glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
functions->glCompileShader(vertexShader);
GLint len = 1;
functions->glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &len);
char infoLog[2048];
functions->glGetShaderInfoLog(vertexShader, 2048, NULL, infoLog);
if (qstrlen(infoLog) > 0)
qWarning("Problems compiling vertex shader:\n %s", infoLog);
functions->glCompileShader(fragmentShader);
functions->glGetShaderInfoLog(fragmentShader, 2048, NULL, infoLog);
if (qstrlen(infoLog) > 0)
qWarning("Problems compiling fragment shader:\n %s", infoLog);
GLuint shaderProgram = functions->glCreateProgram();
functions->glAttachShader(shaderProgram, vertexShader);
functions->glAttachShader(shaderProgram, fragmentShader);
functions->glBindAttribLocation(shaderProgram, 0, "vertexCoordsArray");
functions->glBindAttribLocation(shaderProgram, 1, "textureCoordArray");
functions->glLinkProgram(shaderProgram);
functions->glGetProgramInfoLog(shaderProgram, 2048, NULL, infoLog);
if (qstrlen(infoLog) > 0)
qWarning("Problems linking shaders:\n %s", infoLog);
functions->glUseProgram(shaderProgram);
functions->glEnableVertexAttribArray(0);
functions->glEnableVertexAttribArray(1);
int textureUniformLocation = functions->glGetUniformLocation(shaderProgram, "texture");
functions->glUniform1i(textureUniformLocation, 0);
}
functions->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
{
GLenum error = functions->glGetError();
if (error != GL_NO_ERROR)
qWarning("glDrawArrays reported error 0x%x", error);
}
uchar *data = new uchar[width * height * 4];
functions->glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
QImage image(data, width, height, QImage::Format_ARGB32);
QByteArray fileName = m_referenceFont.familyName().toLatin1() + '_' + QByteArray::number(textureId);
fileName = fileName.replace('/', '_').replace(' ', '_') + ".png";
image.save(QString::fromLocal8Bit(fileName));
{
GLenum error = functions->glGetError();
if (error != GL_NO_ERROR)
qWarning("glReadPixels reported error 0x%x", error);
}
functions->glDisableVertexAttribArray(0);
functions->glDisableVertexAttribArray(1);
functions->glDeleteFramebuffers(1, &fboId);
functions->glDeleteTextures(1, &tmpTexture);
delete[] data;
}