void SatHorizon::render(QMatrix4x4 projection, float distance, QQuaternion quat, QVector3D posnorm, float alt, QColor rendercolor)
{

    float radius = sqrt( alt * alt - 1 ) / alt;

    float theta = acos(QVector3D::dotProduct(QVector3D(0,0,1), posnorm));
    QVector3D vecnorm = QVector3D::crossProduct(QVector3D(0,0,1), posnorm);
    vecnorm.normalize();

    createCircleBuffer(radius, SEGMENTS);

    QMatrix4x4 modelview;
    modelview.translate(0.0, 0.0, distance);
    modelview.rotate(quat);

    modelview.translate(posnorm * (1/alt) * (alt > 1.5 ? 1.0015 : 1.0001));
    modelview.rotate(theta * 180.0f/ PI, vecnorm );

    posBuf.bind();
    posBuf.write(0, vertexData, SEGMENTS * sizeof(QVector3D));
    posBuf.release();

    program->bind();

    program->setUniformValue("MVP", projection * modelview);
    QMatrix3x3 norm = modelview.normalMatrix();
    program->setUniformValue("NormalMatrix", norm);

    program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));
    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);
    glDrawArrays(GL_LINE_LOOP, 0, SEGMENTS);

}
Exemple #2
0
void CGLWidget::initializeGL()
{
    qDebug() << "init gl...";
    this->initializeOpenGLFunctions();
    this->glClearColor(0, 0, 0, 1);

    m_vao.create();
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);

    m_program = new QOpenGLShaderProgram;
    m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/glsl/basic.vert");
    m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/glsl/basic.frag");
    m_program->link();

    m_program->bind();
    m_mvpLoc = m_program->uniformLocation("mvp");
    m_modelMatLoc = m_program->uniformLocation("m");
    m_viewMatLoc = m_program->uniformLocation("v");
    m_lightPosLoc = m_program->uniformLocation("lightPosition_worldspace");

    m_vbo.create();
    m_vbo.bind();

    m_uvBuff.create();
    m_uvBuff.bind();

    m_normalBuff.create();
    m_normalBuff.bind();

    m_indexBuff.create();
    m_indexBuff.bind();

    setupVertexAttribs();
    loadGLTexture();
}
Exemple #3
0
void CGLWidget::initializeGL()
{
    qDebug() << "init gl...";
    this->initializeOpenGLFunctions();
    this->glClearColor(0, 0, 0, 1);

    m_vao.create();
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);

    m_program = new QOpenGLShaderProgram;
    m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/glsl/basic.vert");
    m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/glsl/basic.frag");
    m_program->link();

    m_program->bind();
    m_mvpLoc = m_program->uniformLocation("mvp");

    m_vbo.create();
    m_vbo.bind();
    m_vbo.setUsagePattern(QOpenGLBuffer::UsagePattern::StaticDraw);

    m_uvBuff.create();
    m_uvBuff.bind();
    setupVertexAttribs();
    loadGLTexture();
}
void GLRasterTexture::initializeGL(bool coreProfile) {
    if(m_data.size() == 0) return;
    m_program = new QOpenGLShaderProgram;
    m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, coreProfile ? vertexShaderSourceCore : vertexShaderSource);
    m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, coreProfile ? fragmentShaderSourceCore : fragmentShaderSource);
    m_program->bindAttributeLocation("vertex", 0);
    m_program->bindAttributeLocation("texCoord", 1);
    m_program->link();

    m_program->bind();
    m_projMatrixLoc = m_program->uniformLocation("projMatrix");
    m_mvMatrixLoc = m_program->uniformLocation("mvMatrix");
    m_textureSamplerLoc = m_program->uniformLocation("texture");

    m_vao.create();
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);

    // Setup our vertex buffer object.
    m_vbo.create();
    m_vbo.bind();
    m_vbo.allocate(constData(), m_count * sizeof(GLfloat));

    // Store the vertex attribute bindings for the program.
    setupVertexAttribs();

    m_program->setUniformValue(m_textureSamplerLoc, 0);

    m_program->release();
    m_built = true;
}
Exemple #5
0
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);


}
Exemple #6
0
void CGLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glEnable(GL_CULL_FACE);

    QMatrix4x4 m,v,p;
    m.setToIdentity();
    v.lookAt(QVector3D(0, 0, 5), QVector3D(0, 0, 0), QVector3D(0, 1, 0));
    p.perspective(45.0f,  4.0f / 3.0f, 0.1f, 100.0f);
    QMatrix4x4 mvp = p * v * m;

    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
    m_program->bind();
    m_program->setUniformValue(m_mvpLoc, mvp);
    m_program->setUniformValue(m_modelMatLoc, m);
    m_program->setUniformValue(m_viewMatLoc, v);
    QVector3D lightPos_worldspace(4, 4, 4);
    m_program->setUniformValue(m_lightPosLoc, lightPos_worldspace);

    m_texture->bind();
    m_indexBuff.bind();
    glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, (void*)0);
    m_program->release();
}
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);


}
Exemple #8
0
void CGLWidget::paintGL()
{
    std::cout << "paint gl..." << std::endl;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
    m_program->bind();
    glDrawArrays(GL_TRIANGLES, 0, 3);//total 3 vertices
}
void CompasWidget::paintGL(){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	m_world.setToIdentity();
	m_world.rotate(180.0f - (m_xRot / 16.0f), 1, 0, 0);
	m_world.rotate(m_yRot / 16.0f, 0, 1, 0);
	m_world.rotate(m_zRot / 16.0f, 0, 0, 1);

	/*


	QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
	m_program->bind();
	m_program->setUniformValue(m_projMatrixLoc, m_proj);
	m_program->setUniformValue(m_mvMatrixLoc, m_camera * m_world);
	QMatrix3x3 normalMatrix = m_world.normalMatrix();
	m_program->setUniformValue(m_normalMatrixLoc, normalMatrix);

	glDrawArrays(GL_TRIANGLES, 0, m_logo.vertexCount());

	m_program->release();
*/

	QOpenGLFunctions *f = context()->functions();
	const bool newFrameReady=true;
	if (newFrameReady) {//new frame ready
		f->glFrontFace(GL_CW); // because our cube's vertex data is such

		f->glBindTexture(GL_TEXTURE_2D, m_fbo2->texture());

		m_program2->bind();
		QOpenGLVertexArrayObject::Binder vaoBinder(m_vao2);
		// If VAOs are not supported, set the vertex attributes every time.
		if (!m_vao2->isCreated()){
			setupVertexAttribs2();
		}

		static GLfloat angle = 0;
		QMatrix4x4 m;
		m.translate(0, 0, -20);
		m.rotate(90, 0, 0, 1);
		m.rotate(angle, 0.5, 1, 0);
		angle += 0.5f;

		m_program2->setUniformValue(m_matrixLoc, m_proj * m);

		// Draw the cube.
		f->glDrawArrays(GL_TRIANGLES, 0, 36);

		m_program2->release();

	}


}
bool QOpenGLTextureBlitter::create()
{
    QOpenGLContext *currentContext = QOpenGLContext::currentContext();
    if (!currentContext)
        return false;

    Q_D(QOpenGLTextureBlitter);

    if (d->program)
        return true;

    d->program.reset(new QOpenGLShaderProgram());

    QSurfaceFormat format = currentContext->format();

    if (format.profile() == QSurfaceFormat::CoreProfile && format.version() >= qMakePair(3,2)) {
        d->program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertex_shader150);
        d->program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader150);
    } else {
        d->program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertex_shader);
        d->program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader);
    }
    d->program->link();
    if (!d->program->isLinked()) {
        qWarning() << Q_FUNC_INFO << "Could not link shader program:\n" << d->program->log();
        return false;
    }

    d->program->bind();

    // Create and bind the VAO, if supported.
    QOpenGLVertexArrayObject::Binder vaoBinder(d->vao.data());

    d->vertexBuffer.create();
    d->vertexBuffer.bind();
    d->vertexBuffer.allocate(vertex_buffer_data, sizeof(vertex_buffer_data));
    d->vertexBuffer.release();

    d->textureBuffer.create();
    d->textureBuffer.bind();
    d->textureBuffer.allocate(texture_buffer_data, sizeof(texture_buffer_data));
    d->textureBuffer.release();

    d->vertexCoordAttribPos = d->program->attributeLocation("vertexCoord");
    d->vertexTransformUniformPos = d->program->uniformLocation("vertexTransform");
    d->textureCoordAttribPos = d->program->attributeLocation("textureCoord");
    d->textureTransformUniformPos = d->program->uniformLocation("textureTransform");
    d->swizzleUniformPos = d->program->uniformLocation("swizzle");
    d->opacityUniformPos = d->program->uniformLocation("opacity");

    d->program->setUniformValue(d->swizzleUniformPos,false);

    return true;
}
Exemple #11
0
void GLWidget::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, &GLWidget::cleanup);

    initializeOpenGLFunctions();
    glClearColor(0, 0, 0, m_transparent ? 0 : 1);

    m_program = new QOpenGLShaderProgram;
    m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_core ? vertexShaderSourceCore : vertexShaderSource);
    m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_core ? fragmentShaderSourceCore : fragmentShaderSource);
    m_program->bindAttributeLocation("vertex", 0);
    m_program->bindAttributeLocation("normal", 1);
    m_program->link();

    m_program->bind();
    m_projMatrixLoc = m_program->uniformLocation("projMatrix");
    m_mvMatrixLoc = m_program->uniformLocation("mvMatrix");
    m_normalMatrixLoc = m_program->uniformLocation("normalMatrix");
    m_lightPosLoc = m_program->uniformLocation("lightPos");

    // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
    // implementations this is optional and support may not be present
    // at all. Nonetheless the below code works in all cases and makes
    // sure there is a VAO when one is needed.
    m_vao.create();
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);

    // Setup our vertex buffer object.
    m_logoVbo.create();
    m_logoVbo.bind();
    m_logoVbo.allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));

    // Store the vertex attribute bindings for the program.
    setupVertexAttribs();

    // Our camera never changes in this example.
    m_camera.setToIdentity();
    m_camera.translate(0, 0, -1);

    // Light position is fixed.
    m_program->setUniformValue(m_lightPosLoc, QVector3D(0, 0, -1));

    m_program->release();

    std::cout<<" gl version : "<<glGetString( GL_VERSION )<<" glsl version: "<<glGetString( GL_SHADING_LANGUAGE_VERSION )<<std::endl;
}
void GLDynamicLine::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, const QMatrix4x4 &m_mModel, const QMatrix2x2 &m_selectionBounds)
{
    if(!m_built) return;
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
    m_program->bind();
    m_program->setUniformValue(m_projMatrixLoc, m_mProj);
    m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel);
    m_program->setUniformValue(m_diagVertices2DLoc, m_selectionBounds);

    m_program->setUniformValue(m_colourVectorLoc, m_colour_stroke);
    glDrawArrays(GL_LINE_LOOP, 0, vertexCount());

    m_program->release();
}
void GLRasterTexture::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, const QMatrix4x4 &m_mModel)
{
    if(!m_built) return;
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
    m_program->bind();
    m_program->setUniformValue(m_projMatrixLoc, m_mProj);
    m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel);

    m_texture.bind();
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount());

    m_program->release();
}
void TextureWriter::render()
{

    glBindFramebuffer(GL_FRAMEBUFFER, imageptrs->fboId);
    //set the viewport to be the size of the texture
    glViewport(0,0, imageptrs->pmOut->width(), imageptrs->pmOut->height());

    glBindTexture(GL_TEXTURE_1D, texturelineId);
    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);

    program->bind();

    glDrawArrays(GL_LINE_STRIP, 0, nbrVerticesinBuffer);
    //glDrawArrays(GL_TRIANGLES, 0, nbrVertices);
    glBindTexture(GL_TEXTURE_1D, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);


}
Exemple #15
0
void CGLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    QMatrix4x4 m, v, p;
    m.setToIdentity();
    v.lookAt(QVector3D(0, 0, 5), QVector3D(0, 0, 0), QVector3D(0, 1, 0));
    p.perspective(45.0f,  4.0f / 3.0f, 0.1f, 100.0f);
    QMatrix4x4 mvp = p * v * m;

    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
    m_program->bind();
    m_program->setUniformValue(m_mvpLoc, mvp);

    m_texture->bind();
    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
    m_program->release();
}
Exemple #16
0
SatHorizon::SatHorizon(QOpenGLShaderProgram *prog)
{
    program = prog;
    initializeOpenGLFunctions();

    program->bind();

    vao.create();
    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);

    posBuf.create();
    posBuf.setUsagePattern(QOpenGLBuffer::DynamicDraw);
    posBuf.bind();
    posBuf.allocate(sizeof(QVector3D) * SEGMENTS);

    vertexPosition = program->attributeLocation("VertexPosition");
    program->enableAttributeArray(vertexPosition);
    program->setAttributeBuffer(vertexPosition, GL_FLOAT, 0, 3);

}
Exemple #17
0
void view::initializeGL()
{
    connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &view::cleanup);

    initializeOpenGLFunctions();
    glClearColor(0, 0, 0, m_transparent ? 0 : 1);

    m_program = new QOpenGLShaderProgram;
    m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_core ? vertexShaderSourceCore : vertexShaderSource);
    m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_core ? fragmentShaderSourceCore : fragmentShaderSource);
    m_program->bindAttributeLocation("vertex", 0);
    m_program->bindAttributeLocation("normal", 1);
    m_program->link();

    m_program->bind();
    m_projMatrixLoc = m_program->uniformLocation("projMatrix");
    m_mvMatrixLoc = m_program->uniformLocation("mvMatrix");
    m_normalMatrixLoc = m_program->uniformLocation("normalMatrix");
    m_lightPosLoc = m_program->uniformLocation("lightPos");

    m_vao.create();
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);

    // Setup our vertex buffer object.
    m_logoVbo.create();
    m_logoVbo.bind();
    m_logoVbo.allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));

    // Store the vertex attribute bindings for the program.
    setupVertexAttribs();

    // Our camera never changes in this example.
    m_camera.setToIdentity();
    m_camera.translate(0, 0, -1);

    // Light position is fixed.
    m_program->setUniformValue(m_lightPosLoc, QVector3D(0, 0, 70));

    m_program->release();
}
Exemple #18
0
void CGLWidget::initializeGL()
{
    std::cout << "init gl..." << std::endl;
    this->initializeOpenGLFunctions();
    this->glClearColor(0, 0, 1, 1);

    m_vao.create();
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);

    m_program = new QOpenGLShaderProgram;
    m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/glsl/basic.vert");
    m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/glsl/basic.frag");
    m_program->link();

    m_program->bind();

    m_vbo.create();
    m_vbo.bind();
    m_vbo.allocate(vertexData, sizeof(vertexData));

    setupVertexAttribs();
}
Exemple #19
0
void GLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    m_world.setToIdentity();
    m_world.rotate(180.0f - (m_xRot / 16.0f), 1, 0, 0);
    m_world.rotate(m_yRot / 16.0f, 0, 1, 0);
    m_world.rotate(m_zRot / 16.0f, 0, 0, 1);

    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
    m_program->bind();
    m_program->setUniformValue(m_projMatrixLoc, m_proj);
    m_program->setUniformValue(m_mvMatrixLoc, m_camera * m_world);
    QMatrix3x3 normalMatrix = m_world.normalMatrix();
    m_program->setUniformValue(m_normalMatrixLoc, normalMatrix);

    glDrawArrays(GL_TRIANGLES, 0, m_logo.vertexCount());

    m_program->release();
}
void CompasWidget::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, &CompasWidget::cleanup);

	initializeOpenGLFunctions();
	glClearColor(0, 0, 0, m_transparent ? 0 : 1);

	m_program = new QOpenGLShaderProgram;
	m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_core ? vertexShaderSourceCore : vertexShaderSource);
	m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_core ? fragmentShaderSourceCore : fragmentShaderSource);
	m_program->bindAttributeLocation("vertex", 0);
	m_program->bindAttributeLocation("normal", 1);
	m_program->link();

	m_program->bind();
	m_projMatrixLoc = m_program->uniformLocation("projMatrix");
	m_mvMatrixLoc = m_program->uniformLocation("mvMatrix");
	m_normalMatrixLoc = m_program->uniformLocation("normalMatrix");
	m_lightPosLoc = m_program->uniformLocation("lightPos");

	// Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
	// implementations this is optional and support may not be present
	// at all. Nonetheless the below code works in all cases and makes
	// sure there is a VAO when one is needed.
	m_vao.create();
	QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);

	// Setup our vertex buffer object.
	m_logoVbo.create();
	m_logoVbo.bind();
	m_logoVbo.allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));

	// Store the vertex attribute bindings for the program.
	setupVertexAttribs();

	// Our camera never changes in this example.
	m_camera.setToIdentity();
	m_camera.translate(0, 0, -1);

	// Light position is fixed.
	m_program->setUniformValue(m_lightPosLoc, QVector3D(0, 0, 70));

	m_program->release();



	QSize sz=size();
	m_fbo2 = new QOpenGLFramebufferObject(sz, QOpenGLFramebufferObject::CombinedDepthStencil);



	m_program2 = new QOpenGLShaderProgram;
	m_program2->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderVideoStreamSource);
	m_program2->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderVideoStreamSource);
	m_program2->bindAttributeLocation("vertex", 0);
	m_program2->bindAttributeLocation("coord", 1);
	m_program2->link();
	m_matrixLoc = m_program->uniformLocation("matrix");

	m_vao2 = new QOpenGLVertexArrayObject;
	m_vao2->create();
	m_vao2->bind();

	m_vbo2 = new QOpenGLBuffer;
	m_vbo2->create();
	m_vbo2->bind();

	GLfloat v[] = {
		-0.5, 0.5, 0.5, 0.5,-0.5,0.5,-0.5,-0.5,0.5,
		0.5, -0.5, 0.5, -0.5,0.5,0.5,0.5,0.5,0.5,
		-0.5, -0.5, -0.5, 0.5,-0.5,-0.5,-0.5,0.5,-0.5,
		0.5, 0.5, -0.5, -0.5,0.5,-0.5,0.5,-0.5,-0.5,

		0.5, -0.5, -0.5, 0.5,-0.5,0.5,0.5,0.5,-0.5,
		0.5, 0.5, 0.5, 0.5,0.5,-0.5,0.5,-0.5,0.5,
		-0.5, 0.5, -0.5, -0.5,-0.5,0.5,-0.5,-0.5,-0.5,
		-0.5, -0.5, 0.5, -0.5,0.5,-0.5,-0.5,0.5,0.5,

		0.5, 0.5,  -0.5, -0.5, 0.5,  0.5,  -0.5,  0.5,  -0.5,
		-0.5,  0.5,  0.5,  0.5,  0.5,  -0.5, 0.5, 0.5,  0.5,
		-0.5,  -0.5, -0.5, -0.5, -0.5, 0.5,  0.5, -0.5, -0.5,
		0.5, -0.5, 0.5,  0.5,  -0.5, -0.5, -0.5,  -0.5, 0.5
	};
	GLfloat texCoords[] = {
		0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
		1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
		1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
		0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,

		1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
		0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
		0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
		1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,

		0.0f,1.0f, 1.0f,0.0f, 1.0f,1.0f,
		1.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f,
		1.0f,0.0f, 1.0f,1.0f, 0.0f,0.0f,
		0.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f
	};

	const int vertexCount = 36;
	m_vbo2->allocate(sizeof(GLfloat) * vertexCount * 5);
	m_vbo2->write(0, v, sizeof(GLfloat) * vertexCount * 3);
	m_vbo2->write(sizeof(GLfloat) * vertexCount * 3, texCoords, sizeof(GLfloat) * vertexCount * 2);
	m_vbo2->release();

	if (m_vao2->isCreated()){
		setupVertexAttribs2();
	}
	m_vao2->release();
}
Exemple #21
0
void SegmentGL::RenderContour(Segment *seg, QMatrix4x4 projection, QMatrix4x4 modelview, int width, int height)
{

    QVector3D vec;
    QVector3D pos;
    QVector<GLfloat> positions;
    QEci qeci;


    CalculateSegmentContour(&positions, seg->cornerpointfirst1.latitude, seg->cornerpointfirst1.longitude, seg->cornerpointlast1.latitude, seg->cornerpointlast1.longitude);
    CalculateSegmentContour(&positions,seg->cornerpointlast1.latitude, seg->cornerpointlast1.longitude, seg->cornerpointlast2.latitude, seg->cornerpointlast2.longitude);
    CalculateSegmentContour(&positions, seg->cornerpointlast2.latitude, seg->cornerpointlast2.longitude, seg->cornerpointfirst2.latitude, seg->cornerpointfirst2.longitude);
    CalculateSegmentContour(&positions,seg->cornerpointfirst2.latitude, seg->cornerpointfirst2.longitude, seg->cornerpointfirst1.latitude, seg->cornerpointfirst1.longitude);

    seg->qsgp4->getPosition(seg->minutes_since_state_vector, qeci);
    QGeodetic qgeo = qeci.ToGeo();
    double lat1 = qgeo.latitude;
    double lon1 = qgeo.longitude;

    seg->qsgp4->getPosition(seg->minutes_since_state_vector + seg->minutes_sensing, qeci);
    qgeo = qeci.ToGeo();
    double lat2 = qgeo.latitude;
    double lon2 = qgeo.longitude;

    CalculateSegmentContour(&positions, lat1, lon1, lat2, lon2);

    positionsBuf.bind();
    positionsBuf.write(0, positions.data(), positions.size() * sizeof(GLfloat));
    positionsBuf.release();

    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);

    program->bind();
    program->setUniformValue("MVP", projection * modelview);
    QColor rendercolor(opts.satsegmentcolor);
    QColor rendercolorsel(opts.satsegmentcolorsel);

    if((*seg).segmentselected)
        program->setUniformValue("outcolor", QVector4D(rendercolorsel.redF(), rendercolorsel.greenF(), rendercolorsel.blueF(), 1.0f));
    else
        program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));

    QMatrix3x3 norm = modelview.normalMatrix();
    program->setUniformValue("NormalMatrix", norm);

    glDrawArrays(GL_LINE_LOOP, 0, nbrOfVertices - 10);
    glDrawArrays(GL_LINE_STRIP, nbrOfVertices - 10, 10);


    float mvmatrix[16], projmatrix[16];
    QMatrix4x4 MVP;
    MVP = projection * modelview;

    float *ptr = modelview.data();
    for(int i = 0; i < 16; i++)
        mvmatrix[i] = *(ptr + i);

    ptr = projection.data();
    for(int i = 0; i < 16; i++)
        projmatrix[i] = *(ptr + i);

    QVector2D win;

    LonLat2PointRad((float)seg->cornerpointfirst1.latitude, (float)seg->cornerpointfirst1.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend1 = win;

    LonLat2PointRad((float)seg->cornerpointfirst2.latitude, (float)seg->cornerpointfirst2.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend2 = win;

    LonLat2PointRad((float)seg->cornerpointlast1.latitude, (float)seg->cornerpointlast1.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend3 = win;

    LonLat2PointRad((float)seg->cornerpointlast2.latitude, (float)seg->cornerpointlast2.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend4 = win;

    win = glhProjectf (seg->vec1, mvmatrix, projmatrix, width, height);
    seg->winvec1 = win;

    win = glhProjectf (seg->vec2, mvmatrix, projmatrix, width, height);
    seg->winvec2 = win;

}
Exemple #22
0
SatGL::SatGL(QOpenGLShaderProgram *prog, SatelliteList *satlist, AVHRRSatellite *seglist)
{
    sats = satlist;
    segs = seglist;

    tdiff = 0;
    program = prog;

    initializeOpenGLFunctions();

    program->bind();

    vao.create();
    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);

    positionsBuf.create();
    positionsBuf.setUsagePattern(QOpenGLBuffer::DynamicDraw);
    positionsBuf.bind();

//    QVector<GLfloat> positions;

//    QList<Satellite>::iterator sat = sats->GetSatlist()->begin();

    nbrActiveSats = 0;

//    while ( sat != sats->GetSatlist()->end() )
//    {
//        if( (*sat).active  == true)
//        {
//            QVector3D pos, posssp;
//            (*sat).GetSatellitePosition(pos, posssp, alt);
//            positions.append(0.0f);
//            positions.append(0.0f);
//            positions.append(0.0f);
//            positions.append(pos.x());
//            positions.append(pos.y());
//            positions.append(pos.z());
//            qDebug() << (*sat).sat_name;
//            nbrActiveSats++;
//        }
//        ++sat;
//    }

//    positionsBuf.allocate(positions.data(), positions.size() * sizeof(GLfloat));
//    qDebug() << "SatGL : satposBufsize " << positionsBuf.size() << "  nbr of vertices = " << positionsBuf.size() / (3 * sizeof(GLfloat));
//    qDebug() << "SatGL : nbrActiveSats " << nbrActiveSats;
//    qDebug() << "SatGL : nbrActiveSats = " << nbrActiveSats << "  positions.size = " << positions.size() << " positionsBuf.size() = " << positionsBuf.size();

    vertexPosition = program->attributeLocation("VertexPosition");
    program->enableAttributeArray(vertexPosition);
    program->setAttributeBuffer(vertexPosition, GL_FLOAT, 0, 3);

    vaotrail.create();
    QOpenGLVertexArrayObject::Binder vaoBinder1(&vaotrail);

    positionsTrail.create();
    positionsTrail.setUsagePattern(QOpenGLBuffer::DynamicDraw);
    positionsTrail.bind();
    positionsTrail.allocate(tdiff * 2 * 3 *sizeof(GLfloat));
    program->enableAttributeArray(vertexPosition);
    program->setAttributeBuffer(vertexPosition, GL_FLOAT, 0, 3);

    octa = new Octahedron(program);
    horizon = new SatHorizon(program);

}
Exemple #23
0
void SatGL::render(QMatrix4x4 projection, float distance, QQuaternion quat )
{
    QMatrix4x4 modelview;
    modelview.translate(0.0, 0.0, distance);
    modelview.rotate(quat);


    QVector<GLfloat> positions;

    QList<Satellite>::iterator sat = sats->GetSatlist()->begin();

    int nbrSats = 0;
    int nbrVertices;

    QMatrix4x4 modelocta;
    QColor col(255, 0, 0);
    float alt;
    while ( sat != sats->GetSatlist()->end() )
    {
        if( (*sat).active  == true)
        {
            QVector3D pos, posnorm;
            (*sat).GetSatellitePosition(pos, posnorm, alt);
            positions.append(0.0f);
            positions.append(0.0f);
            positions.append(0.0f);
            positions.append(pos.x());
            positions.append(pos.y());
            positions.append(pos.z());
            modelocta = modelview;
            modelocta.translate(posnorm.x(), posnorm.y(), posnorm.z());
            modelocta.scale(0.005f);

            octa->render(projection, modelocta, col);
            QColor horizoncolour(opts.sathorizoncolor);
            horizon->render(projection, distance, quat, posnorm, alt, horizoncolour);

            nbrSats++;
        }
        ++sat;
    }

    positionsBuf.bind();
    if(nbrSats != nbrActiveSats)
    {
        nbrActiveSats = nbrSats;

        positionsBuf.allocate(positions.data(), positions.size() * sizeof(GLfloat));

        qDebug() << "positionsBuf.size() != nbrActiveSats * 2 * 3 * sizeof(GLfloat)";
        qDebug() << "nbrActiveSats = " << nbrActiveSats << " positionsBuf.size() = " << positionsBuf.size();
    }
    else
    {
        positionsBuf.write(0, positions.data(), positions.size() * sizeof(GLfloat));
    }

    nbrVertices = positionsBuf.size() / (3 * sizeof(GLfloat));

    positionsBuf.release();

    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);

    program->bind();

    program->setUniformValue("MVP", projection * modelview);
    QMatrix3x3 norm = modelview.normalMatrix();
    program->setUniformValue("NormalMatrix", norm);

    QColor rendercolor(255, 0, 0);
    program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));

    glDrawArrays(GL_LINES, 0, nbrVertices);

    sat = sats->GetSatlist()->begin();
    while ( sat != sats->GetSatlist()->end() )
    {
        if( (*sat).active  == true)
        {
            if( (*sat).GetCatalogueNbr() == sats->GetSelectedSat() )
                RenderTrail(&(*sat), projection, distance, quat, true);
            else
                RenderTrail(&(*sat), projection, distance, quat, false);
        }
        ++sat;
    }

    //    QMatrix4x4 mod;
    //    mod.setToIdentity();
    //    mod.translate(0.0, 0.0, distance);
    //    mod.rotate(quat);

    //    modelocta = mod;
    //    modelocta.translate(0.0, 1.0, 0.0);
    //    modelocta.scale(0.009f);
    //    octa->render(projection, modelocta, col);

    //    modelocta = mod;
    //    modelocta.translate(0.0, 0.0, 1.0);
    //    modelocta.scale(0.009f);
    //    octa->render(projection, modelocta, col);

    //    modelocta = mod;
    //    modelocta.translate(1.0, 0.0, 0.0);
    //    modelocta.scale(0.009f);
    //    octa->render(projection, modelocta, col);


}
Exemple #24
0
void SatGL::RenderTrail(Satellite *sat, QMatrix4x4 projection, float distance, QQuaternion quat, bool trackon) // QMatrix4x4 modelview, bool trackon)
{
    QVector<GLfloat> postrail;

    double
            tsince,            // Time since epoch (in minutes)
            jul_epoch,         // Julian date of epoch
            jul_utc;           // Julian UTC date


    QSgp4Date nowutc = QSgp4Date::NowUTC();
    jul_utc = nowutc.Julian();
    jul_epoch = Julian_Date_of_Epoch(sat->GetEpoch());

    QMatrix4x4 model;
    model.translate(0.0, 0.0, distance);
    model.rotate(quat);

    QMatrix4x4 modelview;
    modelview = model;
    QMatrix4x4 modelocta;
    QColor col(0,255,255);

    QEci qeci;
    QVector3D pos;
    double id;
    int nbrVertices = 0;

    tsince = (jul_utc - jul_epoch) * MIN_PER_DAY; // in minutes

    for( id = tsince - 5; id < tsince; id++ )
    {
        (*sat).qsgp4->getPosition(id, qeci);
        QGeodetic qgeo = qeci.ToGeo();
        LonLat2PointRad(qgeo.latitude, qgeo.longitude, &pos, 1.001f);
        if(id < tsince && id >= tsince - 5 )
        {
            modelocta = model;
            modelocta.translate(pos.x(), pos.y(), pos.z());
            modelocta.scale(0.004f);
            octa->render(projection, modelocta, col);
        }
    }


    if(trackon)
    {
        for( id = tsince - opts.realminutesshown + 1; id <= tsince + opts.realminutesshown; id++ )  // nbr of id's = 2 * opts.realminutesshown
        {
            (*sat).qsgp4->getPosition(id, qeci);
            QGeodetic qgeo = qeci.ToGeo();
            LonLat2PointRad(qgeo.latitude, qgeo.longitude, &pos, 1.001f);
            postrail.append(pos.x());
            postrail.append(pos.y());
            postrail.append(pos.z());
        }

        positionsTrail.bind();

        if(tdiff != opts.realminutesshown)
        {
            tdiff = opts.realminutesshown;
            positionsTrail.allocate(postrail.data(), postrail.size() * sizeof(GLfloat));

        }
        else
        {
            positionsTrail.write(0, postrail.data(), postrail.size() * sizeof(GLfloat));
        }

        nbrVertices = positionsTrail.size() / (3 * sizeof(GLfloat));

        positionsTrail.release();

        QOpenGLVertexArrayObject::Binder vaoBinder(&vaotrail);

        program->bind();

        program->setUniformValue("MVP", projection * modelview);
        QMatrix3x3 norm = modelview.normalMatrix();
        program->setUniformValue("NormalMatrix", norm);

        QColor rendercolor(opts.sattrackcolor);
        program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));

        glDrawArrays(GL_LINE_STRIP, 0, nbrVertices);

    }
}