void PlaneViewer::draw(TVectorImageP vi) { TRectD bbox(vi->getBBox()); TRect bboxI(tfloor(bbox.x0), tfloor(bbox.y0), tceil(bbox.x1) - 1, tceil(bbox.y1) - 1); TVectorRenderData rd(TAffine(), bboxI, vi->getPalette(), 0, true, true); tglDraw(rd, vi.getPointer()); }
void ToonzExt::OverallDesigner::draw(ToonzExt::CornerDeformation *sd) { #ifdef _DEBUG glPushMatrix(); { this->setPosition(); TCubic c; c.setP0(TPointD(0.0, 0.0)); c.setP1(TPointD(0.0, 12.0)); c.setP2(TPointD(6.0, 12.0)); c.setP3(TPointD(12.0, 12.0)); glColor3d(1.0, 0.0, 1.0); tglDraw(c, 100, GL_LINE); c.setP0(TPointD(12.0, 12.0)); c.setP1(TPointD(6.0, 8.0)); c.setP2(TPointD(6.0, 4.0)); c.setP3(TPointD(12.0, 0.0)); tglDraw(c, 100, GL_LINE); } glPopMatrix(); #endif }
void MorphTool::draw() { m_pixelSize = sqrt(tglGetPixelSize2()); if (m_vi2) { TVectorRenderData rd(TTranslation(10, 10), TRect(), 0, 0); tglDraw(rd, m_vi2.getPointer()); } double u = m_pixelSize * 5; for (int i = 0; i < (int)deformation.m_controlPoints.size(); i++) { TPointD p = deformation.m_controlPoints[i]; bool selected = deformation.m_selected == i; bool base = (i & 1) == 0; if (base) if (selected) glColor3d(0.8, 0.8, 0.1); else glColor3d(0.5, 0.5, 0.1); else if (selected) glColor3d(0.8, 0.3, 0.1); else glColor3d(0.5, 0.1, 0.1); double r = base ? u * 2 : u * 1; tglDrawDisk(p, r); glColor3d(0, 0, 0); tglDrawCircle(p, r); } glColor3f(0, 1, 0); for (int i = 0; i + 1 < (int)deformation.m_controlPoints.size(); i += 2) { TPointD a = deformation.m_controlPoints[i]; TPointD b = deformation.m_controlPoints[i + 1]; tglDrawSegment(a, b); } /* deformation.update(); glBegin(GL_LINES); for(double x = -200; x<=200; x+=20) for(double y = -200; y<=200; y+=20) { TPointD p0(x,y); TPointD p1 = deformation.apply(p0); glColor3d(0,1,0); tglVertex(p0); glColor3d(1,0,0); tglVertex(p1); } glEnd(); */ }
void tglDraw(const TRectD &rect, const std::vector<TRaster32P> &textures, bool blending) { double pixelSize2 = tglGetPixelSize2(); // level e' la minore potenza di 2 maggiore di sqrt(pixelSize2) unsigned int level = 1; while (pixelSize2 * level * level <= 1.0) level <<= 1; unsigned int texturesCount = (int)textures.size(); if (level > texturesCount) level = texturesCount; level = texturesCount - level; tglDraw(rect, textures[level], blending); }
TImageP ImageRasterizer::build(int imFlags, void *extData) { assert(!(imFlags & ~(ImageManager::dontPutInCache | ImageManager::forceRebuild))); TDimension d(10, 10); TPoint off(0, 0); // Fetch image assert(extData); ImageLoader::BuildExtData *data = (ImageLoader::BuildExtData *)extData; const std::string &srcImgId = data->m_sl->getImageId(data->m_fid); TImageP img = ImageManager::instance()->getImage(srcImgId, imFlags, extData); if (img) { TVectorImageP vi = img; if (vi) { TRectD bbox = vi->getBBox(); d = TDimension(tceil(bbox.getLx()) + 1, tceil(bbox.getLy()) + 1); off = TPoint((int)bbox.x0, (int)bbox.y0); TPalette *vpalette = vi->getPalette(); TVectorRenderData rd(TTranslation(-off.x, -off.y), TRect(TPoint(0, 0), d), vpalette, 0, true, true); TGlContext oldContext = tglGetCurrentContext(); // this is too slow. { QSurfaceFormat format; format.setProfile(QSurfaceFormat::CompatibilityProfile); TRaster32P ras(d); glPushAttrib(GL_ALL_ATTRIB_BITS); glMatrixMode(GL_MODELVIEW), glPushMatrix(); glMatrixMode(GL_PROJECTION), glPushMatrix(); { std::unique_ptr<QOpenGLFramebufferObject> fb(new QOpenGLFramebufferObject(d.lx, d.ly)); fb->bind(); assert(glGetError() == 0); glViewport(0, 0, d.lx, d.ly); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, d.lx, 0, d.ly); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.375, 0.375, 0.0); assert(glGetError() == 0); tglDraw(rd, vi.getPointer()); assert(glGetError() == 0); assert(glGetError() == 0); glFlush(); assert(glGetError() == 0); QImage img = fb->toImage().scaled(QSize(d.lx, d.ly), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); int wrap = ras->getLx() * sizeof(TPixel32); uchar *srcPix = img.bits(); uchar *dstPix = ras->getRawData() + wrap * (d.ly - 1); for (int y = 0; y < d.ly; y++) { memcpy(dstPix, srcPix, wrap); dstPix -= wrap; srcPix += wrap; } fb->release(); } glMatrixMode(GL_MODELVIEW), glPopMatrix(); glMatrixMode(GL_PROJECTION), glPopMatrix(); glPopAttrib(); tglMakeCurrent(oldContext); TRasterImageP ri = TRasterImageP(ras); ri->setOffset(off + ras->getCenter()); return ri; } } } // Error case: return a dummy image (is it really required?) TRaster32P ras(d); ras->fill(TPixel32(127, 0, 127, 127)); return TRasterImageP(ras); }