#include "glwidget.h"
#include <stdio.h>
#include "glextensions.h"
int hasPathRendering = 1;
int hasDirectStateAccess = 1;
const char *programName = "nvpr_basic";
GLuint pathObj = 42;
int path_specification_mode = 0;
int filling = 1;
int stroking = 1;
int even_odd = 0;
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
}
void GLWidget::initializeGL()
{
qDebug() << "OpenGL Versions Supported: " << QGLFormat::openGLVersionFlags();
QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION))));
qDebug() << "Driver Version String:" << versionString;
qDebug() << "Current Context:" << format();
if (!getGLExtensionFunctions().resolve(context())) {
QMessageBox::critical(0, "OpenGL features missing",
"Failed to resolve OpenGL functions required to run this demo.\n"
"The program will now exit.");
delete this;
return;
}
initGraphics();
glViewport(0, 0, width(), height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-50, 50, -50, 50, -50, 50);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.2, 0.2, 0.2, 1);
}
void initGraphics()
{
initPathFromSVG();
glPathParameteriNV(pathObj, GL_PATH_JOIN_STYLE_NV, GL_ROUND_NV);
glPathParameterfNV(pathObj, GL_PATH_STROKE_WIDTH_NV, 6.5);
}
void
initPathFromSVG()
{
const char *svgPathString =
//star
"M100,180 L40,10 L190,120 L10,120 L160,10 z";
// heart
"M300 300 C 100 400,100 200,300 100,500 200,500 400,300 300Z";
glPathStringNV(pathObj, GL_PATH_FORMAT_SVG_NV,
(GLsizei)strlen(svgPathString), svgPathString);
}
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
doGraphics();
//swapBuffers();
}
void
doGraphics(void)
{
glClearStencil(0);
glClearColor(0,0,0,0);
glStencilMask(~0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glMatrixLoadIdentityEXT(GL_PROJECTION);
glMatrixLoadIdentityEXT(GL_MODELVIEW);
glMatrixOrthoEXT(GL_MODELVIEW, 0, 500, 0, 400, -1, 1);
filling = true;
stroking = true;
if (filling) {
qDebug("filling");
glStencilFillPathNV(pathObj, GL_COUNT_UP_NV, 0x1F);
glEnable(GL_STENCIL_TEST);
int even_odd = 0;
if (even_odd) {
glStencilFunc(GL_NOTEQUAL, 0, 0x1);
} else {
glStencilFunc(GL_NOTEQUAL, 0, 0x1F); // make viewport black !?
}
glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
glColor3f(0,1,0); // green
glCoverFillPathNV(pathObj, GL_BOUNDING_BOX_NV);
glBegin(GL_TRIANGLES); //this renders correctly !
glVertex3f(0.8,0.9,0);
glVertex3f(0.9,0.9,0);
glVertex3f(0,0.4,0);
glEnd();
}
if (stroking) {
qDebug("stroking");
glStencilStrokePathNV(pathObj, 0x1, ~0);
glColor3f(1,1,0); // yellow
glCoverStrokePathNV(pathObj, GL_CONVEX_HULL_NV);
}
}
void GLWidget::resizeGL()
{
}