本文整理汇总了C++中QOpenGLFunctions::glGetShaderInfoLog方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLFunctions::glGetShaderInfoLog方法的具体用法?C++ QOpenGLFunctions::glGetShaderInfoLog怎么用?C++ QOpenGLFunctions::glGetShaderInfoLog使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLFunctions
的用法示例。
在下文中一共展示了QOpenGLFunctions::glGetShaderInfoLog方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadShader
/**
* @brief initShader Initiate a shader.
* @return the compiled shader program or 0 if the shader file does not exist
*/
GLuint loadShader(string shader_name)
{
QOpenGLFunctions* qf = new QOpenGLFunctions(QOpenGLContext::currentContext());
char* error;
QFile* file = new QFile((":/shader/" + shader_name + ".vsh").c_str());
if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
return 0;
string code = "";
QTextStream* in = new QTextStream(file);
while (!in->atEnd()) {
QString line = in->readLine();
code = code + line.toStdString() + "\n";
}
file->close();
GLuint vs = qf->glCreateShader(GL_VERTEX_SHADER);
const char* v_str = code.c_str();
qf->glShaderSource(vs, 1, &v_str, NULL);
qf->glCompileShader(vs);
qf->glGetShaderInfoLog(vs, NULL, NULL, error);
cout << error << "\n";
code = "";
delete file;
delete in;
file = new QFile((":/shader/" + shader_name + ".fsh").c_str());
if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
return 0;
in = new QTextStream(file);
while (!in->atEnd()) {
QString line = in->readLine();
code = code + line.toStdString() + "\n";
}
file->close();
GLuint fs = qf->glCreateShader(GL_FRAGMENT_SHADER);
const char *f_str = code.c_str();
qf->glShaderSource(fs, 1, &f_str, NULL);
qf->glCompileShader(fs);
qf->glGetShaderInfoLog(fs, NULL, NULL, error);
cout << error << endl;
GLuint program = qf->glCreateProgram();
qf->glAttachShader(program, vs);
qf->glAttachShader(program, fs);
qf->glLinkProgram(program);
qf->glGetProgramInfoLog(program, NULL, NULL, error);
cout << error << endl;
qf->glUseProgram(program);
return program;
}
示例2: saveTexture
void QSGDistanceFieldGlyphCache::saveTexture(GLuint textureId, int width, int height) const
{
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
GLuint fboId;
functions->glGenFramebuffers(1, &fboId);
GLuint tmpTexture = 0;
functions->glGenTextures(1, &tmpTexture);
functions->glBindTexture(GL_TEXTURE_2D, tmpTexture);
functions->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
functions->glBindTexture(GL_TEXTURE_2D, 0);
functions->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId);
functions->glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,
tmpTexture, 0);
functions->glActiveTexture(GL_TEXTURE0);
functions->glBindTexture(GL_TEXTURE_2D, textureId);
functions->glDisable(GL_STENCIL_TEST);
functions->glDisable(GL_DEPTH_TEST);
functions->glDisable(GL_SCISSOR_TEST);
functions->glDisable(GL_BLEND);
GLfloat textureCoordinateArray[8];
textureCoordinateArray[0] = 0.0f;
textureCoordinateArray[1] = 0.0f;
textureCoordinateArray[2] = 1.0f;
textureCoordinateArray[3] = 0.0f;
textureCoordinateArray[4] = 1.0f;
textureCoordinateArray[5] = 1.0f;
textureCoordinateArray[6] = 0.0f;
textureCoordinateArray[7] = 1.0f;
GLfloat vertexCoordinateArray[8];
vertexCoordinateArray[0] = -1.0f;
vertexCoordinateArray[1] = -1.0f;
vertexCoordinateArray[2] = 1.0f;
vertexCoordinateArray[3] = -1.0f;
vertexCoordinateArray[4] = 1.0f;
vertexCoordinateArray[5] = 1.0f;
vertexCoordinateArray[6] = -1.0f;
vertexCoordinateArray[7] = 1.0f;
functions->glViewport(0, 0, width, height);
functions->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray);
functions->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray);
{
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();
//.........这里部分代码省略.........