コード例 #1
0
ファイル: GL2_Renderer.cpp プロジェクト: BraXi/FartyBear
bool OGL2_Renderer::Init()
{
	if( glewInit() != GLEW_OK  )
	{
		PRINTF( "Failed to initialize GLEW\n" );
		return false;
	}

	glEnable( GL_CULL_FACE );
	glEnable( GL_ALPHA_TEST );
	glEnable( GL_TEXTURE_2D );

	memset( &rconf, 1, sizeof( rconf ) );

	currentTexture = 123123;

	rconf.flags = 0;
	rconf.blendEnabled = true; // just to turn it off

	SetCulling( 0 );
	SetCulling( CULL_FRONT );
	SetDepthTest( DEPTH_DISABLED );
	SetDepthTest( DEPTH_LESS_EQUAL );
	SetAlphaTest( 0 );
	SetAlphaTest( 1 );
	SetAlphaTest( 0 );
	SetBlending( 0, 0 );
	SetBlending( BLEND_ONE, BLEND_ONE );
	SetBlending( 0, 0 );
//	glEnable( GL_DEPTH_TEST );
//	glDepthFunc( GL_LEQUAL );

	p_MainShader = PrecacheShader( "main" );
	p_MenuBgShader = PrecacheShader( "menubg" );

	PrecacheImage( "bear", 1024, 512, false );
	PrecacheImage( "pipe", 256, 128, false );
	PrecacheImage( "grass", 1024, 512, false );
	PrecacheImage( "dirt", 512, 512, false );
	PrecacheImage( "finish", 512, 256, false );

	PrecacheModel( "pipe_1" );
	PrecacheModel( "pipe_2" );
	PrecacheModel( "pipe_3" );
	PrecacheModel( "pipe_4" );
	PrecacheModel( "pipe_5" );
	PrecacheModel( "pipe_6" );
	PrecacheModel( "finish" );
	PrecacheModel( "bear" );
	PrecacheModel( "terrain" );

	p_Ortho->Init();

	return true;
}
コード例 #2
0
CRenderingContext::CRenderingContext(CRenderer* pRenderer, bool bInherit)
{
	m_pRenderer = pRenderer;

	m_clrRender = ::Color(255, 255, 255, 255);

	s_aContexts.push_back();

	if (bInherit && s_aContexts.size() > 1)
	{
		CRenderContext& oLastContext = s_aContexts[s_aContexts.size()-2];
		CRenderContext& oThisContext = GetContext();

		oThisContext.m_mProjection = oLastContext.m_mProjection;
		oThisContext.m_mView = oLastContext.m_mView;
		oThisContext.m_mTransformations = oLastContext.m_mTransformations;

		oThisContext.m_hMaterial = oLastContext.m_hMaterial;
		oThisContext.m_pFrameBuffer = oLastContext.m_pFrameBuffer;
		tstrncpy(oThisContext.m_szProgram, PROGRAM_LEN, oLastContext.m_szProgram, PROGRAM_LEN);
		oThisContext.m_pShader = oLastContext.m_pShader;

		oThisContext.m_rViewport = oLastContext.m_rViewport;
		oThisContext.m_eBlend = oLastContext.m_eBlend;
		oThisContext.m_flAlpha = oLastContext.m_flAlpha;
		oThisContext.m_bDepthMask = oLastContext.m_bDepthMask;
		oThisContext.m_bDepthTest = oLastContext.m_bDepthTest;
		oThisContext.m_eDepthFunction = oLastContext.m_eDepthFunction;
		oThisContext.m_bCull = oLastContext.m_bCull;
		oThisContext.m_bWinding = oLastContext.m_bWinding;

		m_pShader = oThisContext.m_pShader;

		if (m_pShader)
			m_iProgram = m_pShader->m_iProgram;
		else
			m_iProgram = 0;
	}
	else
	{
		m_pShader = NULL;

		BindTexture(0);
		UseMaterial(CMaterialHandle());
		UseFrameBuffer(NULL);
		UseProgram("");

		SetViewport(Rect(0, 0, Application()->GetWindowWidth(), Application()->GetWindowHeight()));
		SetBlend(BLEND_NONE);
		SetAlpha(1);
		SetDepthMask(true);
		SetDepthTest(true);
		SetDepthFunction(DF_LESS);
		SetBackCulling(true);
		SetWinding(true);
	}
}
コード例 #3
0
CRenderingContext::~CRenderingContext()
{
	TAssert(s_aContexts.size());

	s_aContexts.pop_back();

	if (s_aContexts.size())
	{
		CRenderContext& oContext = GetContext();

		UseMaterial(oContext.m_hMaterial);
		UseFrameBuffer(oContext.m_pFrameBuffer);
		UseProgram(oContext.m_pShader);

		if (*oContext.m_szProgram)
		{
			oContext.m_bProjectionUpdated = false;
			oContext.m_bViewUpdated = false;
			oContext.m_bTransformUpdated = false;
		}

		SetViewport(oContext.m_rViewport);
		SetBlend(oContext.m_eBlend);
		SetAlpha(oContext.m_flAlpha);
		SetDepthMask(oContext.m_bDepthMask);
		SetDepthTest(oContext.m_bDepthTest);
		SetDepthFunction(oContext.m_eDepthFunction);
		SetBackCulling(oContext.m_bCull);
		SetWinding(oContext.m_bWinding);
	}
	else
	{
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, 0);

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		if (m_pRenderer)
			glViewport(0, 0, (GLsizei)m_pRenderer->m_iWidth, (GLsizei)m_pRenderer->m_iHeight);
		else
			glViewport(0, 0, (GLsizei)Application()->GetWindowWidth(), (GLsizei)Application()->GetWindowHeight());

		glUseProgram(0);

		glDisablei(GL_BLEND, 0);

		glDepthMask(true);
		glEnable(GL_DEPTH_TEST);
		glEnable(GL_CULL_FACE);
		glDepthFunc(GL_LESS);

		glFrontFace(GL_CCW);
	}
}
コード例 #4
0
ファイル: GLRenderState.cpp プロジェクト: mironside/rabid
void GLRenderState::Bind()
{
  SetBlend(srcBlend, dstBlend);
  SetBlendFunc(blendFunc);
  SetAlphaTest(alphaTest, alphaRef);
  SetCull(cullMode);
  SetDepthTest(depthTest);
  SetDepthWrite(depthWrite);

/*
  if(!curState)
  {

    curState = this;
    return;
  }

  if(curState->GetSrcBlend()  != srcBlend ||
     curState->GetDstBlend()  != dstBlend)
  {
    SetBlend(srcBlend, dstBlend);
  }

  if(curState->GetBlendFunc() != blendFunc)
  {
    SetBlendFunc(blendFunc);
  }

  if(curState->GetAlphaTest() != alphaTest ||
     curState->GetAlphaRef()   != alphaRef)
  {
    SetAlphaTest(alphaTest, alphaRef);
  }

  if(curState->GetDepthTest() != depthTest)
  {
    SetDepthTest(depthTest);
  }

  if(curState->GetDepthWrite() != depthWrite)
  {
    SetDepthWrite(depthWrite);
  }

  if(curState->GetCullMode() != cullMode)
  {
    SetCull(cullMode);
  }
*/
  curState = this;
}
コード例 #5
0
ファイル: glrsi.cpp プロジェクト: tweakoz/orkid
void GlRasterStateInterface::BindRasterState( SRasterState const &newstate, bool bForce )
{
	bForce = true;
	
	bool bAlphaTestChanged =	(newstate.GetAlphaTest()	!=	mLastState.GetAlphaTest()		);
//	bool bTextureModeChanged =	(newstate.GetTextureMode()	!=	rLast.GetTextureMode()		);
//	bool bTextureActiveChanged =(newstate.GetTextureActive()!=	rLast.GetTextureActive()	);
	bool bBlendingChanged =		(newstate.GetBlending()		!=	mLastState.GetBlending()			);
	bool bDepthTestChanged =	(newstate.GetDepthTest()	!=	mLastState.GetDepthTest()		);
	//bool bStencilModeChanged =(newstate.GetStencilID()	!=	rLast.GetStencilID()		);
	bool bShadeModelChanged =	(newstate.GetShadeModel()	!=	mLastState.GetShadeModel()		);
	bool bCullTestChanged =		(newstate.GetCullTest()		!=	mLastState.GetCullTest()			);
	bool bScissorTestChanged =	(newstate.GetScissorTest()	!=	mLastState.GetScissorTest()		);
	
	GL_ERRORCHECK();

	if( bCullTestChanged || bForce )
	{
		SetCullTest( newstate.GetCullTest() );
	}

	/////////////////////////////////////////////////

	SetZWriteMask( newstate.GetZWriteMask() );
	SetRGBAWriteMask( newstate.GetRGBWriteMask(), newstate.GetAWriteMask() );

	/////////////////////////////////////////////////

	if( true )
	{
		glDisable( GL_STENCIL_TEST );
	}

	/////////////////////////////////////////////////
	//	Win32 GL Alpha
	
	if( false )
	{
	//	glDisable( GL_ALPHA_TEST );
	}
	else if( bAlphaTestChanged || bForce )
	{	
		static const F32 frecip = 1.0f / 15.0f;

		F32 fAlphaRef = frecip * (F32) newstate.muAlphaRef;

		switch( newstate.muAlphaTest )
		{	case EALPHATEST_OFF:
				//glDisable( GL_ALPHA_TEST );
				GL_ERRORCHECK();
				break;
			case EALPHATEST_GREATER:
				//glEnable( GL_ALPHA_TEST );
				//glAlphaFunc( GL_GREATER, fAlphaRef );
				GL_ERRORCHECK();
				break;
			case EALPHATEST_LESS:
				//glEnable( GL_ALPHA_TEST );
				//glAlphaFunc( GL_LESS, fAlphaRef );
				GL_ERRORCHECK();
				break;
		}
	}
		
	/////////////////////////////////////////////////
	//	Win32 GL Depth

	if(1)// bDepthTestChanged || bForce )
		SetDepthTest( newstate.GetDepthTest() );

	/////////////////////////////////////////////////

	if( bScissorTestChanged || bForce )
	{
		SetScissorTest( newstate.GetScissorTest() );
	}
	
	/////////////////////////////////////////////////

	if( bBlendingChanged || bForce )
	{
		SetBlending( newstate.GetBlending() );
	}
	
	GL_ERRORCHECK();
	
	if( false )
	{
		//glShadeModel( GL_FLAT );
	}
	else if( bShadeModelChanged || bForce )
	{
		switch( newstate.GetShadeModel() )
		{
			case ESHADEMODEL_FLAT:
				//glShadeModel( GL_FLAT );
				break;
			case ESHADEMODEL_SMOOTH:
				//glShadeModel( GL_SMOOTH );
				break;
			default:
				break;
		}
	}
	GL_ERRORCHECK();

}