本文整理汇总了C++中QOpenGLFunctions类的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLFunctions类的具体用法?C++ QOpenGLFunctions怎么用?C++ QOpenGLFunctions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QOpenGLFunctions类的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: uploadTextures
static void uploadTextures(QOpenGLContext* context, SharedFrame& frame, GLuint texture[])
{
int width = frame.get_image_width();
int height = frame.get_image_height();
const uint8_t* image = frame.get_image();
QOpenGLFunctions* f = context->functions();
// Upload each plane of YUV to a texture.
if (texture[0])
f->glDeleteTextures(3, texture);
check_error(f);
f->glGenTextures(3, texture);
check_error(f);
f->glBindTexture (GL_TEXTURE_2D, texture[0]);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
check_error(f);
f->glTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
check_error(f);
f->glBindTexture (GL_TEXTURE_2D, texture[1]);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
check_error(f);
f->glTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, width/2, height/2, 0,
GL_LUMINANCE, GL_UNSIGNED_BYTE, image + width * height);
check_error(f);
f->glBindTexture (GL_TEXTURE_2D, texture[2]);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
check_error(f);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
check_error(f);
f->glTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, width/2, height/2, 0,
GL_LUMINANCE, GL_UNSIGNED_BYTE, image + width * height + width/2 * height/2);
check_error(f);
}