Exemple #1
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : frame - 
//			x - 
//			y - 
//			*prcSubRect - 
//-----------------------------------------------------------------------------
void CEngineSprite::DrawFrameOfSize( int frame, int x, int y, int iWidth, int iHeight, const wrect_t *prcSubRect )
{
	// FIXME: If we ever call this with AVIs, need to have it call GetTexCoordRange and make that work
	Assert( !IsAVI() && !IsBIK() );

	float fLeft = 0;
	float fRight = 1;
	float fTop = 0;
	float fBottom = 1;

	if ( prcSubRect )
	{
		AdjustSubRect( this, frame, &fLeft, &fRight, &fTop, &fBottom, &iWidth, &iHeight, prcSubRect );
	}

	if ( giScissorTest && !Scissor( x, y, iWidth, iHeight, fLeft, fTop, fRight, fBottom ) )
		return;

	SetFrame( frame );

	CMatRenderContextPtr pRenderContext( materials );
	IMesh* pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, GetMaterial() );

	CMeshBuilder meshBuilder;
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

	float color[3];
	GetHUDSpriteColor( color );
	
	meshBuilder.Color3fv( color );
	meshBuilder.TexCoord2f( 0, fLeft, fTop );
	meshBuilder.Position3f( x, y, 0.0f );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv( color );
	meshBuilder.TexCoord2f( 0, fRight, fTop );
	meshBuilder.Position3f( x + iWidth, y, 0.0f );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv( color );
	meshBuilder.TexCoord2f( 0, fRight, fBottom );
	meshBuilder.Position3f( x + iWidth, y + iHeight, 0.0f );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv( color );
	meshBuilder.TexCoord2f( 0, fLeft, fBottom );
	meshBuilder.Position3f( x, y + iHeight, 0.0f );
	meshBuilder.AdvanceVertex();

	meshBuilder.End();
	pMesh->Draw();
}
Exemple #2
0
void
GL::EnableScissorTest(const IntRect& aScissorRect)
{
  MOZ_ASSERT(IsCurrent());

  if (!mScissorTestEnabled) {
    Enable(GL_SCISSOR_TEST);
    mScissorTestEnabled = true;
  }

  if (!mScissorRect.IsEqualInterior(aScissorRect)) {
    Scissor(aScissorRect.x, aScissorRect.y, aScissorRect.width, aScissorRect.height);
    mScissorRect = aScissorRect;
  }
}
Exemple #3
0
void CGraphicsModule::pushScissor(bool enable, int x, int y, int width, int height, bool offset) {
    
    int cutx = 0;
    int cuty = 0;
    int cutwidth = 0;
    int cutheight = 0;
    
    int nX = x;
    int nY = y;
    int nWidth = width;
    int nHeight = height;
    
    if ( enable ) {
        glEnable(GL_SCISSOR_TEST);
        if ( scissorStack.size() > 0 ) {
            Scissor s = *scissorStack.end()--;
            if ( x < s.x ) {
                cutx = s.x - x;
            }
            if ( y < s.y ) {
                cuty = s.y - y;
            }
            if ( x + width > s.x + s.width ) {
                cutwidth = (x + width) - (s.x + s.width);
            }
            if ( y + height > s.y + s.height ) {
                cutheight = (y + height) - (s.y + s.height);
            }
        }
        nX = x - cutx;
        nY = getHeight() - y - cuty - height;
        nWidth = width - cutx - cutwidth;
        nHeight = height - cuty - cutheight;
        glScissor(nX, nY, nWidth, nHeight);
    } else {
        glDisable(GL_SCISSOR_TEST);
    }
    
    if (offset == true) {
        offsetX += x;
        offsetY += y;
    }
    
    scissorStack.push_back(Scissor(enable, nX, nY, nWidth, nHeight, offset, x, y));
}
Exemple #4
0
VOID Editor::Run()
{
	// check the window rect
	RECT wnd_rc; ::GetClientRect(mWnd, &wnd_rc);
	I32 wnd_width = wnd_rc.right-wnd_rc.left;
	I32 wnd_height = wnd_rc.bottom-wnd_rc.top;
	if(wnd_width<=0||wnd_height<=0) return;

	// get the frame time
	static U32 system_time = Timer::instance().time();
	U32 current_time = Timer::instance().time();
	U32 frame_time = current_time - system_time;
	if(frame_time == 0) return;
	system_time = current_time;

	if(mGraphPtr==NULL) return;

	// reset the render context
	mGraphPtr->Reset();

	// get the window rect	
	Vector4 rect = Vector4(wnd_rc.left, wnd_rc.top, wnd_rc.right, wnd_rc.bottom);

	// set the viewport
	mGraphPtr->viewport(rect);
	ViewportPtr viewport = GNEW(Viewport(rect[0],rect[1],rect[2],rect[3])); CHECK(viewport);
	mGraphPtr->draw(static_cast<Operation*>(viewport.Ptr()));

	// set the scissor
	ScissorPtr scissor = GNEW(Scissor(rect[0],rect[1],rect[2],rect[3]));
	mGraphPtr->draw(static_cast<Operation*>(scissor.Ptr()));

	// clear the target and the zbuffer
	ClearPtr clear = GNEW(Clear(Clear::CT_COLOR|Clear::CT_DEPTH,Vector4(0.5,0.5,0.5,1.0),1.0f)); CHECK(clear);
	mGraphPtr->draw(static_cast<Operation*>(clear.Ptr()));

	// make the projection and the view
	F32 left	= -P2U(wnd_width/2)*mScale;
	F32 right	= P2U(wnd_width/2)*mScale;
	F32 bottom	= -P2U(wnd_height/2)*mScale;
	F32 top		= P2U(wnd_height/2)*mScale;
	F32 znear	= -512.0;
	F32 zfar	= 512.0;
	mGraphPtr->projection(Matrix::makeOrtho(left,right,bottom,top,znear,zfar));
	mGraphPtr->view(Matrix::makeTranslate(-mEye));

	// draw the map
	if(mMapPtr)
	{
		// update the map
		Vector3 start(rect[0], rect[1], 0);
		mGraphPtr->unproject(start, start);
		Vector3 end(rect[2], rect[3], 0);
		mGraphPtr->unproject(end, end);
		mMapPtr->Update(Vector4(start[0], start[1], end[0], end[1]));

		// draw the map
		mMapPtr->Draw(mGraphPtr.Ptr());

		// draw the reference line
		if(mDrawGrid)
		{
			mMapPtr->DrawReferenceLine(mGraphPtr.Ptr());
		}		
	}	

	// draw the brush
	if(mBrushPtr) mBrushPtr->Draw(mGraphPtr.Ptr());

	// swap the graph buffer
	mGraphPtr->swap();

	// swap buffers
	eglSwapBuffers(mDisplay, mSurface);
}
Exemple #5
0
/*
====================
run
====================
*/
VOID Game::run(F32 delta_time)
{
    // reset the render context
    mGraphPtr->Reset();

    // draw the box
    // mBoxPtr->draw(mGraphPtr.Ptr());
    // mCapsulePtr->draw(mGraphPtr.Ptr());
    // mConePtr->draw(mGraphPtr.Ptr());
    // mCylinderPtr->draw(mGraphPtr.Ptr());
    // mSpherePtr->draw(mGraphPtr.Ptr());

    mAngle += 0.1f;

    mPawnPtr->Play("idle");
    mPawnPtr->Tick(delta_time);

    // draw the color rt
    {
        mGraphPtr->draw(static_cast<Operation*>(mColorRTPtr.Ptr()));

        // get the window rect
        Vector4 rect = Vector4(0.0f,0.0f,(F32)mColorTexPtr->Width(), (F32)mColorTexPtr->Height());

        // set the viewport
        mGraphPtr->viewport(rect);
        ViewportPtr viewport = GNEW(Viewport((I32)rect[0],(I32)rect[1],(I32)rect[2],(I32)rect[3]));
        CHECK(viewport);
        mGraphPtr->draw(static_cast<Operation*>(viewport.Ptr()));

        // set the scissor
        ScissorPtr scissor = GNEW(Scissor((I32)rect[0],(I32)rect[1],(I32)rect[2],(I32)rect[3]));
        mGraphPtr->draw(static_cast<Operation*>(scissor.Ptr()));

        // clear the target and the zbuffer
        ClearPtr clear = GNEW(Clear(Clear::CT_COLOR|Clear::CT_DEPTH,Vector4(0.0f,0.0f,0.0f,0.0f),1.0f));
        CHECK(clear);
        mGraphPtr->draw(static_cast<Operation*>(clear.Ptr()));

        // make the projection and the modelview
        Matrix proj_mat = Matrix::makePerspective(mFov,mAspect,mZNear,mZFar);
        mGraphPtr->projection(proj_mat);
        Matrix view_mat = Matrix::makeLookAt(mEye,mCenter,mUp);
        mGraphPtr->view(view_mat);

        // draw the pawn
        {
            AUTO_LOCK_WORLD(mGraphPtr.Ptr());
            Quaternion quat;
            quat.setRotate(GMath::degToRad(mAngle),Vector3(0,0,1));
            Matrix world = Matrix::makeRotate(quat);
            mGraphPtr->world(world*mGraphPtr->world());
            mPawnPtr->Draw(mGraphPtr.Ptr());
        }
    }

    // draw the null rt
    {
        mGraphPtr->draw(static_cast<Operation*>(mNullRTPtr.Ptr()));

        // get the window rect
        Vector4 rect = Vector4(0,0,(F32)mWndWidth, (F32)mWndHeight);

        // set the viewport
        mGraphPtr->viewport(rect);
        ViewportPtr viewport = GNEW(Viewport((I32)rect[0],(I32)rect[1],(I32)rect[2],(I32)rect[3]));
        CHECK(viewport);
        mGraphPtr->draw(static_cast<Operation*>(viewport.Ptr()));

        // set the scissor
        ScissorPtr scissor = GNEW(Scissor((I32)rect[0],(I32)rect[1],(I32)rect[2],(I32)rect[3]));
        mGraphPtr->draw(static_cast<Operation*>(scissor.Ptr()));

        // clear the target and the zbuffer
        ClearPtr clear = GNEW(Clear(Clear::CT_COLOR|Clear::CT_DEPTH,Vector4(0.5f,0.4f,0.5f,1.0f),1.0f));
        CHECK(clear);
        mGraphPtr->draw(static_cast<Operation*>(clear.Ptr()));

        // draw the pawn
        {
            AUTO_LOCK_WORLD(mGraphPtr.Ptr());

            // make the projection and the modelview
            Matrix proj_mat = Matrix::makePerspective(mFov,mAspect,mZNear,mZFar);
            mGraphPtr->projection(proj_mat);
            Matrix view_mat = Matrix::makeLookAt(mEye,mCenter,mUp);
            mGraphPtr->view(view_mat);

            Quaternion quat;
            quat.setRotate(GMath::degToRad(mAngle),Vector3(0,0,1));
            Matrix world = Matrix::makeRotate(quat);
            mGraphPtr->world(world*mGraphPtr->world());
            mPawnPtr->Draw(mGraphPtr.Ptr());
        }

        // draw the quad
        {
            AUTO_LOCK_WORLD(mGraphPtr.Ptr());

            // compute the ortho matrix
            F32 left, right, bottom, top, nearval, farval;
            left = -(F32)mWndWidth / 2.0f;
            right = (F32)mWndWidth / 2.0f;
            bottom = -(F32)mWndHeight / 2.0f;
            top = (F32)mWndHeight / 2.0f;
            nearval = 0.0f;
            farval = 1.0f;

            // make the projection and the modelview
            Matrix proj_mat = Matrix::makeOrtho(left, right, bottom, top, nearval, farval);
            mGraphPtr->projection(proj_mat);
            Matrix view_mat = Matrix::makeTranslate(Vector3(left,bottom,0.0));
            mGraphPtr->view(view_mat);
            mQuadPtr->GetConstant("gWVP")->SetMatrix(mGraphPtr->wvp());
            mGraphPtr->draw(static_cast<Operation*>(mQuadPtr.Ptr()));
        }
    }

    // swap the graph buffer
    mGraphPtr->swap();
}