git-svn-id: svn://db.shs.com.ru/libs@605 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -53,41 +53,51 @@ QString findFile(const QString & file, const QStringList & pathes) {
|
||||
}
|
||||
|
||||
|
||||
void quadProgPoint(QOpenGLFunctions * glFuncs, QOpenGLShaderProgram * prog, QVector4D * corner_dirs,
|
||||
GLfloat x, GLfloat y, GLfloat tx, GLfloat ty, int locv, int loct, int locc, int index) {
|
||||
if (prog) {
|
||||
if (corner_dirs)
|
||||
prog->setAttributeValue(locc, corner_dirs[index]);
|
||||
glFuncs->glVertexAttrib2f(loct, tx, ty);
|
||||
glFuncs->glVertexAttrib2f(locv, x, y);
|
||||
} else {
|
||||
glTexCoord2f(tx, ty);
|
||||
glVertex2f(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
|
||||
glResetAllTransforms();
|
||||
glSetPolygonMode(GL_FILL);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
int loc = prog ? prog->attributeLocation("qgl_Color") : -1,
|
||||
locv = prog ? prog->attributeLocation("qgl_Vertex") : -1,
|
||||
loct = prog ? prog->attributeLocation("qgl_Texture") : -1,
|
||||
locc = prog ? prog->attributeLocation("view_corner") : -1;
|
||||
//if (prog) {qDebug() << locv << loct << locc;}
|
||||
QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions();
|
||||
if (prog) {
|
||||
static const GLfloat cols [] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f};
|
||||
static const GLfloat verts[] = {x, y, x+w, y, x, y+h, x+w, y+h};
|
||||
static const GLfloat texs [] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f};
|
||||
GLfloat vcs[] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
|
||||
if (corner_dirs) {
|
||||
vcs[0] = corner_dirs[0].x(); vcs[1] = corner_dirs[0].y(); vcs[2] = corner_dirs[0].z();
|
||||
vcs[3] = corner_dirs[1].x(); vcs[4] = corner_dirs[1].y(); vcs[5] = corner_dirs[1].z();
|
||||
vcs[6] = corner_dirs[2].x(); vcs[7] = corner_dirs[2].y(); vcs[8] = corner_dirs[2].z();
|
||||
vcs[9] = corner_dirs[3].x(); vcs[10] = corner_dirs[3].y(); vcs[11] = corner_dirs[3].z();
|
||||
}
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glFuncs->glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glFuncs->glEnableVertexAttribArray(loc);
|
||||
glFuncs->glVertexAttribPointer(loc, 3, GL_FLOAT, 0, 0, cols);
|
||||
glFuncs->glEnableVertexAttribArray(locv);
|
||||
glFuncs->glVertexAttribPointer(locv, 2, GL_FLOAT, 0, 0, verts);
|
||||
glFuncs->glEnableVertexAttribArray(loct);
|
||||
glFuncs->glVertexAttribPointer(loct, 2, GL_FLOAT, 0, 0, texs);
|
||||
glFuncs->glEnableVertexAttribArray(locc);
|
||||
glFuncs->glVertexAttribPointer(locc, 3, GL_FLOAT, 0, 0, vcs);
|
||||
glFuncs->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
} else {
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0.f, 0.f); glVertex2f(x, y);
|
||||
glTexCoord2f(1.f, 0.f); glVertex2f(x+w, y);
|
||||
glTexCoord2f(0.f, 1.f); glVertex2f(x, y+h);
|
||||
glTexCoord2f(1.f, 1.f); glVertex2f(x+w, y+h);
|
||||
glEnd();
|
||||
}
|
||||
//if (prog)
|
||||
//qDebug() << loc << locv << loct << locc;
|
||||
glBegin(GL_QUADS);
|
||||
QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions();
|
||||
if (prog) {
|
||||
glFuncs->glVertexAttrib3f(loc, 1.f, 1.f, 1.f);
|
||||
}
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
quadProgPoint(glFuncs, prog, corner_dirs, x , y , 0.f, 0.f, locv, loct, locc, 0);
|
||||
quadProgPoint(glFuncs, prog, corner_dirs, x+w, y , 1.f, 0.f, locv, loct, locc, 1);
|
||||
quadProgPoint(glFuncs, prog, corner_dirs, x+w, y+h, 1.f, 1.f, locv, loct, locc, 2);
|
||||
quadProgPoint(glFuncs, prog, corner_dirs, x , y+h, 0.f, 1.f, locv, loct, locc, 3);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user