void SceneRenderToTex::render()
{
    glBindFramebuffer(GL_FRAMEBUFFER, fboHandle);
    renderToTexture();

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    renderScene();
}
Esempio n. 2
0
void UWKRendererGL::UpdateTexture()
{
    if (!valid_ && surfaceIDSet_)
    {
        InitInternal();
    }

    renderToTexture();
}
Esempio n. 3
0
//瞧,这是以前从未见过的最短的绘制程序,有很棒的视觉效果!
//我们调用RenderToTexture 函数。幸亏我们视口改变这个函数才着色被拉伸的弹簧。 对于我们的纹理拉伸的弹簧被着色,并且这些缓冲器被清除。
//我们之后绘制“真正的”弹簧 (你在屏幕上看到的3D实体) 通过调用 ProcessHelix( )。
//最后我们在弹簧前面绘制一些混合的方块。有织纹的方块将被拉伸以适应在真正的3D弹簧
//上面。
void MyGLWidget::paintGL()
{
    glClearColor(0.0f, 0.0f, 0.0f, 0.5);// 将清晰的颜色设定为黑色
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// 清除屏幕和深度缓冲器
    glLoadIdentity();// 重置视图
    renderToTexture();// 着色纹理
    processHelix();// 绘制我们的螺旋
    drawBlur(25,0.02f);// 绘制模糊效果
}
Esempio n. 4
0
void CUDARenderer::draw(const glm::mat4 &View, const glm::mat4 &Projection)
{
	setCameraInfo(camera.cam);
	gpuErrchk(cudaGraphicsMapResources(1, &cudaSurfRes));
	{
		cudaArray *viewCudaArray;
		gpuErrchk(cudaGraphicsSubResourceGetMappedArray(&viewCudaArray, cudaSurfRes, 0, 0));
		renderToTexture(dimBlock, dimGrid, d_scene, viewCudaArray);
	}
	gpuErrchk(cudaGraphicsUnmapResources(1, &cudaSurfRes));
	glDrawArrays(GL_TRIANGLES, 0, 6);
}
Esempio n. 5
0
void SVG::render(const QRectF& texCoords)
{
    // get on-screen and full rectangle corresponding to the window in pixel units
    const QRectF screenRect = renderContext_->getGLWindow()->getProjectedPixelRect(true);
    const QRectF fullRect = renderContext_->getGLWindow()->getProjectedPixelRect(false); // maps to [tX, tY, tW, tH]

    // If we're not visible or we don't have a valid SVG, we're done.
    if(screenRect.isEmpty() || !svgRenderer_.isValid())
    {
        textureData_.erase(renderContext_->getActiveGLWindow()->getTileIndex());
        return;
    }

    // Get the texture for the current GLWindow
    SVGTextureData& textureData = textureData_[renderContext_->getActiveGLWindow()->getTileIndex()];

    const QRectF textureRect = computeTextureRect(screenRect, fullRect, texCoords);
    const QSize textureSize(round(screenRect.width()), round(screenRect.height()));

    const bool recreateTextureFbo = !textureData.fbo || textureData.fbo->size() != textureSize;

    if( recreateTextureFbo || textureRect != textureData.region )
    {
        if ( recreateTextureFbo )
        {
            textureData.fbo.reset( new QGLFramebufferObject( textureSize ));
        }

        renderToTexture(textureRect, textureData.fbo);

        // keep rendered texture information so we know when to rerender
        // this works great when the SVG is only rendered once per GLWindow
        // however, it will rerender every time otherwise, for example if the zoom context is shown
        textureData.region = textureRect;
    }
    assert(textureData.fbo);

    // figure out what visible region is for screenRect, a subregion of [0, 0, 1, 1]
    const float xp = (screenRect.x() - fullRect.x()) / fullRect.width();
    const float yp = (screenRect.y() - fullRect.y()) / fullRect.height();
    const float wp = screenRect.width() / fullRect.width();
    const float hp = screenRect.height() / fullRect.height();

    // Render the (scaled) unit textured quad
    glPushMatrix();

    glTranslatef(xp, yp, 0);
    glScalef(wp, hp, 1.f);

    drawUnitTexturedQuad(textureData.fbo->texture());

    glPopMatrix();
}
Esempio n. 6
0
/*
================
 SceneManager::render

 All rendering takes place here
================
*/
bool SceneManager::render()
{
	renderToTexture();

	renderRefractionToTexture();

	renderReflectionToTexture();

	renderScene();

	return true;
	
	/*
	// Render to texture first
	renderToTexture();

	// Clear buffers
	d3d_->beginScene(0.0f, 0.0f, 0.0f, 1.0f);
	
	// Render the scene to back buffer
	renderScene();
		
	
	// Render 2D window displaying the RenderTexture
	
	d3d_->turnZBufferOff();

	D3DXMATRIX worldMatrix, viewMatrix, orthoMatrix;

	d3d_->getWorldMatrix(worldMatrix);
	camera_->getViewMatrix(viewMatrix);
	d3d_->getOrthoMatrix(orthoMatrix);

	bool result = debugWindow_->render(d3d_->getDevice(), 150, 50);
	if (!result)
	{
		return false;
	}

	shaderManager_->renderTransparentShader(d3d_->getDevice(), debugWindow_->getIndexCount(), worldMatrix, viewMatrix, orthoMatrix, renderTexture_->getShaderResourceView(), 1.0f);
	
	d3d_->turnZBufferOn();
	

	// Present scene to the screen
	d3d_->endScene();

	return true;
	*/
}
Esempio n. 7
0
void drawFBO(int option)
{    
	if (option == 1) {
		glBindFramebuffer(GL_FRAMEBUFFER_EXT, mfbo);
		glPushAttrib(GL_VIEWPORT_BIT);
    
		glViewport(0, 0, width, height);
    
		// Draw scene.
		glClearColor(1.0, 1.0, 0.0, 0.0);
		glClear(GL_COLOR_BUFFER_BIT);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glRotatef(ang += 1, 1, 1, 1);

		drawScene();

		glPopAttrib();
		glBindFramebuffer(GL_READ_FRAMEBUFFER, mfbo);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
		glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
    
		// you have to unbind all fbos before you can render to the main window
		glBindFramebuffer(GL_FRAMEBUFFER, 0);    
			
		glBindTexture(GL_TEXTURE_2D, texture1);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		glEnable(GL_TEXTURE_2D);
		drawQuad();		
	} else {
		glClearColor(1.0, 1.0, 0.0, 0.0);		
		glClear(GL_COLOR_BUFFER_BIT);

		renderToTexture();	

		glutSwapBuffers();
	}
    
}
Esempio n. 8
0
void OGLWidget::gpuRayCast()
{
	//first pass, render ray entry and exit point to texture
	renderToTexture();	
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	//second pass, raycasting is performed in the raycasting shader

	glUseProgram(raycastingShader->programHandle);

	//Uniforms
	//--Set the 2D textures (entry- and exitpoint of ray)
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, entryPoint);
	auto tex_location = glGetUniformLocation(raycastingShader->programHandle, "entryPoint");
	glUniform1i(tex_location, 0);
	
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, exitPoint);
	tex_location = glGetUniformLocation(raycastingShader->programHandle, "exitPoint");
	glUniform1i(tex_location, 1);

	//--Set the 3D texture (volume Data);
	glEnable(GL_TEXTURE_3D),
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_3D, volumeTexture);
	tex_location = glGetUniformLocation(raycastingShader->programHandle, "volumeTexture");
	glUniform1i(tex_location, 2);
	glDisable(GL_TEXTURE_3D);

	//--width, height, depth, renderingtype (enum) and stepsize and firsthitThreshold as uniforms
	auto loc = glGetUniformLocation(raycastingShader->programHandle, "width");
	glUniform1i(loc, volume->width());

	loc = glGetUniformLocation(raycastingShader->programHandle, "height");
	glUniform1i(loc, volume->height());
	
	loc = glGetUniformLocation(raycastingShader->programHandle, "depth");
	glUniform1i(loc, volume->depth());

	loc = glGetUniformLocation(raycastingShader->programHandle, "rendering");
	glUniform1i(loc, (volume->gradient?3:volume->rendering));
	
	loc = glGetUniformLocation(raycastingShader->programHandle, "samplingStepSize");
	glUniform1f(loc, (float)samplingStepSize);

	loc = glGetUniformLocation(raycastingShader->programHandle, "firstHitThreshold");
	glUniform1f(loc, (float)volume->firstHitThreshold);

	loc = glGetUniformLocation(raycastingShader->programHandle, "rotationAxis");
	glUniform1i(loc, volume->rAxis);
		
	//--filter Kernels for gradient
	loc = glGetUniformLocation(raycastingShader->programHandle, "filterKernelX");
	glUniformMatrix3fv(loc, 1, GL_FALSE, glm::value_ptr(filterKernelX));

	loc = glGetUniformLocation(raycastingShader->programHandle, "filterKernelY");
	glUniformMatrix3fv(loc, 1, GL_FALSE, glm::value_ptr(filterKernelY));

	glBindVertexArray(VAOview);
	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
	
	glBindVertexArray(0);
	glUseProgram(0);
}