QOpenGLTexture* Model::TextureFromFile(QString path, QString directory) { //Generate texture ID and load texture data QString filename = path; filename = directory + '/' + filename; //glGenTextures(1, &textureID); //int width, height; QOpenGLTexture *texture = new QOpenGLTexture(QImage(filename).mirrored()); texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear); texture->setMagnificationFilter(QOpenGLTexture::Linear); texture->setWrapMode(QOpenGLTexture::Repeat); texture->setAutoMipMapGenerationEnabled(true); //unsigned char* image = SOIL_load_image(filename.c_str(), &width, &height, 0, SOIL_LOAD_RGB); // Assign texture to ID //glBindTexture(GL_TEXTURE_2D, textureID); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); //glGenerateMipmap(GL_TEXTURE_2D); // Parameters /*glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);*/ //glBindTexture(GL_TEXTURE_2D, 0); //SOIL_free_image_data(image); return texture; }
void Quiddiards::loadResources(){ for (unsigned i = 0; i < TEXNUM; i++){ std::string file = texFiles[i]; QImage image; /* add perlin noise to balls texture */ if (file == "quaffle.jpg"){ perlin(image, QColor(255, 0, 0, 0), 0.7); } else if (file == "bludger.jpg"){ perlin(image, QColor(0, 0, 255, 0), 0.7); } else if (file == "snitch.jpg"){ perlin(image, QColor(255, 214, 0, 0), 0.7); } else if (file == "cueball.jpg"){ perlin(image, QColor(240, 240, 240, 0), 0.7); } else{ image.load((":/images/" + file).c_str()); } QOpenGLTexture* tex = new QOpenGLTexture(image); tex->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); tex->setWrapMode(QOpenGLTexture::MirroredRepeat); textures[file] = tex; } }
QOpenGLTexture* Map::createTexture(QImage& image) { QOpenGLTexture* texture = new QOpenGLTexture(image); texture->setMinificationFilter(QOpenGLTexture::Filter::Nearest); texture->setMagnificationFilter(QOpenGLTexture::Filter::Nearest); return texture; }
GLuint NaviCubeImplementation::createCubeFaceTex(QtGLWidget* gl, float gap, float radius, const char* text) { int texSize = m_CubeWidgetSize* m_OverSample; int gapi = texSize * gap; int radiusi = texSize * radius; QImage image(texSize, texSize, QImage::Format_ARGB32); image.fill(qRgba(255, 255, 255, 0)); QPainter paint; paint.begin(&image); if (text) { paint.setPen(Qt::white); QFont sansFont(str("Helvetica"), 0.1875 * texSize); paint.setFont(sansFont); paint.drawText(QRect(0, 0, texSize, texSize), Qt::AlignCenter,qApp->translate("Gui::NaviCube",text)); } else { QPainterPath path; path.addRoundedRect(QRectF(gapi, gapi, texSize - 2 * gapi, texSize - 2 * gapi), radiusi, radiusi); paint.fillPath(path, Qt::white); } paint.end(); #if !defined(HAVE_QT5_OPENGL) return gl->bindTexture(image); #else Q_UNUSED(gl); QOpenGLTexture *texture = new QOpenGLTexture(image.mirrored()); m_glTextures.push_back(texture); return texture->textureId(); #endif }
bool loadSkyBoxTexture(QOpenGLTexture & tex, const char *posx, const char *negx, const char *posy, const char *negy, const char *posz, const char *negz) { if (!tex.create()) { ERRORM("Failed to create skybox texture's OpenGL object name"); return false; } tex.bind(); utils::misc::ScopedGuard guard([&tex] { tex.release(); }); (void) guard; if (!loadTextureHelper(posx, GL_TEXTURE_CUBE_MAP_POSITIVE_X)) return false; if (!loadTextureHelper(negx, GL_TEXTURE_CUBE_MAP_NEGATIVE_X)) return false; if (!loadTextureHelper(posy, GL_TEXTURE_CUBE_MAP_POSITIVE_Y)) return false; if (!loadTextureHelper(negy, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y)) return false; if (!loadTextureHelper(posz, GL_TEXTURE_CUBE_MAP_POSITIVE_Z)) return false; if (!loadTextureHelper(negz, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)) return false; OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); return true; }
GLuint AnimeGLWidget::bindTexture(QImage &image) { makeCurrent(); QOpenGLTexture *pTexture = new QOpenGLTexture(image.mirrored(), QOpenGLTexture::DontGenerateMipMaps); if (m_pSetting->getCheckLinearFilter()) { pTexture->setMinificationFilter(QOpenGLTexture::Nearest); pTexture->setMagnificationFilter(QOpenGLTexture::Linear); } doneCurrent(); return m_pTextureCacheManager->add(pTexture); }
void QGLView::drawTexts() { QList<Parameters*>* parametersList = getDrawableList(Text); if (parametersList->isEmpty()) { return; } m_textVertexBuffer->bind(); m_textProgram->enableAttributeArray(m_textPositionLocation); m_textProgram->enableAttributeArray(m_textTexCoordinateLocation); m_textProgram->setAttributeBuffer(m_textPositionLocation, GL_FLOAT, 0, 3, sizeof(TextVertex)); m_textProgram->setAttributeBuffer(m_textTexCoordinateLocation, GL_FLOAT, 3*sizeof(GLfloat), 2, sizeof(TextVertex)); for (int i = 0; i < parametersList->size(); ++i) { TextParameters *textParameters = static_cast<TextParameters*>(parametersList->at(i)); QStaticText staticText = textParameters->staticText; int textureIndex; QOpenGLTexture *texture; float aspectRatio; textureIndex = m_textTextList.indexOf(staticText); texture = m_textTextureList.at(textureIndex); aspectRatio = m_textAspectRatioList.at(textureIndex); if (!texture->isCreated()) // initialize texture on first use { createTextTexture(textParameters); } m_textProgram->setUniformValue(m_textAspectRatioLocation, aspectRatio); m_textProgram->setUniformValue(m_textAlignmentLocation, (GLint)textParameters->alignment); m_textProgram->setUniformValue(m_textColorLocation, textParameters->color); m_textProgram->setUniformValue(m_textModelMatrixLocation, textParameters->modelMatrix); m_textProgram->setUniformValue(m_textTextureLocation, texture->textureId()); if (m_selectionModeActive) // selection mode active { m_textProgram->setUniformValue(m_textIdColorLocation, QColor(0xFF000000u + m_currentDrawableId)); // color for selection mode m_drawableIdMap.insert(m_currentDrawableId, textParameters); m_currentDrawableId++; } texture->bind(texture->textureId()); glDrawArrays(GL_TRIANGLES, 0, m_textVertexBuffer->size()/sizeof(TextVertex)); texture->release(texture->textureId()); } m_textProgram->disableAttributeArray(m_textPositionLocation); m_textProgram->disableAttributeArray(m_textTexCoordinateLocation); m_textVertexBuffer->release(); }
bool load2DTexture(QOpenGLTexture & tex, const char *name, GLint internal_format, GLint filter_mode, GLint clamp_mode) { if (!tex.create()) { ERRORM("Failed to create 2D texture's OpenGL object name"); return false; } tex.bind(); utils::misc::ScopedGuard guard([&tex] { tex.release(); }); (void) guard; if (!loadTextureHelper(name, GL_TEXTURE_2D, internal_format)) return false; OGLF->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_mode); OGLF->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_mode); OGLF->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp_mode); OGLF->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp_mode); return true; }
void QGLView::createTextTexture(TextParameters *textParameters) { int textureIndex = m_textTextList.indexOf(textParameters->staticText); QOpenGLTexture *texture = m_textTextureList.at(textureIndex); texture->create(); texture->setMinificationFilter(QOpenGLTexture::Nearest); texture->setMagnificationFilter(QOpenGLTexture::Nearest); texture->setWrapMode(QOpenGLTexture::ClampToEdge); texture->setData(m_textImageList.at(textureIndex)); }
GLuint NaviCubeImplementation::createMenuTex(QtGLWidget* gl, bool forPicking) { int texSize = m_CubeWidgetSize* m_OverSample; QImage image(texSize, texSize, QImage::Format_ARGB32); image.fill(qRgba(0, 0, 0, 0)); QPainter painter; painter.begin(&image); QTransform transform; transform.translate(texSize * 12 / 16, texSize * 13 / 16); transform.scale(texSize/200.0,texSize/200.0); // 200 == size at which this was designed painter.setTransform(transform); QPainterPath path; if (forPicking) { path.addRoundedRect(-25,-8,75,45,6,6); painter.fillPath(path, Qt::white); } else { // top path.moveTo(0,0); path.lineTo(15,5); path.lineTo(0,10); path.lineTo(-15,5); painter.fillPath(path, QColor(240,240,240)); // left QPainterPath path2; path2.lineTo(0,10); path2.lineTo(-15,5); path2.lineTo(-15,25); path2.lineTo(0,30); painter.fillPath(path2, QColor(190,190,190)); // right QPainterPath path3; path3.lineTo(0,10); path3.lineTo(15,5); path3.lineTo(15,25); path3.lineTo(0,30); painter.fillPath(path3, QColor(220,220,220)); // outline QPainterPath path4; path4.moveTo(0,0); path4.lineTo(15,5); path4.lineTo(15,25); path4.lineTo(0,30); path4.lineTo(-15,25); path4.lineTo(-15,5); path4.lineTo(0,0); painter.strokePath(path4, QColor(128,128,128)); // menu triangle QPainterPath path5; path5.moveTo(20,10); path5.lineTo(40,10); path5.lineTo(30,20); path5.lineTo(20,10); painter.fillPath(path5, QColor(64,64,64)); } painter.end(); #if !defined(HAVE_QT5_OPENGL) return gl->bindTexture(image); #else Q_UNUSED(gl); QOpenGLTexture *texture = new QOpenGLTexture(image.mirrored()); m_glTextures.push_back(texture); return texture->textureId(); #endif }
GLuint NaviCubeImplementation::createButtonTex(QtGLWidget* gl, int button) { int texSize = m_CubeWidgetSize * m_OverSample; QImage image(texSize, texSize, QImage::Format_ARGB32); image.fill(qRgba(255, 255, 255, 0)); QPainter painter; painter.begin(&image); QTransform transform; transform.translate(texSize / 2, texSize / 2); transform.scale(texSize / 2, texSize / 2); painter.setTransform(transform); QPainterPath path; float as1 = 0.12f; // arrow size float as3 = as1 / 3; switch (button) { default: break; case TEX_ARROW_RIGHT: case TEX_ARROW_LEFT: { QRectF r(-1.00, -1.00, 2.00, 2.00); QRectF r0(r); r.adjust(as3, as3, -as3, -as3); QRectF r1(r); r.adjust(as3, as3, -as3, -as3); QRectF r2(r); r.adjust(as3, as3, -as3, -as3); QRectF r3(r); r.adjust(as3, as3, -as3, -as3); QRectF r4(r); float a0 = 72; float a1 = 45; float a2 = 38; if (TEX_ARROW_LEFT == button) { a0 = 180 - a0; a1 = 180 - a1; a2 = 180 - a2; } path.arcMoveTo(r0, a1); QPointF p0 = path.currentPosition(); path.arcMoveTo(r2, a2); QPointF p1 = path.currentPosition(); path.arcMoveTo(r4, a1); QPointF p2 = path.currentPosition(); path.arcMoveTo(r1, a0); path.arcTo(r1, a0, -(a0 - a1)); path.lineTo(p0); path.lineTo(p1); path.lineTo(p2); path.arcTo(r3, a1, +(a0 - a1)); break; } case TEX_ARROW_EAST: { path.moveTo(1, 0); path.lineTo(1 - as1, +as1); path.lineTo(1 - as1, -as1); break; } case TEX_ARROW_WEST: { path.moveTo(-1, 0); path.lineTo(-1 + as1, -as1); path.lineTo(-1 + as1, +as1); break; } case TEX_ARROW_SOUTH: { path.moveTo(0, 1); path.lineTo(-as1,1 - as1); path.lineTo(+as1,1 - as1); break; } case TEX_ARROW_NORTH: { path.moveTo(0, -1); path.lineTo(+as1,-1 + as1); path.lineTo(-as1,-1 + as1); break; } } painter.fillPath(path, Qt::white); painter.end(); //image.save(str(enum2str(button))+str(".png")); #if !defined(HAVE_QT5_OPENGL) return gl->bindTexture(image); #else Q_UNUSED(gl); QOpenGLTexture *texture = new QOpenGLTexture(image.mirrored()); m_glTextures.push_back(texture); return texture->textureId(); #endif }
void SceneObject::draw(ShaderStack *stack) { bool shaderOverridden = false; if ( !geometry()->isEmpty() ) { // If we have a shader override, push the override. QString shaderOverrideName = geometry()->shaderOverride(); if ( !shaderOverrideName.isNull() ) { ShaderProgram* program = resourceManager()->shader(shaderOverrideName); if ( program ) { shaderOverridden = true; stack->shaderPush(program); } } } // Multiply the modelWorld matrix by our current one. // This updates the shader uniform too. // We do this even if the geometry is empty, so that the // transformation will apply recursively. // It is the caller's responsibility to manage pushing // and popping of the m2w matrix. stack->modelToWorldPostMultiply(localToParent()); if ( !geometry()->isEmpty() ) { // Upload and bind the geometry. geometry()->upload(); geometry()->bindVertices(true); geometry()->bindIndices(true); // Apply the data format. geometry()->applyDataFormat(stack->shaderTop()); // If we're selected, set the global colour. bool pushedColor = false; MapDocument* doc = m_pScene->document(); if ( doc->selectedSet().contains(this) ) { pushedColor = true; stack->globalColorPush(); stack->globalColorSetTop(doc->selectedColor()); } // Apply the texture. QOpenGLTexture* tex = resourceManager()->texture(geometry()->texture(0)); tex->bind(0); // Draw. geometry()->draw(); if ( pushedColor ) { stack->globalColorPop(); } // Pop the shader if we pushed one earlier. if ( shaderOverridden ) { stack->shaderPop(); } } }
void AnimeGLWidget::paintGL() { QColor col = m_pSetting->getAnimeBGColor(); if (m_pEditData->isExportPNG()) { col.setAlphaF(0); } glClearColor(col.redF(), col.greenF(), col.blueF(), col.alphaF()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_matProj.setToIdentity(); m_matProj.ortho(-m_DrawWidth / 2, m_DrawWidth / 2, m_DrawHeight / 2, -m_DrawHeight / 2, -10000, 10000); m_lineShaderProgram.bind(); m_lineShaderProgram.setUniformValue("mvp_matrix", m_matProj); if (m_pSetting->getUseDepthTest()) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } // 背景画像描画 if (m_backImageTex) { RectF rect; RectF uvF; QColor col = QColor(255, 255, 255, 255); m_textureShaderProgram.bind(); QOpenGLTexture *pTex = m_pTextureCacheManager->get(m_backImageTex); if (pTex) { pTex->bind(); } m_textureShaderProgram.setUniformValue("mvp_matrix", m_matProj); rect.setRect(-m_backImageW / 2, m_backImageH / 2, m_backImageW, -m_backImageH); uvF.setRect(0.0, (float)(m_BackImage.height() - m_backImageH) / m_BackImage.height(), (float)m_backImageW / m_BackImage.width(), (float)m_backImageH / m_BackImage.height()); drawRect(rect, uvF, -9999.9, col); } if (m_pEditData) { drawLayers(); } bool bDepth = glIsEnabled(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST); if (m_bDrawGrid) { if (!m_pEditData->isExportPNG()) { drawGrid(); } } // センター if (m_pSetting->getDrawCenter()) { if (!m_pEditData->isExportPNG()) { drawCenter(); } } // PNG吐き出しモード if (m_pEditData->getEditMode() == EditData::kEditMode_ExportPNG && !m_pEditData->isExportPNG()) { int rect[4]; QColor col = QColor(255, 0, 0, 255); m_pEditData->getExportPNGRect(rect); drawLine(QPoint(rect[0], rect[1]), QPoint(rect[2], rect[1]), col, 1.0); drawLine(QPoint(rect[2], rect[1]), QPoint(rect[2], rect[3]), col, 1.0); drawLine(QPoint(rect[2], rect[3]), QPoint(rect[0], rect[3]), col, 1.0); drawLine(QPoint(rect[0], rect[3]), QPoint(rect[0], rect[1]), col, 1.0); } if (bDepth) { glEnable(GL_DEPTH_TEST); } }