Esempio n. 1
0
ATOM_Vector3f LockedCamera::calcMoveVector (int x_rel, int y_rel) const
{
	ATOM_Vector3f right = getViewMatrix().transformVector (ATOM_Vector3f(1.f, 0.f, 0.f));
	right.y = 0;
	right.normalize ();

	ATOM_Vector3f forward = getViewMatrix().transformVector (ATOM_Vector3f(0.f, 0.f, 1.f));
	forward.y = 0;
	forward.normalize ();

	ATOM_Vector3f up = crossProduct (forward, right);
	up.normalize ();

	return -right * x_rel * _moveSpeed + forward * y_rel * _moveSpeed;
}
void GFXD3D9Device::setClipRect( const RectI &inRect ) 
{
	// We transform the incoming rect by the view 
   // matrix first, so that it can be used to pan
   // and scale the clip rect.
   //
   // This is currently used to take tiled screenshots.
	Point3F pos( inRect.point.x, inRect.point.y, 0.0f );
   Point3F extent( inRect.extent.x, inRect.extent.y, 0.0f );
   getViewMatrix().mulP( pos );
   getViewMatrix().mulV( extent );  
   RectI rect( pos.x, pos.y, extent.x, extent.y );

   // Clip the rect against the renderable size.
   Point2I size = mCurrentRT->getSize();

   RectI maxRect(Point2I(0,0), size);
   rect.intersect(maxRect);

   mClipRect = rect;

   F32 l = F32( mClipRect.point.x );
   F32 r = F32( mClipRect.point.x + mClipRect.extent.x );
   F32 b = F32( mClipRect.point.y + mClipRect.extent.y );
   F32 t = F32( mClipRect.point.y );

   // Set up projection matrix, 
   static Point4F pt;   
   pt.set(2.0f / (r - l), 0.0f, 0.0f, 0.0f);
   mTempMatrix.setColumn(0, pt);

   pt.set(0.0f, 2.0f/(t - b), 0.0f, 0.0f);
   mTempMatrix.setColumn(1, pt);

   pt.set(0.0f, 0.0f, 1.0f, 0.0f);
   mTempMatrix.setColumn(2, pt);

   pt.set((l+r)/(l-r), (t+b)/(b-t), 1.0f, 1.0f);
   mTempMatrix.setColumn(3, pt);

   setProjectionMatrix( mTempMatrix );

   // Set up world/view matrix
   mTempMatrix.identity();   
   setWorldMatrix( mTempMatrix );

   setViewport( mClipRect );
}
Esempio n. 3
0
void drawSun()
{   
	glUseProgram(sunShader);
	
	setupLighting(sunShader);
	
	//glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
	vec3 Position = getCameraPosition();
	
	v = getViewMatrix();
	
	mat4 a = translate(0.0, 0.0, -400.0); //333.0 Times
	mat4 rotation = rotateY(thetaY);
	mat4 b = multiplymat4(a, rotation);
	m = multiplymat4(b, scale(100.0));
	
	initMVP(sunShader, m, v);
	glUniform3f(glGetUniformLocation(sunShader, "cameraPos"), Position.x, Position.y, Position.z);
	glUniform1f(glGetUniformLocation(sunShader, "systemTime"), glfwGetTime());
    
    glBindVertexArray (planetVAO);
    bindTexture(GL_TEXTURE0, sunTexture);
    bindTexture(GL_TEXTURE1, sunNormal);
    glUniform1i(glGetUniformLocation(sunShader, "tex"), 0);
    glUniform1i(glGetUniformLocation(sunShader, "normalTex"), 1);
    
    glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber );
    glBindVertexArray(0);
    //glBindFramebuffer(GL_FRAMEBUFFER, 0);  
    
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, colorBuffer);
    glUniform1f(glGetUniformLocation(sunShader, "exposure"), 1.0);
}
Esempio n. 4
0
void drawPlanet()
{   
	glUseProgram(planetShader);
	setupLighting(planetShader);
	vec3 Position = getCameraPosition();
	v = getViewMatrix();
		
	for(int i = 0; i < 11; i++)
	{	
		mat4 rotation = multiplymat4(rotateY(rotationSpeedArray[i]), rotateX(planetInstanceArray[i].axialTilt+45));
		mat4 translation = multiplymat4(translate(planetInstanceArray[i].radius*1000, 0.0, 0.0), rotation);
		mat4 b = translate(0.0, 0.0, -400.0);
		mat4 roty = rotateY(orbitSpeedArray[i]);
		mat4 rotxy = multiplymat4(b, roty);
		mat4 c = multiplymat4(rotxy, translation);
		m = multiplymat4(c, scale(planetInstanceArray[i].size*100));
		planetInstanceArray[i].planetLocation = m;
    	
		//mv = modelMatrices[i];
		initMVP(planetShader, m, v);
		glUniform3f(glGetUniformLocation(planetShader, "cameraPos"), Position.x, Position.y, Position.z);
    
    	glBindVertexArray (planetVAO);
    	bindTexture(GL_TEXTURE0, planetInstanceArray[i].texture);
    	bindTexture(GL_TEXTURE1, planetInstanceArray[i].normal);
    	glUniform1i(glGetUniformLocation(planetShader, "tex"), 0);
    	glUniform1i(glGetUniformLocation(planetShader, "normalTex"), 1);
    	glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber);
    	glBindVertexArray(0);
    }
}
Esempio n. 5
0
void drawSkybox(Context &ctx)
{
	glm::mat4 view;
	getViewMatrix(&view);
	glm::mat4 view_transpose = glm::transpose(view);

	float fovy = getFovy(ctx);
	float aspect = ctx.aspect;

    // Activate program
	glUseProgram(ctx.skyboxProgram);

    // Bind textures
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_CUBE_MAP, ctx.cubemap);
	glUniform1i(glGetUniformLocation(ctx.skyboxProgram, "u_cubemap"), /*GL_TEXTURE0*/ 0);

	glUniformMatrix4fv(glGetUniformLocation(ctx.skyboxProgram, "u_view_transpose"), 1, GL_FALSE, &view_transpose[0][0]);
	glUniform1f(glGetUniformLocation(ctx.skyboxProgram, "u_fovy"), fovy);
	glUniform1f(glGetUniformLocation(ctx.skyboxProgram, "u_aspect"), aspect);

	// Draw!
	glBindVertexArray(ctx.skyboxVAO.vao);
	glDrawElements(GL_TRIANGLES, ctx.skyboxVAO.numIndices, GL_UNSIGNED_BYTE, 0);
    glBindVertexArray(ctx.defaultVAO);
}
	void GLProgramData::setUniformSource(const std::string & valName, CameraMatrixType camMatrixType, bool transpose)
	{
		const GLint loc = mProgram->getUniformLocation(valName);
		mSetters[valName] = [loc, camMatrixType, transpose, this]()
		{
			mProgram->checkBound();
			auto camera = Camera::getCurrent();

			switch (camMatrixType)
			{
			case CamMatrixType_Projection:
				glUniformMatrix4fv(loc, 1, transpose, (const GLfloat*)camera->getProjectionMatrixPtr());
				break;
			case CamMatrixType_View:
				glUniformMatrix4fv(loc, 1, transpose, (const GLfloat*)camera->getViewMatrixPtr());
				break;
			case CamMatrixType_ProjectionView:
				glUniformMatrix4fv(loc, 1, transpose, (const GLfloat*)camera->getProjectionViewMatrixPtr());
				break;
			case CamMatrixType_InvView:
				if (camera->getCameraGameObject())
					glUniformMatrix4fv(loc, 1, transpose, (const GLfloat*)camera->getCameraGameObject()->getGlobalTransformationPtr());
				else
					glUniformMatrix4fv(loc, 1, transpose, (const GLfloat*)&camera->getViewMatrix().invert());
				break;
			}

			CHECK_GL_ERROR();
		};
	}
Esempio n. 7
0
void Renderer::draw(GLFWwindow* window, unsigned char* frame_data, int width, int height)
{	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	// Simple shader
	shader_program->useProgram();
	
	// Background
	updateTexture(environment->getTextureID(), width, height, frame_data);
	glm::mat4 ortho_projection_matrix = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f);
	glm::mat4 env_model_matrix = position_object_in_scene(environment->getPosition());
	glm::mat4 model_projection_matrix = ortho_projection_matrix * env_model_matrix;
	shader_program->setUniforms(model_projection_matrix, environment->getTextureID());
	environment->draw();
	
	// Camera 
	computeMatricesFromInputs(window);
	glm::mat4 projection_matrix = getProjectionMatrix();
	glm::mat4 view_matrix = getViewMatrix();
	
	// Updates data and draws
	glm::mat4 model_matrix = position_object_in_scene(trophy->getPosition());
	glm::mat4 model_view_projection_matrix = projection_matrix * view_matrix * model_matrix; 
	shader_program->setUniforms(model_view_projection_matrix, trophy->getTextureID());
	trophy->draw();
	
	// Swaps drawing canvas
	glfwSwapBuffers(window);
	glfwPollEvents();
}
Esempio n. 8
0
float	C3dMouseListener::getOrientation()
{
	CVector	j = getViewMatrix().getJ();
	j.z = 0.0f;
	j.normalize();
	return (float)atan2(j.y, j.x);
}
Esempio n. 9
0
ElRay ElCamera::getCameraToViewportRay(float screenx, float screeny)
{
	D3DXMATRIX proj = getProjectionMatrix();
	D3DXMATRIX view = getViewMatrix();

	// Compute the vector of the Pick ray in screen space
	D3DXVECTOR3 v;
	v.x = ((2.0f * screenx) - 1.0f) / proj._11;
	v.y = (1.0f - (2.0f * screeny)) / proj._22;
	v.z = 1.0f;

	// Transform the screen space Pick ray into 3D space
	D3DXMATRIX m;
	D3DXMatrixInverse(&m, NULL, &view);
	
	D3DXVECTOR3 origin, direction;
	direction.x = v.x * m._11 + v.y * m._21 + v.z * m._31;
	direction.y = v.x * m._12 + v.y * m._22 + v.z * m._32;
	direction.z = v.x * m._13 + v.y * m._23 + v.z * m._33;
	origin.x = m._41;
	origin.y = m._42;
	origin.z = m._43;

	return ElRay(origin, direction);
}
Esempio n. 10
0
    /*! \brief Load the specified OpenGL texture matrix with the
      projection required for shadow mapping.
      
      \note The current OpenGL model view matrix must be the matrix
      used for rendering.
      
      \param textureUnit The texture unit whose matrix is to be
      setup for shadowmapping.
    */
    inline magnet::GL::GLMatrix getShadowTextureMatrix()
    {
      return magnet::GL::GLMatrix::translate(magnet::math::Vector(0.5, 0.5, 0.5))
	* magnet::GL::GLMatrix::scale(magnet::math::Vector(0.5, 0.5, 0.5))
	* getProjectionMatrix()
	* getViewMatrix();
    }
Esempio n. 11
0
	//---------------------------------------------------------------------
	void Frustum::calcViewMatrixRelative(const Vector3& relPos, Matrix4& matToUpdate) const
	{
		Matrix4 matTrans = Matrix4::IDENTITY;
		matTrans.setTrans(relPos);
		matToUpdate = getViewMatrix() * matTrans;

	}
Esempio n. 12
0
    void render() override
    {

        jassert (OpenGLHelpers::isContextActive());

        const float desktopScale = (float) openGLContext.getRenderingScale();
        OpenGLHelpers::clear (Colour::greyLevel (0.1f));

        glEnable (GL_BLEND);
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        glViewport (0, 0, roundToInt (desktopScale * getWidth()), roundToInt (desktopScale * getHeight()));

        shader->use();

        if (uniforms->projectionMatrix != nullptr)
            uniforms->projectionMatrix->setMatrix4 (getProjectionMatrix().mat, 1, false);

        if (uniforms->viewMatrix != nullptr)
            uniforms->viewMatrix->setMatrix4 (getViewMatrix().mat, 1, false);

        shape->draw (openGLContext, *attributes);

        // Reset the element buffers so child Components draw correctly
        openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, 0);
        openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);

    }
Esempio n. 13
0
	//---------------------------------------------------------------------
    void Camera::getCameraToViewportRay(Real screenX, Real screenY, Ray* outRay) const
    {
		Matrix4 inverseVP = (getProjectionMatrix() * getViewMatrix(true)).inverse();

#if OGRE_NO_VIEWPORT_ORIENTATIONMODE == 0
        // We need to convert screen point to our oriented viewport (temp solution)
        Real tX = screenX; Real a = getOrientationMode() * Math::HALF_PI;
        screenX = Math::Cos(a) * (tX-0.5f) + Math::Sin(a) * (screenY-0.5f) + 0.5f;
        screenY = Math::Sin(a) * (tX-0.5f) + Math::Cos(a) * (screenY-0.5f) + 0.5f;
        if ((int)getOrientationMode()&1) screenY = 1.f - screenY;
#endif

		Real nx = (2.0f * screenX) - 1.0f;
		Real ny = 1.0f - (2.0f * screenY);
		Vector3 nearPoint(nx, ny, -1.f);
		// Use midPoint rather than far point to avoid issues with infinite projection
		Vector3 midPoint (nx, ny,  0.0f);

		// Get ray origin and ray target on near plane in world space
		Vector3 rayOrigin, rayTarget;
		
		rayOrigin = inverseVP * nearPoint;
		rayTarget = inverseVP * midPoint;

		Vector3 rayDirection = rayTarget - rayOrigin;
		rayDirection.normalise();

		outRay->setOrigin(rayOrigin);
		outRay->setDirection(rayDirection);
    } 
Esempio n. 14
0
	void ShaderParamSet::setupGlobalParam( IShaderParamInput* input , ShaderParamGroup& paramGroup )
	{
		for ( ShaderParamList::iterator iter( paramGroup.paramList.begin() ), 
			                            itEnd( paramGroup.paramList.end() );
			iter != itEnd ; ++iter )
		{
			switch( iter->content )
			{
			case SP_WORLD:
				input->setUniform( iter->varName.c_str() , getWorldMatrix() );
				break;
			case SP_VIEW :
				input->setUniform( iter->varName.c_str() , getViewMatrix() );
				break;
			case SP_PROJ :
				input->setUniform( iter->varName.c_str() , getProjectMatrix() );
				break;
			case SP_WORLD_INV :
				input->setUniform( iter->varName.c_str() , getInvWorldMatrix() );
				break;
			case SP_VIEW_PROJ :
				input->setUniform( iter->varName.c_str() , getViewProjMatrix() );
				break;
			case SP_WVP :
				input->setUniform( iter->varName.c_str() , getWVPMatrix() );
				break;
			case SP_WORLD_VIEW:
				input->setUniform( iter->varName.c_str() , getWorldViewMatrix() );
				break;
			//case SP_AMBIENT_LIGHT:
			//	input->setUniform( iter->varName.c_str() , scene->setAmbientLight() );
			}
		}
	}
Esempio n. 15
0
  vec3 Camera::project(ivec2 vp, vec3 point) const {
    GLint viewport[4];
    GLdouble modelview[16];
    GLdouble projection[16];

    mat4 projection_glm = getProjectionMatrix(vp);
    mat4 modelview_glm = getViewMatrix();
    for (int i = 0; i < 4; ++i) {
      modelview[i + 0] = modelview_glm[i].x;
      modelview[i + 4] = modelview_glm[i].y;
      modelview[i + 8] = modelview_glm[i].z;
      modelview[i + 12] = modelview_glm[i].w;
      projection[i + 0] = projection_glm[i].x;
      projection[i + 4] = projection_glm[i].y;
      projection[i + 8] = projection_glm[i].z;
      projection[i + 12] = projection_glm[i].w;
    }
    viewport[0] = 0;
    viewport[1] = 0;
    viewport[2] = vp.x;
    viewport[3] = vp.y;

    GLdouble pointProjectedGL[3];
    gluProject(point.x, point.y, point.z, modelview, projection, viewport,
      &pointProjectedGL[0], &pointProjectedGL[1], &pointProjectedGL[2]);

    return vec3(static_cast<float>(pointProjectedGL[0]),
      static_cast<float>(pointProjectedGL[1]),
      static_cast<float>(pointProjectedGL[2]));
  }
Esempio n. 16
0
    void Light::generateShadowMap(std::vector<Geometry*>* renderQueue)
    {

        m_shaderProgram->use();
        m_fbo->use();

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		//glEnable(GL_CULL_FACE);
        //glCullFace(GL_FRONT);

        glViewport(0, 0, m_shadowMap_size.x, m_shadowMap_size.y);

        m_shaderProgram->setUniform(m_uniform_loc_view, getViewMatrix());
        m_shaderProgram->setUniform(m_uniform_loc_projection, getProjectionMatrix());

        for(unsigned int i = 0; i < renderQueue->size(); i++)
        {
            m_shaderProgram->setUniform(m_uniform_loc_model, renderQueue->at(i)->getTransform()->getModelMatrix() );
			m_shaderProgram->setUniformSampler(m_uniform_loc_diffuse_tex, renderQueue->at(i)->getMaterial()->getDiffuseTexture(), 0);
            renderQueue->at(i)->drawTriangles();
        }

		//glDisable(GL_CULL_FACE);
        m_shaderProgram->unuse();
        m_fbo->unuse();

    }
Esempio n. 17
0
void SceneView::cull()
{
    _dynamicObjectCount = 0;

    if (_camera->getNodeMask()==0) return;

    _renderInfo.setView(_camera->getView());

    // update the active uniforms
    updateUniforms();

    if (!_renderInfo.getState())
    {
        osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView::_state attached, creating a default state automatically."<< std::endl;

        // note the constructor for osg::State will set ContextID to 0 which will be fine to single context graphics
        // applications which is ok for most apps, but not multiple context/pipe applications.
        _renderInfo.setState(new osg::State);
    }
    
    osg::State* state = _renderInfo.getState();

    if (!_localStateSet)
    {
        _localStateSet = new osg::StateSet;
    }
    
    // we in theory should be able to be able to bypass reset, but we'll call it just incase.
    //_state->reset();
   
    state->setFrameStamp(_frameStamp.get());
    state->setDisplaySettings(_displaySettings.get());


    if (!_cullVisitor)
    {
        osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView:: attached, creating a default CullVisitor automatically."<< std::endl;
        _cullVisitor = CullVisitor::create();
    }
    if (!_stateGraph)
    {
        osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView:: attached, creating a global default StateGraph automatically."<< std::endl;
        _stateGraph = new StateGraph;
    }
    if (!_renderStage)
    {
        osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView::_renderStage attached, creating a default RenderStage automatically."<< std::endl;
        _renderStage = new RenderStage;
    }

    _cullVisitor->setTraversalMask(_cullMask);
    bool computeNearFar = cullStage(getProjectionMatrix(),getViewMatrix(),_cullVisitor.get(),_stateGraph.get(),_renderStage.get(),getViewport());

    if (computeNearFar)
    {
        CullVisitor::value_type zNear = _cullVisitor->getCalculatedNearPlane();
        CullVisitor::value_type zFar = _cullVisitor->getCalculatedFarPlane();
        _cullVisitor->clampProjectionMatrix(getProjectionMatrix(),zNear,zFar);
    }
}
Esempio n. 18
0
		void Node::draw(bool child, int numInstances, std::vector<mat4> rotMats, std::vector<ci::mat4> positions, std::vector<ci::mat4> scales){

				{
					
					if (numInstances == 0){
						gl::pushModelView();
						matrix = rotmat * glm::scale(scale);
						matrix[3] = vec4(trans,1);
						gl::multModelMatrix(matrix);

					}
					else {
						matrix = rotmat;
						rotMats.push_back(matrix);
						positions.push_back(glm::translate(trans));
						scales.push_back(glm::scale(scale));
					}
					
					//matrix[3] = vec4(trans,1);
					//gl::multModelMatrix(matrix);
					//double t1 = ci::app::getElapsedSeconds();
					//ci::app::console() << (t1 - t0) * 1000 << " : " << name << " : matrix node time " << std::endl;
					
					for (MeshRef pMesh : pMeshes)
					{
						//double t0 = ci::app::getElapsedSeconds();
						if (visible)
							pMesh->draw(numInstances, rotMats, positions, scales);
						//double t1 = ci::app::getElapsedSeconds();
						//ci::app::console() << (t1 - t0) * 1000 << " : "<< name << " : node draw time " << std::endl;

					}
					vec4 xform = getModelMatrix() * vec4(0, 0, 0, 1);
					worldPos = xform;
					std::vector<float> distances;
					for (NodeRef pChild : pChildren)
					{
						vec4 start = vec4(1);
						vec4 xform = getProjectionMatrix() * getViewMatrix() * getModelMatrix() * pChild->matrix * vec4(pChild->bounds.getCenter(), 1);
						distances.push_back(xform.z);
					}
					vector<pair<size_t, myiter> > order(distances.size());
					size_t n = 0;
					for (myiter it = distances.begin(); it != distances.end(); ++it, ++n)
						order[n] = make_pair(n, it);

					sort(order.begin(), order.end(), ordering());

					//ci::app::console() << ":::::::::::" << endl;
					for (auto pDrawOrder : order)
					{
						pChildren[pDrawOrder.first]->draw(true, numInstances, rotMats, positions, scales);
					}
					
					if (numInstances == 0){
						gl::popModelView();
					}
				}
		};
Esempio n. 19
0
glm::vec3 Z3DCamera::project(glm::vec3 wpt, glm::ivec4 viewport)
{
  glm::mat4 projection = getProjectionMatrix(CenterEye);
  glm::mat4 modelview = getViewMatrix(CenterEye);


  return glm::project(wpt, modelview, projection, viewport);
}
Esempio n. 20
0
float Camera::worldToEyeDepth( const vec3 &worldCoord ) const
{
	const mat4 &m = getViewMatrix();
	return	m[0][2] * worldCoord.x +
			m[1][2] * worldCoord.y +
			m[2][2] * worldCoord.z +
			m[3][2];
}
Esempio n. 21
0
	Matrix4 const& ShaderParamSet::getViewProjMatrix()
	{
		if ( mDirtyBit & DIRTY_VIEW_PROJ )
		{
			mViewProj = getViewMatrix() * getProjectMatrix();
			mDirtyBit &= ~DIRTY_VIEW_PROJ;
		}
		return mViewProj;
	}
Esempio n. 22
0
	Matrix4 const& ShaderParamSet::getWorldViewMatrix()
	{
		if ( mDirtyBit & DIRTY_WORLD_VIEW )
		{
			mWorldView = getWorldMatrix() * getViewMatrix();
			mDirtyBit &= ~DIRTY_WORLD_VIEW;
		}
		return mWorldView;
	}
Esempio n. 23
0
 //-----------------------------------------------------------------------------
 const Matrix4& AutoParamDataSource::getViewProjectionMatrix(void) const
 {
     if (mViewProjMatrixDirty)
     {
         mViewProjMatrix = getProjectionMatrix() * getViewMatrix();
         mViewProjMatrixDirty = false;
     }
     return mViewProjMatrix;
 }
Esempio n. 24
0
 //-----------------------------------------------------------------------------
 const Matrix4& AutoParamDataSource::getWorldViewMatrix(void) const
 {
     if (mWorldViewMatrixDirty)
     {
         mWorldViewMatrix = getViewMatrix().concatenateAffine(getWorldMatrix());
         mWorldViewMatrixDirty = false;
     }
     return mWorldViewMatrix;
 }
Esempio n. 25
0
 //-----------------------------------------------------------------------------
 const Matrix4& AutoParamDataSource::getInverseViewMatrix(void) const
 {
     if (mInverseViewMatrixDirty)
     {
         mInverseViewMatrix = getViewMatrix().inverseAffine();
         mInverseViewMatrixDirty = false;
     }
     return mInverseViewMatrix;
 }
Esempio n. 26
0
    void render() override
    {
        // Make sure an OpenGL graphics context has been defined
        jassert (OpenGLHelpers::isContextActive());

        // This allows to calculate correct pixel number by using
        // physical vs logical pixel number
        const float desktopScale = (float) openGLContext.getRenderingScale();
        
        // You need to clear the display upon every new frame unless you're dead sure
        // that nothing has changed, which you are not...
        OpenGLHelpers::clear (Colour::greyLevel (0.1f));

#if DEFAULT_TEXTURE == 2
        // Having used the juce 2D renderer, it will have messed-up a whole load of GL state, so
        // we need to initialise some important settings before doing our normal GL 3D drawing..
        glEnable (GL_DEPTH_TEST);
        glDepthFunc (GL_LESS);
        // Using a texture to paint main OpenGL object (teapot)
        openGLContext.extensions.glActiveTexture (GL_TEXTURE0); // Using texture #0
        glEnable (GL_TEXTURE_2D);
        // Tell the GPU to use that texture
        texture.bind();
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#endif
        // OpenGL method to blend the computed fragment color values with the values in the color buffers
        glEnable (GL_BLEND);
        // OpenGL method to specify how the red, green, blue, and alpha blending factors are computed.
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        // OpenGL method to specify viewport's x, y, width and height
        glViewport (0, 0, roundToInt (desktopScale * getWidth()), roundToInt (desktopScale * getHeight()));
        // This will call an OpenGL method to tell the GPU to use this program
        usedShaderProgram->use();
        
        if (uniforms->demoTexture != nullptr)
            uniforms->demoTexture->set ((GLint) 0);
            
        // Modify the uniform (global) variable projectionMatrix that will be used by the GPU when executing the shaders
        if (uniforms->projectionMatrix != nullptr)
            // Update the projection matrix with the values given, 1 matrix, do not transpose
            uniforms->projectionMatrix->setMatrix4 (getProjectionMatrix().mat, 1, false);

        // Modify the uniform (global) variable viewMatrix that will be used by the GPU when executing the shaders
        if (uniforms->viewMatrix != nullptr)
            // Update the view matrix with the values given, 1 matrix, do not transpose
            uniforms->viewMatrix->setMatrix4 (getViewMatrix().mat, 1, false);

        // This will fill a vertex buffer that is sent to the GPU to be used along with the attributes
        // by the GPU in the shaders. See Shape struct below. This buffer is called a Vertex Buffer Object
        // (VBO) and allows to send a bunch of variables at once to the GPU for better efficiency
        shape->draw (openGLContext, *attributes);

        // Reset the element buffers so child Components draw correctly
        openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, 0);
        openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
    }
Esempio n. 27
0
const glm::mat4& CTransformer::getViewProjectionMatrix() const
{
	if (m_viewProjection.m_matrixDirty)
	{
		m_viewProjection.m_matrix = getProjectionMatrix() * getViewMatrix();
		m_viewProjection.m_matrixDirty = false;
	}
	return m_viewProjection.m_matrix;
}
Esempio n. 28
0
void RenderTargetD3D9::setViewMatrix(const Matrix4& mtx)
{
    //if( m_RenderState.m_mtxView == mtx) return; //这种情况很少出现
    m_RenderState.m_mtxView = mtx;
    m_RenderState.m_mtxModelView = m_RenderState.m_mtxView * m_RenderState.m_mtxWorld;
    D3DXMATRIX mtxD3D;
    getViewMatrix(mtxD3D);
    m_pRenderSystem->getD3D9Device()->getDevice()->SetTransform( D3DTS_VIEW, &mtxD3D );
}
Esempio n. 29
0
 //-----------------------------------------------------------------------------
 const Affine3& AutoParamDataSource::getWorldViewMatrix(void) const
 {
     if (mWorldViewMatrixDirty)
     {
         mWorldViewMatrix = getViewMatrix() * getWorldMatrix();
         mWorldViewMatrixDirty = false;
     }
     return mWorldViewMatrix;
 }
Esempio n. 30
0
void modelMatrix(GLuint MatrixID)
{
	// Model matrix : an identity matrix (model will be at the origin)
	computeMatricesFromInputs();
	glm::mat4 ProjectionMatrix = getProjectionMatrix();
	glm::mat4 ViewMatrix = getViewMatrix();
	glm::mat4 ModelMatrix = glm::mat4(1.0);
	glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
	glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
}