GraphicsContext3DPrivate::GraphicsContext3DPrivate(GraphicsContext3D* context, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) : m_context(context) , m_hostWindow(hostWindow) , m_surface(0) , m_platformContext(0) , m_surfaceOwner(0) , m_platformContextWatcher(0) { if (renderStyle == GraphicsContext3D::RenderToCurrentGLContext) { m_platformContext = QOpenGLContext::currentContext(); if (m_platformContext) m_surface = m_platformContext->surface(); // Watcher needed to invalidate the GL context if destroyed before this instance m_platformContextWatcher = new QtContextWatcher(m_platformContext, this); initializeOpenGLFunctions(); return; } QOpenGLContext* shareContext = 0; if (hostWindow && hostWindow->platformPageClient()) shareContext = hostWindow->platformPageClient()->openGLContextIfAvailable(); QOffscreenSurface* surface = new QOffscreenSurface; surface->create(); m_surface = surface; m_surfaceOwner = surface; m_platformContext = new QOpenGLContext(m_surfaceOwner); if (shareContext) m_platformContext->setShareContext(shareContext); if (!m_platformContext->create()) { delete m_platformContext; m_platformContext = 0; return; } makeCurrentIfNeeded(); initializeOpenGLFunctions(); #if USE(GRAPHICS_SURFACE) IntSize surfaceSize(m_context->m_currentWidth, m_context->m_currentHeight); m_surfaceFlags = GraphicsSurface::SupportsTextureTarget | GraphicsSurface::SupportsSharing; if (!surfaceSize.isEmpty()) m_graphicsSurface = GraphicsSurface::create(surfaceSize, m_surfaceFlags, m_platformContext); #endif }
void Viewer::init() { // Restore previous viewer state. restoreStateFromFile(); initializeOpenGLFunctions(); // Define 'Control+Q' as the new exit shortcut (default was 'Escape') setShortcut(CGAL::qglviewer::EXIT_VIEWER, Qt::CTRL+Qt::Key_Q); // Add custom key description (see keyPressEvent). setKeyDescription(Qt::Key_W, "Toggles wire frame display"); setKeyDescription(Qt::Key_F, "Toggles flat shading display"); setKeyDescription(Qt::Key_E, "Toggles edges display"); setKeyDescription(Qt::Key_V, "Toggles vertices display"); setKeyDescription(Qt::Key_N, "Inverse direction of normals"); setKeyDescription(Qt::Key_Plus, "Increase size of edges"); setKeyDescription(Qt::Key_Minus, "Decrease size of edges"); setKeyDescription(Qt::Key_Plus+Qt::ShiftModifier, "Increase size of vertices"); setKeyDescription(Qt::Key_Minus+Qt::ShiftModifier, "Decrease size of vertices"); setKeyDescription(Qt::Key_PageDown, "Increase light (all colors, use shift/alt/ctrl for one rgb component)"); setKeyDescription(Qt::Key_PageUp, "Decrease light (all colors, use shift/alt/ctrl for one rgb component)"); // Light default parameters glLineWidth(size_edges); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f,1.0f); glClearColor(1.0f,1.0f,1.0f,0.0f); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); glDisable(GL_POLYGON_SMOOTH_HINT); glBlendFunc(GL_ONE, GL_ZERO); glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); compile_shaders(); }
void init(QOpenGLContext* ctx) { glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)ctx->getProcAddress("glFramebufferTexture"); if(!ctx->isOpenGLES()) initializeOpenGLFunctions(); }
CardBuffer::CardBuffer(const CardBuilder& builder) : _specifications(builder.specifications()) { initializeOpenGLFunctions(); _object = builder.bufferObject(*this); glGenBuffers(BufferCount, _buffers); _topCount = builder.topIndices().size(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffers[TopIndex]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, _topCount * sizeof(GLushort), builder.topIndices().constData(), GL_STATIC_DRAW); _middleCount = builder.middleIndices().size(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffers[MiddleIndex]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, _middleCount * sizeof(GLushort), builder.middleIndices().constData(), GL_STATIC_DRAW); _bottomCount = builder.bottomIndices().size(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffers[BottomIndex]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, _bottomCount * sizeof(GLushort), builder.bottomIndices().constData(), GL_STATIC_DRAW); }
void MainWidget::initializeGL() { initializeOpenGLFunctions(); connect(this, SIGNAL(frameSwapped()), this, SLOT(update())); //animationTimer.setSingleShot(true); //connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate())); distance = -4; trackball = TrackBall(0.0f, QVector3D(0, 1, 0), TrackBall::Sphere); glClearColor(0.05, 0.05, 0.05, 1); // Enable depth buffer glEnable(GL_DEPTH_TEST); // Enable back face culling glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); initShaders(); initTextures(); geometries = new GeometryEngine(&programearth, &programearthnobump); gshhs = new gshhsData(&programgshhs); skybox = new SkyBox(&programskybox); }
GraphicsLayer13::GraphicsLayer13() { initializeOpenGLFunctions(); AppearanceDialog::setBevelsEnabled(true); // Disable unused OpenGL features glDisable(GL_LIGHTING); glDisable(GL_BLEND); // Enable OpenGL features glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnableClientState(GL_VERTEX_ARRAY); // Set OpenGL parameters glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); glFrontFace(GL_CCW); setColor(Qt::white); glActiveTexture(GL_TEXTURE1); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED); glActiveTexture(GL_TEXTURE0); }
void TFInteg2DGL::newResources(int resolution) { auto f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_3_Core>(); f->initializeOpenGLFunctions(); // painter painter.initializeGL(":/volren/shaders/quad.vert", ":/volren/shaders/transferfunction/tfinteg2d.frag"); // new texture 1d tex1d.reset(new QOpenGLTexture(QOpenGLTexture::Target1D)); tex1d->setFormat(QOpenGLTexture::RGBA32F); tex1d->setMinMagFilters(QOpenGLTexture::Nearest, QOpenGLTexture::Nearest); tex1d->setWrapMode(QOpenGLTexture::ClampToEdge); tex1d->setSize(resolution); tex1d->allocateStorage(); // new texture full texFull.reset(new QOpenGLTexture(QOpenGLTexture::Target2D)); texFull->setFormat(QOpenGLTexture::RGBA32F); texFull->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); texFull->setWrapMode(QOpenGLTexture::ClampToEdge); texFull->setSize(resolution, resolution); texFull->allocateStorage(); // new texture back texBack.reset(new QOpenGLTexture(QOpenGLTexture::Target2D)); texBack->setFormat(QOpenGLTexture::RGBA32F); texBack->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); texBack->setWrapMode(QOpenGLTexture::ClampToEdge); texBack->setSize(resolution, resolution); texBack->allocateStorage(); // new fbo newFbo(); }
/** This initilizes the texture map in opengl */ void cwImageTexture::initialize() { initializeOpenGLFunctions(); glGenTextures(1, &TextureId); glBindTexture(GL_TEXTURE_2D, TextureId); #ifdef Q_OS_WIN //Only upload one texture, GL_LINEAR, because some intel cards, //don't support npot dxt1 copression, so we just used GL_LINEAR //FIXME: ADD to rendering settings! Use mipmaps. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); #else //All other platforms GLfloat fLargest; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest); #endif glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glBindTexture(GL_TEXTURE_2D, 0); }
void OpenGLWindow::initializeGL() { initializeOpenGLFunctions(); // // shader program // m_program.reset(new QOpenGLShaderProgram(this)); m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vshader.glsl"); m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fshader.glsl"); m_program->link(); m_program->bind(); // // variables // m_vertexLocation = m_program->attributeLocation("vertex"); m_colorLocation = m_program->attributeLocation("sourceColor"); m_program->enableAttributeArray(m_vertexLocation); m_program->enableAttributeArray(m_colorLocation); m_matrixLocation = m_program->uniformLocation("matrix"); }
void MapWidget::initializeGL() { initializeOpenGLFunctions(); QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION)))); QOpenGLContext *ctx = QOpenGLContext::currentContext(); Q_UNUSED(ctx); lg = new QOpenGLDebugLogger(context()); lg->initialize(); lg->startLogging(QOpenGLDebugLogger::SynchronousLogging); lg->enableMessages(); connect(lg, SIGNAL(messageLogged(QOpenGLDebugMessage)), this, SLOT(glLog(QOpenGLDebugMessage))); qDebug() << "Driver Version String:" << versionString; qDebug() << "Current Context:" << ctx->format(); //glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &gpuTotalMemory); //qDebug() << "total" << gpuTotalMemory; m_renderer = new Renderer(); m_renderer->createStaticResources(); //m_painterOverlay = new PainterOverlay(); }
void QFFmpegGLWidget::initializeGL() { initializeOpenGLFunctions(); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glEnable(GL_TEXTURE_2D); /* The following three commented lines if uncommented generate following errors: * undefined reference to `_imp__glShadeModel@4' * undefined reference to `_imp__glClearDepth@8' * bad reloc address 0x20 in section `.eh_frame' */ // glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // glClearDepth(1.0f); // glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //--------------------- m_vshaderA = new QOpenGLShader(QOpenGLShader::Vertex); m_vshaderA->compileSourceCode(g_vertextShader); m_fshaderA = new QOpenGLShader(QOpenGLShader::Fragment); m_fshaderA->compileSourceCode(g_fragmentShader); m_programA = new QOpenGLShaderProgram; m_programA->addShader(m_vshaderA); m_programA->addShader(m_fshaderA); m_programA->link(); int positionHandle=m_programA->attributeLocation("aPosition"); int textureHandle=m_programA->attributeLocation("aTextureCoord"); glVertexAttribPointer(positionHandle, 3, GL_FLOAT, false, 5 * sizeof(GLfloat), m_verticesA); glEnableVertexAttribArray(positionHandle); glVertexAttribPointer(textureHandle, 2, GL_FLOAT, false, 5 * sizeof(GLfloat), &m_verticesA[3]); glEnableVertexAttribArray(textureHandle); int i=m_programA->uniformLocation("Ytex"); glUniform1i(i, 0); i=m_programA->uniformLocation("Utex"); glUniform1i(i, 1); i=m_programA->uniformLocation("Vtex"); glUniform1i(i, 2); // glViewport(0, 0, width, height); //timer->start(30); }
void OpenGLWindow::renderNow() { if (!isExposed()) return; bool needsInitialize = false; // Create an OpenGL context if there is not any if (!m_context) { m_context = new QOpenGLContext(this); m_context->setFormat(requestedFormat()); m_context->create(); needsInitialize = true; } m_context->makeCurrent(this); m_funcs = m_context->versionFunctions<QOpenGLFunctions_3_3_Core>(); if (needsInitialize) { initializeOpenGLFunctions(); initialize(); } render(); m_context->swapBuffers(this); }
void SurfaceGraph::initializeGL() { initializeOpenGLFunctions(); glClearColor(0, 0, 0, 1); initShaders(); initTextures(); // Enable depth buffer glEnable(GL_DEPTH_TEST); // Enable back face culling glEnable(GL_CULL_FACE); // Change znear - zfar double fovy = 45.0f; double aspect = 1.333f; double zNear = 0.1f; double zFar = 100.0f; GLdouble xmin, xmax, ymin, ymax; ymax = zNear * tan( fovy * M_PI / 360.0 ); ymin = -ymax; xmin = ymin * aspect; xmax = ymax * aspect; glFrustum( xmin, xmax, ymin, ymax, zNear, zFar ); geometries = new GeometryEngine; // Use QBasicTimer because its faster than QTimer timer.start(12, this); }
void XYZ::initVertexBufferObjects() { initializeOpenGLFunctions(); m_vertices = new Vertex[6]; //Possisjon m_vertices[0].set_xyz(0.0, 0.0, 0.0); m_vertices[1].set_xyz(1.0, 0.0, 0.0); m_vertices[2].set_xyz(0.0, 0.0, 0.0); m_vertices[3].set_xyz(0.0, 1.0, 0.0); m_vertices[4].set_xyz(0.0, 0.0, 0.0); m_vertices[5].set_xyz(0.0, 0.0, 1.0); //Farge m_vertices[0].set_rgb(1.0, 0.0, 0.0); m_vertices[1].set_rgb(1.0, 0.0, 0.0); m_vertices[2].set_rgb(0.0, 1.0, 0.0); m_vertices[3].set_rgb(0.0, 1.0, 0.0); m_vertices[4].set_rgb(0.0, 0.0, 1.0); m_vertices[5].set_rgb(0.0, 0.0, 1.0); //Sender vertex possisjon og fargedata til et buffer glGenBuffers(1, &m_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); glBufferData(GL_ARRAY_BUFFER, 6*sizeof(Vertex), m_vertices, GL_STATIC_DRAW); }
SegmentGL::SegmentGL(QOpenGLShaderProgram *prog, SatelliteList *satlist, AVHRRSatellite *seglist ) { sats = satlist; segs = seglist; program = prog; initializeOpenGLFunctions(); program->bind(); vao.create(); QOpenGLVertexArrayObject::Binder vaoBinder(&vao); positionsBuf.create(); positionsBuf.setUsagePattern(QOpenGLBuffer::DynamicDraw); positionsBuf.bind(); nbrOfVertices = 50; positionsBuf.allocate( nbrOfVertices * 3 * sizeof(GLfloat)); vertexPosition = program->attributeLocation("VertexPosition"); program->enableAttributeArray(vertexPosition); program->setAttributeBuffer(vertexPosition, GL_FLOAT, 0, 3); }
void Viewer::init() { // Restore previous viewer state. restoreStateFromFile(); initializeOpenGLFunctions(); // Define 'Control+Q' as the new exit shortcut (default was 'Escape') setShortcut(EXIT_VIEWER, Qt::CTRL+Qt::Key_Q); // Add custom key description (see keyPressEvent). setKeyDescription(Qt::Key_W, "Toggles wire frame display"); setKeyDescription(Qt::Key_F, "Toggles flat shading display"); setKeyDescription(Qt::Key_E, "Toggles edges display"); setKeyDescription(Qt::Key_V, "Toggles vertices display"); // Light default parameters ::glLineWidth(1.4f); ::glPointSize(4.f); ::glEnable(GL_POLYGON_OFFSET_FILL); ::glPolygonOffset(1.0f,1.0f); ::glClearColor(1.0f,1.0f,1.0f,0.0f); ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); ::glEnable(GL_LIGHTING); ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); ::glShadeModel(GL_FLAT); ::glDisable(GL_BLEND); ::glDisable(GL_LINE_SMOOTH); ::glDisable(GL_POLYGON_SMOOTH_HINT); ::glBlendFunc(GL_ONE, GL_ZERO); ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); compile_shaders(); }
void TriangleSurface::draw(GLint positionAttribute, GLint normalAttribute, GLint textureAttribute) { // Har en array av strukturer (noen Vertex objekter) som skal splittes på to // attributter i vertex shader. stride blir her størrelsen av hver struktur // Må bruke offset for start initializeOpenGLFunctions();//makeCurrent(); int offset = 0; glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); glVertexAttribPointer(positionAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const void*> (offset)); offset = 3*sizeof(GLfloat); glVertexAttribPointer(normalAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const void*> (offset)); // Tekstur if (textureAttribute != -1) { //glUniform1i(colorAttribute, 0); offset = 6*sizeof(GLfloat); //glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer); glVertexAttribPointer(textureAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const void*> (offset)); //glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_texture); } //glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); glDrawArrays(GL_TRIANGLES, 0, m_antallVertices); //qDebug() << "TriangleSurface::draw() " << ++i; }
bool QVROSGViewer::initProcess(QVRProcess* /* p */) { // Qt-based OpenGL function pointers initializeOpenGLFunctions(); // FBO glGenFramebuffers(1, &_fbo); glBindFramebuffer(GL_FRAMEBUFFER, _fbo); glGenTextures(1, &_fboDepthTex); glBindTexture(GL_TEXTURE_2D, _fboDepthTex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _fboDepthTex, 0); // OSG // Since we always only have to deal with one OpenGL context, we set up // just one graphics window with a dummy size, and in render() resize and // reuse it as necessary. _graphicsWindow = _viewer.setUpViewerAsEmbeddedInWindow(0, 0, 640, 480); _viewer.setSceneData(_model.get()); _viewer.realize(); return true; }
GLSubView::GLSubView(Session *sPtr, QWidget *parent) : QGLWidget(parent), sessionPtr(sPtr) { makeCurrent(); initializeOpenGLFunctions(); glGenBuffers(1, &gratVBO); glGenBuffers(1, &gratBorderVBO); glBindBuffer(GL_ARRAY_BUFFER, gratVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(linearInnerPoints), linearInnerPoints, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, gratBorderVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(linearBorderPoints), linearBorderPoints, GL_DYNAMIC_DRAW); innerGratPoints = linearInnerCount; borderGratPoints = linearBorderCount; doneCurrent(); setAutoFillBackground(false); }
TexturedCubeRenderer( TexturedCube* const cube ): m_cube( cube ), m_vertexBuffer( QOpenGLBuffer::VertexBuffer ), m_texture( QOpenGLTexture::Target2D ) { initializeOpenGLFunctions( ); // 创建着色器、顶点缓存以及纹理 const char* vertexShaderSource = "attribute highp vec3 position;\ attribute highp vec3 normal;\ attribute highp vec2 texCoord;\ uniform mat4 modelMatrix;\ uniform mat4 viewMatrix;\ uniform mat4 projectionMatrix;\ varying highp vec2 v_texCoord;\ varying highp vec3 v_normal;\ void main( void )\ {\ gl_Position = projectionMatrix *\ viewMatrix *\ modelMatrix *\ vec4( position, 1.0 );\ v_texCoord = texCoord;\ v_normal = normal;\ }";
void TFInteg2DGL::newFbo() { auto f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_3_Core>(); f->initializeOpenGLFunctions(); // new fbo fbo.reset([](){ GLuint* fboPtr = new GLuint(); QOpenGLContext::currentContext()->functions()->glGenFramebuffers(1, fboPtr); return fboPtr; }(), [](GLuint* fboPtr){ QOpenGLContext::currentContext()->functions()->glDeleteFramebuffers(1, fboPtr); }); GLint oFbo; f->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oFbo); f->glBindFramebuffer(GL_FRAMEBUFFER, *fbo); f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texFull->textureId(), 0); f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texBack->textureId(), 0); GLenum bufs[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; f->glDrawBuffers(2, bufs); f->glBindFramebuffer(GL_FRAMEBUFFER, oFbo); GLenum status; status = f->glCheckFramebufferStatus(GL_FRAMEBUFFER); switch (status) { case GL_FRAMEBUFFER_COMPLETE: break; default: std::cout << "framebuffer back incomplete" << std::endl; } }
void QtVLCWidget::initializeGL() { // In this example the widget's corresponding top-level window can change // several times during the widget's lifetime. Whenever this happens, the // QOpenGLWidget's associated context is destroyed and a new one is created. // Therefore we have to be prepared to clean up the resources on the // aboutToBeDestroyed() signal, instead of the destructor. The emission of // the signal will be followed by an invocation of initializeGL() where we // can recreate all resources. connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &QtVLCWidget::cleanup); initializeOpenGLFunctions(); vertexBuffer.create(); vertexBuffer.bind(); vertexBuffer.allocate(g_vertex_buffer_data, sizeof(g_vertex_buffer_data)); vertexIndexBuffer.create(); vertexIndexBuffer.bind(); vertexIndexBuffer.allocate(g_element_buffer_data, sizeof(g_element_buffer_data)); m_program = new QOpenGLShaderProgram; m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); m_program->link(); m_program->setUniformValue("texture", 0); m_program->bindAttributeLocation("position", 0); }
TextureWriter::TextureWriter(QOpenGLShaderProgram *prog) { program = prog; initializeOpenGLFunctions(); program->bind(); vao.create(); QOpenGLVertexArrayObject::Binder vaoBinder(&vao); positionsBuf.create(); positionsBuf.setUsagePattern(QOpenGLBuffer::DynamicDraw); positionsBuf.bind(); vertexPosition = program->attributeLocation("VertexPosition"); program->enableAttributeArray(vertexPosition); program->setAttributeBuffer(vertexPosition, GL_FLOAT, 0, 2); texcoordBuf.create(); texcoordBuf.setUsagePattern(QOpenGLBuffer::DynamicDraw); texcoordBuf.bind(); vertexTexCoord = program->attributeLocation("VertexTexCoord"); program->enableAttributeArray(vertexTexCoord); program->setAttributeBuffer(vertexTexCoord, GL_FLOAT, 0, 1); glGenTextures(1, &texturelineId); }
bool Painter::initialize() { initializeOpenGLFunctions(); glClearColor(1.f, 1.f, 1.f, 0.f); m_transform.scale(2.f, 0.16f, 2.f); m_transform.translate(-.5f, 0.f, -.5f); // prepare vao and vbo m_vao.create(); m_vao.bind(); m_vertices.create(); m_vertices.setUsagePattern(QOpenGLBuffer::StaticDraw); glEnableVertexAttribArray(0); m_vao.release(); // create Texture m_height = getOrCreateTexture("data/height.png"); // create shader program m_program = createBasicShaderProgram("data/exercise6.vert", "data/exercise6.frag"); return true; }
void Grid::render() { initializeOpenGLFunctions(); // Alpha glEnable (GL_BLEND); if (alwaysVisible) glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); for (auto i : mcs) { QColor c = i.color(); glColor4f(c.red()/255.f, c.green()/255.f, c.blue()/255.f, c.alpha()/255.f); glVertex2f(i.rx(), i.ry()); } glEnd(); // Reset color to white glColor4f(1,1,1,1); glDisable(GL_BLEND); }
cubemaker::cubemaker() : indexBuf(QOpenGLBuffer::IndexBuffer) { // Generate 2 VBOs initializeOpenGLFunctions(); makeCubePls(); }
Scene::Scene() { initializeOpenGLFunctions(); this->setSkyBox(NULL); m_root.setName ("root"); this->setRenderType (DEFERRED_SHADING); m_mainRenderTarget = new RenderTarget(); m_mainRenderTarget->setType (RenderTarget::TargetType::ON_SCREEN); bloom_fbo1 = new RenderBuffer(1024,768); bloom_fbo2 = new RenderBuffer(1024,768); bloom_fbo3 = new RenderBuffer(1024,768); TMesh * mesh = new TMesh(); mesh->pushVertex (VertexData(QVector3D(-1,-1,0),QVector2D(0,0))); mesh->pushVertex (VertexData(QVector3D(1,-1,0),QVector2D(1,0))); mesh->pushVertex (VertexData(QVector3D(1,1,0),QVector2D(1,1))); mesh->pushVertex (VertexData(QVector3D(-1,1,0),QVector2D(0,1))); mesh->pushIndex (0); mesh->pushIndex (1); mesh->pushIndex (2); mesh->pushIndex (0); mesh->pushIndex (2); mesh->pushIndex (3); mesh->setMaterial (MaterialPool::getInstance ()->createOrGetMaterial ("default")); mesh->finishWithoutNormal (); m_quad = new Entity(); m_quad->addMesh (mesh); m_guiCamera = new Camera(); m_guiCamera->setOrtho (0,1024,0,768,0.01,1000); m_guiCamera->setPos (QVector3D(0,0,0)); m_renderType = DEFERRED_SHADING; }
void OpenGLWindow::renderNow() { // end function if window is not visible if (!isExposed()) return; bool needsInitialize = false; /*QOpenGLContext represents the OpenGL state of an underlying OpenGL context. To set up a context, set its screen and format such that they match those of the surface or surfaces with which the context is meant to be used.*/ if (!m_context) { m_context = new QOpenGLContext(this); m_context->setFormat(requestedFormat()); m_context->create(); needsInitialize = true; } m_context->makeCurrent(this); if (needsInitialize) { // intern OpenGL function initializeOpenGLFunctions(); initialize(); } render(); m_context->swapBuffers(this); if (m_animating) renderLater(); }
void OpenGLWindow::renderNow() { if (!isExposed()) return; m_update_pending = false; bool needsInitialize = false; if (!m_context) { m_context = new QOpenGLContext(this); m_context->setFormat(requestedFormat()); m_context->create(); needsInitialize = true; } m_context->makeCurrent(this); if (needsInitialize) { initializeOpenGLFunctions(); initialize(); } render(); m_context->swapBuffers(this); if (m_animating) renderLater(); }
void AnimeGLWidget::initializeGL() { initializeOpenGLFunctions(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (!initShaders(m_textureShaderProgram, "texture")) { close(); return; } m_textureShaderProgram.setUniformValue("texture", 0); if (!initShaders(m_lineShaderProgram, "line")) { close(); return; } for (int i = 0; i < m_pEditData->getImageDataListSize(); i++) { EditData::ImageData *p = m_pEditData->getImageData(i); if (!p) { continue; } if (p->nTexObj) { continue; } p->nTexObj = bindTexture(p->Image); } }