Example #1
0
void Window::initializeGL()
{
  // Initialize OpenGL Backend
  initializeOpenGLFunctions();
  connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(teardownGL()), Qt::DirectConnection);
  connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
  printVersionInformation();

  // Set global information
  glEnable(GL_CULL_FACE);
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

  // Application-specific initialization
  {
    // Create Shader (Do not release until VAO is created)
    m_program = new QOpenGLShaderProgram();
    m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/simple.vert");
    m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/simple.frag");
    m_program->link();
    m_program->bind();

    // Cache Uniform Locations
    u_modelToWorld = m_program->uniformLocation("modelToWorld");
    u_worldToCamera = m_program->uniformLocation("worldToCamera");
    u_cameraToView = m_program->uniformLocation("cameraToView");

    // Create Buffer (Do not release until VAO is created)
    m_vertex.create();
    m_vertex.bind();
    m_vertex.setUsagePattern(QOpenGLBuffer::StaticDraw);
    m_vertex.allocate(sg_vertexes, sizeof(sg_vertexes));

    // Create Vertex Array Object
    m_object.create();
    m_object.bind();
    m_program->enableAttributeArray(0);
    m_program->enableAttributeArray(1);
    m_program->setAttributeBuffer(0, GL_FLOAT, Vertex::positionOffset(), Vertex::PositionTupleSize, Vertex::stride());
    m_program->setAttributeBuffer(1, GL_FLOAT, Vertex::colorOffset(), Vertex::ColorTupleSize, Vertex::stride());

    // Release (unbind) all
    m_object.release();
    m_vertex.release();
    m_program->release();
  }
}
Example #2
0
void
main2()
{
    // C++ exception handling. We only throw exceptions when it really hurts
//   try {
    logEngineInfo("ShortHike started");
    printVersionInformation();
    rMain()->mainLoop();
//   }
    // This usually provides enough information about the crash, no need to dump
//   catch( SH_Exception&) {
//     ostringstream errorStream;
//     errorStream << e.getFullDescription() << endl;
//     logEngineError(errorStream.str());
//     ostringstream ossIdentifier;
//     ossIdentifier << e.getFile() << " line " << e.getLine();
//     reportBug(ossIdentifier.str(), e.getFullDescription());
//   }
}
Example #3
0
void PreviewPane::initializeGL()
{
    initializeOpenGLFunctions();

    printVersionInformation();

    glClearColor(0.15f, 0.15f, 0.15f, 1.0f);

    SetupShaders();
    SetupVertexBuffer();
    SetupObject();
    //SetupTexture();

    object.release();
    vertex.release();
    program->release();

    _initialized = true;

    glGenTextures(1, &textureRed);
    glGenTextures(1, &textureGreen);
    glGenTextures(1, &textureBlue);
}
Example #4
0
void Window::initializeGL()
{
    initializeOpenGLFunctions();
    connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(teardownGL()), Qt::DirectConnection);
    printVersionInformation();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    //Loading, compiling and linking shaders.
	shaderProgram = new QOpenGLShaderProgram();
	shaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ".\\simple.vert");
	shaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ".\\simple.frag");
	shaderProgram->link();
	shaderProgram->bind();

	//Creating the VAO
	vertexArrayObject.create();
	vertexArrayObject.bind();

	//We now need to combine the data of out mesh and our interator mesh
	vector<Vertex> combinedVertexBuffer;
	combinedVertexBuffer.reserve(mesh->getVertexVector().size() +
		interatorMesh->getVertexVector().size());
	combinedVertexBuffer.insert(combinedVertexBuffer.end(), mesh->
		getVertexVector().begin(), mesh->getVertexVector().end());
	combinedVertexBuffer.insert(combinedVertexBuffer.end(), interatorMesh->
		getVertexVector().begin(), interatorMesh->getVertexVector().end());


	//Index buffer
	vector<unsigned int> combinedIndexBuffer;
	combinedIndexBuffer.reserve(mesh->getIndexVector().size() + interatorMesh->
		getIndexVector().size());
	combinedIndexBuffer.insert(combinedIndexBuffer.end(), mesh->
		getIndexVector().begin(), mesh->getIndexVector().end());

	unsigned int vertexVectorSize = static_cast<unsigned int>(mesh->
		getVertexVector().size());
	for (auto index : interatorMesh->getIndexVector()) {
		combinedIndexBuffer.push_back(index + vertexVectorSize);
	}

	//Creating the VBO for the mesh
    vertexBuffer.create();
	vertexBuffer.bind();
	vertexBuffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
	vertexBuffer.allocate(combinedVertexBuffer.data(), 
		static_cast<int>(combinedVertexBuffer.size() * sizeof(Vertex)));

	//Creating IBO for the mesh
	indexBuffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer);
	indexBuffer.create();
	indexBuffer.bind();
	indexBuffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
	indexBuffer.allocate(combinedIndexBuffer.data(),
		static_cast<int>(combinedIndexBuffer.size() * sizeof(unsigned int)));

	//Enabling attribute arrays for vertex, normal and color data.
	shaderProgram->enableAttributeArray(0);
	shaderProgram->enableAttributeArray(1);
	shaderProgram->enableAttributeArray(2);
	shaderProgram->setAttributeBuffer(0, GL_FLOAT, Vertex::positionOffset(), Vertex::PositionTupleSize, Vertex::stride());
	shaderProgram->setAttributeBuffer(1, GL_FLOAT, Vertex::colorOffset(), Vertex::ColorTupleSize, Vertex::stride());
	shaderProgram->setAttributeBuffer(2, GL_FLOAT, Vertex::normalOffset(), Vertex::NormalTupleSize, Vertex::stride());

	vertexArrayObject.release();
	vertexBuffer.release();
	indexBuffer.release();
	shaderProgram->release();

	//Setting up model, view and projection matrices.
	mvpSetup();

	//Creating interator ray
	interator = new Ray(vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 1.0f));

	//Setting up the collision detector
	collisionDetector.setMesh(mesh);
	collisionDetector.setRay(interator);

	//Initializing haptic device
	if (hapticsEnabled) {
		haptic.initializeHL();
		haptic.updateHapticWorkspace();
		haptic.setInterator(interator);
		haptic.setCollisionDetector(&collisionDetector);
		haptic.setCollisionPath(&path);
		haptic.setMesh(mesh);
		haptic.setShaderProgram(shaderProgram);
		haptic.setVAO(&vertexArrayObject);
		handle = hdScheduleAsynchronous(HapticInterface::mainHapticCallback,
			&haptic, HD_MAX_SCHEDULER_PRIORITY);
		hdStartScheduler();
	}
}
Example #5
0
void Window::initializeGL() {
	// Initialize OpenGL Backend
	initializeOpenGLFunctions();
	//This is equivalent to register an IDLE function callback for animation
	//We don't control the frame rate is as fast as the system is available
	//Maybe using the vsync
	connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
	printVersionInformation();
	
	//Global GL configurations
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glClearColor(0.15f, 0.15f, 0.15f, 1.0f);
	// Application-specific initialization
	{
		// Create Shader (Do not release until VAO is created)
		m_program_ptr = new QOpenGLShaderProgram();
		m_program_ptr->addShaderFromSourceFile(QOpenGLShader::Vertex, "Resources/shaders/simpleVertex.glsl");
		m_program_ptr->addShaderFromSourceFile(QOpenGLShader::Fragment, "Resources/shaders/simpleFragment.glsl");
		m_program_ptr->link();
		m_program_ptr->bind();

		//Fill the arrays with date in CPU side
		createGeomerty();
		// Create Vertex Array Object (Remember this needs to be done BEFORE binding the vertex)
		m_vao.create();
		m_vao.bind();

		// Create Buffers (Do not release until VAO is created)
		m_vertex_buffer = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
		m_vertex_buffer.create();
		m_vertex_buffer.bind();
		m_vertex_buffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
		m_vertex_buffer.allocate(m_vertices.constData(), m_vertices.size() * sizeof(Vertex));

		m_index_buffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer);
		m_index_buffer.create();
		m_index_buffer.bind();
		m_index_buffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
		m_index_buffer.allocate(m_indexes.constData(), m_indexes.size() * sizeof(unsigned int));
		
		
		m_program_ptr->enableAttributeArray(0);
		m_program_ptr->enableAttributeArray(1);
		m_program_ptr->setAttributeBuffer(0, GL_FLOAT, Vertex::positionOffset(), Vertex::PositionTupleSize, Vertex::stride());
		m_program_ptr->setAttributeBuffer(1, GL_FLOAT, Vertex::colorOffset(), Vertex::ColorTupleSize, Vertex::stride());

		// Release (unbind) all
		m_vao.release();
		m_index_buffer.release();
		m_index_buffer.release();
		m_program_ptr->release();

		//Once we have a copy in the GPU there is no need to keep a CPU copy (unless yopu want to)
		m_indexes.clear();
		m_vertices.clear();
	}

	//Program main logic
	//Camera start with no rotation
	m_new_rotation = m_base_rotation = QQuaternion(1.0f, QVector3D(0.0f, 0.0f, 0.0f));
	m_mouse_draging = false;
	m_fovy_y = 45.0f;
}