bool CEffectTechnique::BeginRender()
{
    if ( m_Effect )
    {
        // Obtain the direct x effect
        LPD3DXEFFECT l_Effect = m_Effect->GetEffect();
        D3DXHANDLE l_Handle = NULL;

        //
        // Debug color, only for debug primitives
        //
        m_Effect->SetDebugColor( mUseDebugColor, m_DebugColor );

        if ( mUseFBSize )
        {
          uint32 lWidth, lHeight;
          GraphicsInstance->GetWidthAndHeight( lWidth, lHeight );
          if( !m_Effect->SetFBSize( Math::Vect2u(lWidth, lHeight ) ) )
            LOG_WARNING_APPLICATION("Error setting Fb size" );
        }

        SetupMatrices();
        SetupLights();
    }

    return true;
}
예제 #2
0
파일: Lights.cpp 프로젝트: arlukin/dev
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    // Clear the backbuffer and the zbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                         D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Setup the lights and materials
        SetupLights();

        // Setup the world, view, and projection matrices
        SetupMatrices();

        // Render the vertex buffer contents
        g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
        g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
        g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 );

        // End the scene
        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
예제 #3
0
void MainScreen::onInit(ScreenContext& sc)
{
    // Store engine ref
    mEngine = sc.GetEngine();

    // Store file data cache ref
    mFileDataCache = sc.GetFileDataCache();

    // Cube rotation state
    mRotationData.degreesInc = 0.05f;
    mRotationData.rotating = false;

    // Camera initial position
    mCamera.SetPos(glm::vec3(0, 0, 8));

    // Add sample UV Sphere
    ModelData sphereModel = GenUVSphere(1, 32, 32);
    mEngine->GetModelStore().Load("4", std::move(sphereModel));

    // Create world objects
    SetupWorld();

    // Create world lights
    SetupLights();

    // Cam shouldn't follow character initially
    mFollowingCharacter = false;

    // Initial choosen moving light
    mMovingLightIndex = 0;

    // Init character
    mCharacter.Init(&mEngine->GetWindow(), mScene.get());

    // Load the skybox
    ImageLoader imLoader;
    auto& cubemapStore = mEngine->GetCubemapStore();
    cubemapStore.Load(skybox, imLoader.Load(*(*mFileDataCache)["ext/Assets/Textures/Skybox/Bluesky/bluesky.tga"], "tga"));
    mEngine->GetSkyboxRenderer().SetCubemapId(cubemapStore[skybox]->id);

    // Load the irr map
    mEngine->GetCubemapStore().Load(irrmap, imLoader.Load(*(*mFileDataCache)["ext/Assets/Textures/Skybox/Bluesky/bluesky_irr.tga"], "tga"));

    // Load the rad map
    for (unsigned int i = 0; i < 9; ++i) {
        mEngine->GetCubemapStore().Load(
            radmap,
            imLoader.Load(*(*mFileDataCache)[
                              "ext/Assets/Textures/Skybox/Bluesky/bluesky_rad_" + std::to_string(i) + ".tga"], "tga"), i);
    }

    // Do not show AABBs by default
    mShowAABBs = false;

    // Do not show Debug info by default
    mShowDbgInfo = false;

    // Init renderform creator
    mRenderformCreator = std::make_unique<RenderformCreator>(&(mEngine->GetModelStore()), &(mEngine->GetMaterialStore()));
}
예제 #4
0
VOID Render()
{
	// 背景为蓝色
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		// 茶壶的材料颜色也定义在这个函数中
		SetupLights();

		// Setup the world, view, and projection matrices
		SetupMatrices();

		// Render the vertex buffer contents
		g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
		g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

		//创建一个茶壶

		D3DXMATRIX  Worlds;
		D3DXCreateTeapot(g_pd3dDevice, &Objects, 0);
		Objects->DrawSubset(0);
		//释放Mesh(网格)
		Objects->Release();
		Objects = 0;
		// End the scene
		g_pd3dDevice->EndScene();
	}

	// Present the backbuffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
	//Objects->Release();
}
예제 #5
0
파일: bunny.cpp 프로젝트: vcoda/glesbench
//
// Initialize
//
bool Initialize(int argc, char *argv[])
{
    puts("Initialize...");

#if !defined(USE_SDL) && !defined(USE_EGL)
    glewInit();
#endif

    g_pBunny = new CMesh(bunny::g_Vertices, sizeof(bunny::g_Vertices),
        bunny::g_Indices, sizeof(bunny::g_Indices) / sizeof(bunny::g_Indices[0]), true);

    g_pSphere = new CMesh(sphere::g_Vertices, sizeof(sphere::g_Vertices),
        sphere::g_Indices, sizeof(sphere::g_Indices) / sizeof(sphere::g_Indices[0]), false);

    g_pFont = new CBffFont("fixedsys.bff");
    g_pTitleFont = new CBffFont("arialn.bff");
    g_pTitleFont->SetScale(0.8f);
    g_pTitleFont->SetColor(XMFLOAT3(0.75f, 0.75f, 0.75f));
    g_pFraps = new CFraps();
    g_pBackground = new CBackground();

    bool bShaders = LoadShaders();
    assert(bShaders);

    // Get light count
    const char *optstring = "p:";
    char p_arg[80];

    p_arg[0] = '\0';
    optind = 1; // Reset getopt

    int opt = getopt(argc, argv, optstring);
    while (opt != -1)
    {
        switch (opt)
        {
        case 'p':
            strcpy(p_arg, optarg);
            break;
        }

        opt = getopt(argc, argv, optstring);
    }

    unsigned LightCount = (unsigned)(p_arg[0] ? atoi(p_arg) : 8);

    // Allow no more than 8 point lights
    if (LightCount > 8)
        LightCount = 8;

    SetupLights(LightCount);

    // Setup render states once
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    return true;
}
예제 #6
0
//==========================================================================
//
// 
//
//==========================================================================
void GLWall::Draw(int pass)
{
	gl_RenderState.SetNormal(glseg.Normal());
	switch (pass)
	{
	case GLPASS_LIGHTSONLY:
		SetupLights();
		break;

	case GLPASS_ALL:
		SetupLights();
		// fall through
	case GLPASS_PLAIN:
		RenderTextured(RWF_TEXTURED);
		break;

	case GLPASS_TRANSLUCENT:

		switch (type)
		{
		case RENDERWALL_MIRRORSURFACE:
			RenderMirrorSurface();
			break;

		case RENDERWALL_FOGBOUNDARY:
			RenderFogBoundary();
			break;

		default:
			RenderTranslucentWall();
			break;
		}
		break;

	case GLPASS_LIGHTTEX:
	case GLPASS_LIGHTTEX_ADDITIVE:
	case GLPASS_LIGHTTEX_FOGGY:
		RenderLightsCompat(pass);
		break;

	case GLPASS_TEXONLY:
		gl_RenderState.SetMaterial(gltexture, flags & 3, 0, -1, false);
		RenderWall(RWF_TEXTURED);
		break;
	}
}
/**-----------------------------------------------------------------------------
 * 애니메이션 설정
 *------------------------------------------------------------------------------
 */
VOID Animate()
{
	D3DXMatrixIdentity( &g_matAni );

	SetupLights();
	ProcessInputs();

	LogFPS();
}
예제 #8
0
void GLWall::RenderTranslucentWall()
{
	bool transparent = gltexture? gltexture->GetTransparent() : false;
	
	// currently the only modes possible are solid, additive or translucent
	// and until that changes I won't fix this code for the new blending modes!
	bool isadditive = RenderStyle == STYLE_Add;

	if (gl_fixedcolormap == CM_DEFAULT && gl_lights && (gl.flags & RFL_BUFFER_STORAGE))
	{
		SetupLights();
	}

	if (!transparent) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold);
	else gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
	if (isadditive) gl_RenderState.BlendFunc(GL_SRC_ALPHA,GL_ONE);

	int extra;
	if (gltexture) 
	{
		gl_RenderState.EnableGlow(!!(flags & GLWF_GLOW));
		gl_RenderState.SetMaterial(gltexture, flags & 3, 0, -1, false);
		extra = getExtraLight();
	}
	else 
	{
		gl_RenderState.EnableTexture(false);
		extra = 0;
	}
	int tmode = gl_RenderState.GetTextureMode();

	gl_SetColor(lightlevel, extra, Colormap, fabsf(alpha));
	if (type!=RENDERWALL_M2SNF) gl_SetFog(lightlevel, extra, &Colormap, isadditive);
	else
	{
		if (flags & GLT_CLAMPY)
		{
			if (tmode == TM_MODULATE) gl_RenderState.SetTextureMode(TM_CLAMPY);
		}
		gl_SetFog(255, 0, NULL, false);
	}

	RenderWall(RWF_TEXTURED|RWF_NOSPLIT);

	// restore default settings
	if (isadditive) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	if (!gltexture)	
	{
		gl_RenderState.EnableTexture(true);
	}
	gl_RenderState.EnableGlow(false);
	gl_RenderState.SetTextureMode(tmode);
}
예제 #9
0
파일: test5.cpp 프로젝트: edvorg/cpp-drash
        Test5::Test5(greng::Greng& greng) : Test3(greng) {
            SetupProcessors();
            SetupMeshes();
            SetupTextures();
            SetupShaders();
            SetupLights();

            light1.position.Set(0, 50, 0);

            GetDebugRenderer().SetLight(&light1);
        }
/**-----------------------------------------------------------------------------
 * 애니메이션 설정
 *------------------------------------------------------------------------------
 */
VOID Animate()
{
    /// 0 ~ 2PI 까지(0~360도) 값을 변화시킴 Fixed Point기법 사용
    DWORD d = GetTickCount() % ( (int)((D3DX_PI*2) * 1000) );
    /// Y축 회전행렬
//	D3DXMatrixRotationY( &g_matAni, d / 1000.0f );
    D3DXMatrixIdentity( &g_matAni );

    LogFPS();

    SetupLights();
    ProcessInputs();
}
예제 #11
0
/**-----------------------------------------------------------------------------
 * 애니메이션 설정
 *------------------------------------------------------------------------------
 */
VOID Animate()
{
	D3DXMATRIXA16	matX;
	D3DXMATRIXA16	matY;

	D3DXMatrixRotationX( &matX, g_xRot );
	D3DXMatrixRotationY( &matY, g_yRot );
	g_matWorld = matX * matY;
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld ); /// 디바이스에 월드행렬 설정
	SetupLights();
	SetupPS();
	LogFPS();						// 로깅
}
예제 #12
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
	// Clear the backbuffer and the zbuffer
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );

	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		// Setup the world, view, and projection matrices
		SetupMatrices();

		SetupLights();

		// Meshes are divided into subsets, one for each material. Render them in
		// a loop
		for( DWORD i = 0; i < g_dwNumMaterials; i++ )
		{
			// Set the material and texture for this subset
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );

			// Draw the mesh subset
			g_pMesh->DrawSubset( i );
		}
		D3DXMATRIXA16 mat;
		D3DXMatrixTranslation( &mat, 1,0,0 );
		g_pd3dDevice->SetTransform( D3DTS_WORLD, &mat );
		for( DWORD i = 0; i < g_dwNumMaterials2; i++ )
		{
			// Set the material and texture for this subset
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials2[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures2[i] );

			// Draw the mesh subset
			g_pMesh->DrawSubset( i );
		}

		// End the scene
		g_pd3dDevice->EndScene();
	}
	LPDIRECT3DTEXTURE9* pTemp = g_pMeshTextures;
	g_pMeshTextures = g_pMeshTextures2;
	g_pMeshTextures2 = pTemp;
	// Present the backbuffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
/**-----------------------------------------------------------------------------
 * 애니메이션 설정
 *------------------------------------------------------------------------------
 */
VOID Animate()
{
	D3DXMatrixIdentity( &g_matAni );

	SetupLights();
	ProcessInputs();

	D3DXMATRIXA16	m;
	D3DXMATRIXA16	*pView;
	pView = g_pCamera->GetViewMatrix();	// 카메라 클래스로부터 행렬정보를 얻는다.
	m = *pView * g_matProj;				// World좌표를 얻기위해서 View * Proj행렬을 계산한다.
	if ( !g_bLockFrustum )
	{
		g_pFrustum->Make( &m );	// View*Proj행렬로 Frustum을 만든다.
	}
	ProcessFrustumCull();		// Frustum정보를 기반으로, 보여질 삼각형의 인덱스를 만든다.

	LogFPS();
}
예제 #14
0
int main(int argc, char **argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(100, 100);
	glutCreateWindow(argv[0]);
	init();
	LoadGLTexTures(g_texture, "body.bmp");
	LoadGLTexTures_head(g_texture_head, "face.bmp");
	LoadGLTexTures_ground(g_texture_ground, "ground.bmp");
	LoadGLTexTures_sky(g_texture_sky, "sky.bmp");
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);  //屏幕刷新是用
	glutKeyboardFunc(keyboard);//按下按键
	glutPassiveMotionFunc(passiveMotionFunc);//鼠标转动
	SetupLights();
	glutMainLoop();
	return 0;
}
예제 #15
0
파일: poolscene.cpp 프로젝트: mkkellogg/GTE
/*
 * Set up all elements of the scene using [importer] to load any assets from disk.
 *
 * [ambientLightObject] - Global scene object that contains the global ambient light.
 * [directLightObject] - Global scene object that contains the global directional light.
 * [playerObject] - Scene object that contains the player mesh & renderer.
 */
void PoolScene::Setup(GTE::AssetImporter& importer, GTE::SceneObjectSharedPtr ambientLightObject, GTE::SceneObjectSharedPtr directionalLightObject, GTE::SceneObjectSharedPtr playerObject) {
    importer.SetBoolProperty(GTE::AssetImporterBoolProperty::PreserveFBXPivots, false);

    // get reference to the engine's object manager
    GTE::EngineObjectManager * objectManager = GTE::Engine::Instance()->GetEngineObjectManager();

    sceneRoot = objectManager->CreateSceneObject();
    ASSERT(sceneRoot.IsValid(), "Could not create scene root for pool scene!\n");

    SetupTerrain(importer);
    SetupStructures(importer);
    SetupPlants(importer);
    SetupExtra(importer);
    SetupWaterSurface(importer);
    SetupLights(importer, playerObject);

    this->directionalLightObject = directionalLightObject;
    this->playerObject = playerObject;
}
예제 #16
0
VOID Render()
{
    if( !g_pd3dDevice ) return;
    LPDIRECT3DDEVICE9 d = g_pd3dDevice;

    d->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
    
    if( SUCCEEDED( d->BeginScene() ) ) {
        SetupLights();
        SetupMatrices();

        d->SetStreamSource( 0, g_pVertexBuff, 0, sizeof(CUSTOMVERTEX) );
        d->SetFVF( D3DFVF_CUSTOMVERTEX );
        d->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2 );
        //d->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
        d->EndScene();
    }
    d->Present( NULL, NULL, NULL, NULL );
}
VOID Render()
{
	if ( NULL == g_pd3dDevice )
	{
		return;
	}

	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 30, 10, 10 ), 1.0f, 0 );

	if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		SetupLights();

		SetupMatrices();

		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

		D3DXMATRIXA16 thisMatrix;

		D3DXMatrixTranslation( &thisMatrix, 0.0f, -10.0f, 30.0f );
		g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix );
		D3DXMatrixRotationY( &thisMatrix, timeGetTime() / 1000.0f );
		g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix );
		D3DXMatrixScaling( &thisMatrix, 1.0f, 1.2f, 1.0f );
		g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix );


		for ( DWORD i = 0; i < g_dwNumMaterials; ++i )
		{
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
			g_pMesh->DrawSubset( i );
		}

		g_pd3dDevice->EndScene();
	}

	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
예제 #18
0
HRESULT ColladaLoader::Run()
{
	StartLogging();

	if(!Initialize()) {
        StopLogging();
        return -1;
    } else {
        SetupShaders();
        SetupMatrices();
        SetupLights();
        SetupGeometry();
        MainLoop();
        Terminate();
        StopLogging();
    }

	return 0;

}
VOID Render()
{
	g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );

	if ( SUCCEEDED( g_pD3DDevice->BeginScene() ) )
	{
		SetupLights();

		SetupMatrices();

		g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
		g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
		g_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

		//soldier
		D3DXMATRIXA16 matFirstTiger, matTrans, matRotate;
		//D3DXMatrixIdentity(&matFirstTiger);

		//g_pD3DDevice->GetTransform(D3DTS_WORLD, &matFirstTiger);
		D3DXMatrixTranslation( &matTrans, 0.f, -2.f, 0.f );
		D3DXMatrixRotationY( &matRotate, timeGetTime() / 1000.0f );
		D3DXMatrixMultiply( &matFirstTiger, &matRotate, &matTrans );
		g_pD3DDevice->SetTransform( D3DTS_WORLD, &matFirstTiger );


		for ( DWORD i = 0; i < g_dwNumMaterials; ++i )
		{
			g_pD3DDevice->SetMaterial( &g_pMeshMaterials0[i] );
			g_pD3DDevice->SetTexture( 0, g_pMeshTextures0[i] );

			g_pMesh0->DrawSubset( i );
		}

		g_pD3DDevice->EndScene();
	}

	g_pD3DDevice->Present( NULL, NULL, NULL, NULL );
	g_tick++;
}
예제 #20
0
HRESULT CMainFrame::Render()
{
    HRESULT hr = E_FAIL;
    CHECK_POINTER_RETURN_VALUE_IF_FAIL(m_pD3dDevice, E_POINTER);

    // Clear the backbuffer to a blue color
    DX_VERIFY(m_pD3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
        D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ));

    // Begin the scene
    DX_VERIFY(m_pD3dDevice->BeginScene());
    if( SUCCEEDED( hr ))
    {
#ifndef DRAW_FISHJAM_2D
        DX_VERIFY(SetupLights());
        DX_VERIFY(SetupMatrices());
#endif

        //通过Stream的方式绘制 vertices,先指定 Source
        DX_VERIFY(m_pD3dDevice->SetStreamSource( 0, m_pD3dVertexBuffer, 0, sizeof(FISHJAM_VERTEX)));

        //设置FVF的格式,使得D3D知道 m_pD3dVertexBuffer 中 Vertex 的格式
        DX_VERIFY(m_pD3dDevice->SetFVF( D3DFVF_FISHJAM_VERTEX ));
        //输出

        //DX_VERIFY(m_pD3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1));  //输出三角形
        DX_VERIFY(m_pD3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2)); //输出圆柱
        
                                               
        // End the scene
        DX_VERIFY(m_pD3dDevice->EndScene());
    }

    // Present the back buffer contents to the display
    DX_VERIFY(m_pD3dDevice->Present( NULL, NULL, NULL, NULL ));

    return hr;
}
예제 #21
0
void GLWall::RenderTranslucentWall()
{
	if (gltexture)
	{
		if (mDrawer->FixedColormap == CM_DEFAULT && gl_lights && gl.lightmethod == LM_DIRECT)
		{
			SetupLights();
		}
		if (!gltexture->GetTransparent()) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold);
		else gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
		if (RenderStyle == STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA,GL_ONE);
		RenderTextured(RWF_TEXTURED | RWF_NOSPLIT);
		if (RenderStyle == STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	else
	{
		gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
		mDrawer->SetColor(lightlevel, 0, Colormap, fabsf(alpha));
		mDrawer->SetFog(lightlevel, 0, &Colormap, RenderStyle == STYLE_Add);
		gl_RenderState.EnableTexture(false);
		RenderWall(RWF_NOSPLIT);
		gl_RenderState.EnableTexture(true);
	}
}
예제 #22
0
//-----------------------------------------------------------------------------
// Desc: 渲染图形 
//-----------------------------------------------------------------------------
VOID Render()
{
	//清空后台缓冲区和深度缓冲区
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(45, 50, 170), 1.0f, 0 );

	//开始在后台缓冲区绘制图形
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		//设置材料和灯光, 因为灯光属性不断变化,所以在此设置
		SetupLights();

		//在后台缓冲区绘制图形
		g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
		g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
		g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 );

		//结束在后台缓冲区绘制图形
		g_pd3dDevice->EndScene();
	}

	//将在后台缓冲区绘制的图形提交到前台缓冲区显示
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
예제 #23
0
//==========================================================================
//
// 
//
//==========================================================================
void GLWall::Draw(int pass)
{
	int rel;
	int tmode;

#ifdef _DEBUG
	if (seg->linedef-lines==879)
	{
		int a = 0;
	}
#endif


	switch (pass)
	{
	case GLPASS_LIGHTSONLY:
		SetupLights();
		break;

	case GLPASS_ALL:
		SetupLights();
		// fall through
	case GLPASS_PLAIN:
		rel = rellight + getExtraLight();
		gl_SetColor(lightlevel, rel, Colormap,1.0f);
		tmode = gl_RenderState.GetTextureMode();
		if (type!=RENDERWALL_M2SNF) gl_SetFog(lightlevel, rel, &Colormap, false);
		else
		{
			if (flags & GLT_CLAMPY)
			{
				if (tmode == TM_MODULATE) gl_RenderState.SetTextureMode(TM_CLAMPY);
			}
			gl_SetFog(255, 0, NULL, false);
		}
		gl_RenderState.EnableGlow(!!(flags & GLWF_GLOW));
		gl_RenderState.SetMaterial(gltexture, flags & 3, false, -1, false);
		RenderWall(RWF_TEXTURED|RWF_GLOW);
		gl_RenderState.EnableGlow(false);
		gl_RenderState.SetTextureMode(tmode);
		break;

	case GLPASS_TRANSLUCENT:


		switch (type)
		{
		case RENDERWALL_MIRRORSURFACE:
			RenderMirrorSurface();
			break;

		case RENDERWALL_FOGBOUNDARY:
			RenderFogBoundary();
			break;

		case RENDERWALL_COLORLAYER:
			glEnable(GL_POLYGON_OFFSET_FILL);
			glPolygonOffset(-1.0f, -128.0f);
			RenderTranslucentWall();
			glDisable(GL_POLYGON_OFFSET_FILL);
			glPolygonOffset(0, 0);

		default:
			RenderTranslucentWall();
			break;
		}
	}
}
예제 #24
0
int main(int argc, char* argv[])
{
	bool bIsbowlingMode = false;
	std::wstring input2 = L"Hello! Please enter 1 if you wish to try the bowling mode. Enter anything else to play checkpoint mode";
	std::wcout << input2 << std::endl;
	std::wstring input;
	std::getline(std::wcin, input);
	if (input == L"1")
	{
		bIsbowlingMode = true;
	}

	bool bLoadTires = false;
	std::wstring input3 = L"Would you like to load the tire models? (loading tires may cause slowdown) y/n";
	std::wcout << input3 << std::endl;
	std::wstring input4;
	std::getline(std::wcin, input4);
	if (input4 == L"y")
	{
		bLoadTires = true;
	}


	printTheWhatsThisProgramAboutBlurb();

	::g_gameState.currentGameMode = CGameState::GAME_LOADING;

	::OpenGL_Initialize( argc, argv, 1200, 800 );		// Initialize(argc, argv);
	//::OpenGL_Initialize( argc, argv, 640, 480 );		// Initialize(argc, argv);


	// CModelLoaderManager
	g_pModelLoader = new CModelLoaderManager();
	g_pModelLoader->SetRootDirectory( "assets/models" );

	std::vector< CModelLoaderManager::CLoadInfo > vecModelsToLoad;

	if (bIsbowlingMode)
		ReadInModelsInfo("assets/BowlingScene.txt");
	else 
		ReadInModelsInfo("assets/Scene.txt");

	for (unsigned int i = 0; i < vecModelsInfo.size(); i++)
	{
		::g_mapModelTypes[vecModelsInfo[i].type] = vecModelsInfo[i].file;
		if (vecModelsInfo[i].tex.size() > 0)
			::g_mapTextures[i] = vecModelsInfo[i].tex[0];
		//vecModelsToLoad.push_back(CModelLoaderManager::CLoadInfo(vecModelsInfo[i].file, 1.0f, true));
	}
	for (unsigned int i = 0; i < vecModelsInfo.size(); i++)
	{
		for (std::map<std::string, std::string>::iterator jIterator = g_mapModelTypes.begin(); jIterator != ::g_mapModelTypes.end(); jIterator++)
		{
			if (vecModelsInfo[i].type == jIterator->first){
				if (vecModelsInfo[i].isEnvironment){
					vecModelsToLoad.push_back(CModelLoaderManager::CLoadInfo(jIterator->second));
				}
				else
					vecModelsToLoad.push_back(CModelLoaderManager::CLoadInfo(jIterator->second, 1.0f, true));
			}
		}
	}

	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("sphere_UV_xyz.ply", 1.0f, true) );
	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("Cube.ply", 1.0f, true ) );
	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("Cube2.ply", 1.0f, true));
	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("1x1_6_Star_2_Sided.ply", 1.0f, true ) );
	vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("truck.ply", 1.0f, true));
	//vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("truck2.ply", 1.0f, true));
	if (bLoadTires)
		vecModelsToLoad.push_back( CModelLoaderManager::CLoadInfo("tire.ply", 1.0f, true));

	if ( ! g_pModelLoader->LoadModels( vecModelsToLoad ) )
	{
		std::cout << "Can't load one or more models. Sorry it didn't work out." << std::endl;
		return -1;
	}

	g_pShaderManager = new CGLShaderManager();
	//LoadShaders();		// Moved from CreateCube
	CShaderDescription uberVertex;
	uberVertex.filename = "assets/shaders/OpenGL.LightTexSkyUber.vertex.glsl";
	uberVertex.name = "UberVertex";

	CShaderDescription uberFragment;
	uberFragment.filename = "assets/shaders/OpenGL.LightTexSkyUber.fragment_texture.glsl";
	uberFragment.name = "UberFragment";

	CShaderProgramDescription uberShader("UberShader", uberVertex, uberFragment );

	if ( !g_pShaderManager->CreateShaderProgramFromFile( uberShader ) )
	{
		std::cout << "Error compiling one or more shaders..." << std::endl;
		std::cout << g_pShaderManager->getLastError() << std::endl;
		std::cout << uberShader.getErrorString() << std::endl;
		return -1;
	}

	::SetUpTextures();

	std::cout << "Starting Havok" << std::endl;
	g_pFactoryMediator = new CFactoryMediator();
	// ******************************************************
	// Set up the Havok physics thing
	// Create a Havok Physic thingie:
	// Passing "Havok" gives us a physics manager using Havok. 
	// Anything else is an error...
	// if crashing on release, right click on Desktop->NVIDIA Contol Panel->Set PhysX configuration. Select a PhysX dropdown menu->CPU
	//::g_pPhysicsManager = CPhysicsManagerFactory::CreatePhysicsMananger( L"Havok" ); 

	if ((::g_pPhysicsManager = CPhysicsManagerFactory::CreatePhysicsMananger(L"Havok")) == 0){
		std::cout << "Failed Creating Havok" << std::endl;  std::cout.flush();
	}
	// 
	std::cout << "Havok Created" << std::endl; std::cout.flush();
	std::vector< CNameValuePair2 > vecParams;
	vecParams.push_back( CNameValuePair2( L"VisualDebugger", true ) );

	::g_pPhysicsManager->Init(vecParams); 
	// ******************************************************************
	
	std::cout << "Done with physics." << std::endl;	std::cout.flush();

	static const float oneDegreeInRadians = static_cast<float>(PI) / 180.0f;

	for (unsigned i = 0; i < vecModelsInfo.size(); i++)
	{
		CPhysicalProp physicalProp;
		physicalProp.position = vecModelsInfo[i].pos;
		physicalProp.setOrientationEulerAngles(CVector3f(oneDegreeInRadians * vecModelsInfo[i].rot.x, oneDegreeInRadians * vecModelsInfo[i].rot.y, oneDegreeInRadians * vecModelsInfo[i].rot.z));
		physicalProp.rotStep = vecModelsInfo[i].rot;

		CMeshDesc mesh(vecModelsInfo[i].file);
		mesh.scale = vecModelsInfo[i].scale;
		mesh.bIsSkybox = vecModelsInfo[i].isSkybox;
		mesh.bIsPlayer = vecModelsInfo[i].isPlayer;
		mesh.modelID = i;
		mesh.blend = vecModelsInfo[i].blend;
		mesh.debugColour = CVector4f(vecModelsInfo[i].col.x, vecModelsInfo[i].col.y, vecModelsInfo[i].col.z, 1.0f);
		mesh.bIsParticle = vecModelsInfo[i].isParticle;

		if (vecModelsInfo[i].isTransparent){
			mesh.bIsTransparent = true;
			mesh.tranparency = vecModelsInfo[i].transparency;
		}
		else{
			mesh.bIsTransparent = false;
			mesh.tranparency = 1.0f;
		}

		if (vecModelsInfo[i].tex.size() > 0)
		{
			mesh.bHasTexture = true;
			mesh.firstTex = vecModelsInfo[i].firstTex;
		}


		mesh.ObjectType = vecModelsInfo[i].type;
		if (vecModelsInfo[i].isSkybox || vecModelsInfo[i].isParticle)
			mesh.bIsHavok = false;

		vecModelsInfo[i].ID = g_pFactoryMediator->CreateObjectByType(vecModelsInfo[i].type, physicalProp, mesh);

		makeHavokObject(vecModelsInfo[i].ID);

		if (vecModelsInfo[i].isPlayer)
			::g_FloorHavokID = vecModelsInfo[i].ID;
		if (vecModelsInfo[i].isSkybox)
			::g_skyBoxID = vecModelsInfo[i].ID;
		//if (vecModelsInfo[i].isLightBall)
		//	::g_lightModelID = vecModelsInfo[i].ID;
		if (vecModelsInfo[i].isParticle)
			::g_vecParticleID.push_back(vecModelsInfo[i].ID);
	}
	
	

	CMeshDesc sphereMesh("sphere_UV_xyz.ply");
	sphereMesh.debugColour = CVector4f(0.75f, 0.5f, 0.3f, 0.0f);
	sphereMesh.bIsTransparent = true;
	sphereMesh.tranparency = 0.4f;
	CPhysicalProp sphereProps( CVector3f( 0.0f, 5.0f, 4.0f ) );
	sphereProps.position = (CVector3f(0.0f, 5.0f, 0.0f));
	::g_lightModelID = g_pFactoryMediator->CreateObjectByType( "Sphere UV", sphereProps, sphereMesh );

	CMeshDesc sphereHavokMesh("sphere_UV_xyz.ply");
	sphereHavokMesh.debugColour = CVector4f(0.75f, 0.5f, 0.3f, 0.0f);
	sphereHavokMesh.ObjectType = "Star";
	sphereHavokMesh.bIsHavok = false;
	CPhysicalProp sphereHavokProps( CVector3f( 0.0f, 5.0f, -10.0f ) );
	::g_StarHavokID = g_pFactoryMediator->CreateObjectByType( "Sphere UV", sphereHavokProps, sphereHavokMesh );

	//makeHavokObject(::g_StarHavokID);




	//for (int i = 1; i < 4; i++){
	//	for (int j = 1; j < 4; j++){
	//		CMeshDesc floorHavokMesh("Cube2.ply");
	//		floorHavokMesh.debugColour = CVector4f(0.75f, 0.5f, 0.3f, 0.0f);

	//		floorHavokMesh.bHasTexture = true;
	//		if (i == 2 && j == 2){
	//			floorHavokMesh.ObjectType = "IceFloor";
	//		}
	//		else {
	//			floorHavokMesh.ObjectType = "GroundFloor";
	//		}
	//		floorHavokMesh.scale = floorSize;
	//		//CPhysicalProp floorHavokProps(CVector3f(-(floorSize / 2.0f), -floorSize, -(floorSize / 2.0f)));
	//		CVector3f floorPosition;
	//		floorPosition.x = i*(-(floorSize / 2.0f));
	//		floorPosition.z = j*(-(floorSize / 2.0f));
	//		floorPosition.y = -floorSize;
	//		CPhysicalProp floorHavokProps(floorPosition);
	//		unsigned int floorID = g_pFactoryMediator->CreateObjectByType("Cube UV", floorHavokProps, floorHavokMesh);

	//		makeHavokObject(floorID);
	//	}
	//}

	CMeshDesc truckMesh("truck.ply");
	truckMesh.ObjectType = "Vehicle";
	truckMesh.scale = 5.0f;

	CPhysicalProp truckProps(CVector3f(0.0f, 5.0f, 4.0f));
	truckProps.position = (CVector3f(0.0f, 5.0f, 0.0f));
	::g_Player_ID = g_pFactoryMediator->CreateObjectByType("Player", truckProps, truckMesh);

	makeHavokObject(::g_Player_ID);

	if (bLoadTires){
		CMeshDesc tireMesh("tire.ply");
		tireMesh.bIsHavok = false;
		tireMesh.scale = 1.0f;
		g_pFactoryMediator->addMeshDescription(::g_Player_ID, tireMesh);
		g_pFactoryMediator->addMeshDescription(::g_Player_ID, tireMesh);
		g_pFactoryMediator->addMeshDescription(::g_Player_ID, tireMesh);
		g_pFactoryMediator->addMeshDescription(::g_Player_ID, tireMesh);
	}
	



	/*CMeshDesc checkpointHavokMesh("Cube2.ply");
	checkpointHavokMesh.debugColour = CVector4f(0.75f, 0.5f, 0.3f, 0.0f);
	checkpointHavokMesh.ObjectType = "CheckPoint";
	CPhysicalProp checkpointHavokProps(CVector3f(0.0f, 0.0f, 0.0f));
	unsigned int checkpoint_ID = g_pFactoryMediator->CreateObjectByType("Sphere UV", checkpointHavokProps, checkpointHavokMesh);

	makeHavokObject(checkpoint_ID);*/

	



	g_pPhysicsManager->SetCheckPoints(vecCheckPointsInfo);

	//g_pPhysicsManager

	//GenerateAABBWorld();

	// Added October 3, 2014
	g_pCamera = new CCamera();
	// Camera expects an IMediator*, so cast it as that
	g_pCamera->SetMediator( (IMediator*)g_pFactoryMediator );

	g_pCamera->eye.x = 0.0f;		// Centred (left and right)
	g_pCamera->eye.y = 5.0f;		// 2.0 units "above" the "ground"
	g_pCamera->eye.z = -20.0f;		// .0funits0 from "back" the origin    .  1, 2.5, 1.8
	g_pCamera->target.x = 50.0f;		// Centred (left and right)
	g_pCamera->target.y = 350.0f;		// 2.0 units "above" the "ground"
	g_pCamera->target.z = 50.0f;		// 0.0 units "back" from the origin
	g_pCamera->cameraAngleYaw = 2.8f;
	g_pCamera->cameraAnglePitch = -0.2f;

	g_pCamera->up.x = 0.0f;
	g_pCamera->up.y = 1.0f;				// The Y axis is "up and down"

	g_pCamera->m_LEFPLookupMode = CCamera::LERP;

	g_pCamera->setMode_FollowAtDistance( ::g_Player_ID );
	float followSpeed = 30.0f;		// 1.0f whatever per second
	float followMinDistance = 3.0f;
	float followMaxSpeedDisance = 100.0f;
	g_pCamera->setFollowDistances( followMinDistance, followMaxSpeedDisance );
	g_pCamera->setFollowMaxSpeed( followSpeed );

	// A "fly through" camera
	// These numbers are sort of in the direction of the original camera
	g_pCamera->orientation = glm::fquat( 0.0960671529f, 0.972246766f, -0.0900072306f, -0.193443686f );
	glm::normalize( g_pCamera->orientation );
	//g_pCamera->setMode_IndependentFreeLook();


	g_pMouseState = new CMouseState();

	// Set up the basic lighting
	ExitOnGLError("Error setting light values");
	SetupLights();

		//
	if ( !::g_p_LightManager->initShadowMaps( 1, CLightManager::DEFAULT_SHADOW_DEPTH_TEXTURE_SIZE ) )
	{
		std::cout << "Error setting up the shadow textures: " << std::endl;
		std::cout << ::g_p_LightManager->getLastError();
	}

	setUpShadowTexture();


	g_p_GameControllerManager = CGameControllerManager::getGameControllerManager();
	g_p_GameController_0 = g_p_GameControllerManager->getController(0);
	if ( ( g_p_GameController_0 != 0 ) && 
		 ( g_p_GameController_0->bIsConnected() ) )
	{
		g_p_GameController_0->AddVibrationSequence( IGameController::CVibStep::LEFT, 0.5f, 2.0f );
		g_p_GameController_0->AddVibrationSequence( IGameController::CVibStep::RIGHT, 0.5f, 1.0f );
		std::cout << "Game controller 0 found!" << std::endl;
	}
	else 
	{
		std::cout << "Didn't get an ID for the game controller; is there one plugged in?" << std::endl;
	}


	//***************************************
	g_p_checkpointEmitter = new CParticleEmitter();
	g_p_timerEmitter = new CParticleEmitter();
	//**************************************

	CPhysicalProp starProps;
	::g_pFactoryMediator->getPhysicalPropertiesByID(::g_StarHavokID, starProps);
	g_p_checkpointEmitter->SetLocation(starProps.position);
	::g_p_checkpointEmitter->GenerateParticles(1, /*number of particles*/
		CVector3f(0.0f, 0.0f, 0.0f), /*Init veloc.*/
		0.1f, /*dist from source */
		5.0f, /*seconds*/
		true);
	::g_p_checkpointEmitter->SetAcceleration(CVector3f(0.0f, 0.0f, 0.0f));

	g_p_timerEmitter->SetLocation(truckProps.position);
	::g_p_timerEmitter->GenerateParticles(1, /*number of particles*/
		CVector3f(0.0f, 1.0f, 0.0f), /*Init veloc.*/
		0.01f, /*dist from source */
		1.0f, /*seconds*/
		true);
	::g_p_timerEmitter->SetAcceleration(CVector3f(0.0f, 1.0f, 0.0f));



	::g_p_PhysicsThingy = new CPhysicsCalculatron();


	// Added in animation on Sept 19
	::g_simTimer.Reset();
	::g_simTimer.Start();		// Start "counting"

	if (bIsbowlingMode)
	{
		::g_gameState.currentGameMode = CGameState::GAME_BOWLING;
	}
	else
		::g_gameState.currentGameMode = CGameState::GAME_RUNNING;
	
	// FULL SCREEN, Mr. Data!
	//::glutFullScreen();

	ExitOnGLError("Error getting uniform light variables");

	glutMainLoop();

	std::cout << "Shutting down..." << std::endl;

	ShutDown();
  
	exit(EXIT_SUCCESS);
}
VOID Render()
{
	g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);

	if (SUCCEEDED(g_pD3DDevice->BeginScene()))
	{
		SetupLights();

		SetupMatrices();

		if (15 < (g_tick % 31))
		{
			g_pD3DDevice->SetTexture(0, g_pTexture0);
		}
		else
		{
			g_pD3DDevice->SetTexture(0, g_pTexture1);
		}
		g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
		g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
		g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
		

		g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer0, 0, sizeof(CUSTOMVERTEX));
		g_pD3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2);

		g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer1, 0, sizeof(CUSTOMVERTEX));
		g_pD3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2);



		//tiger 1
		D3DXMATRIXA16 matFirstTiger, matTrans, matRotate;
		//D3DXMatrixIdentity(&matFirstTiger);

		//g_pD3DDevice->GetTransform(D3DTS_WORLD, &matFirstTiger);
		D3DXMatrixTranslation(&matTrans, -3.f, -1.5f, -1.6f);		
		D3DXMatrixRotationY(&matRotate, timeGetTime() / 1000.0f);
		D3DXMatrixMultiply(&matFirstTiger, &matRotate, &matTrans);
		g_pD3DDevice->SetTransform(D3DTS_WORLD, &matFirstTiger);

		
		for (DWORD i = 0; i < g_dwNumMaterials; ++i)
		{
			g_pD3DDevice->SetMaterial(&g_pMeshMaterials0[i]);
			g_pD3DDevice->SetTexture(0, g_pMeshTextures0[i]);

			g_pMesh0->DrawSubset(i);
		}


		//tiger 2
		D3DXMATRIXA16 matSecondTiger;
		D3DXMatrixIdentity(&matSecondTiger);
		D3DXMatrixIdentity(&matTrans);
		D3DXMatrixIdentity(&matRotate);

		g_pD3DDevice->GetTransform(D3DTS_WORLD, &matSecondTiger);
		D3DXMatrixTranslation(&matTrans, 3.f, -1.5f, -1.6f);
		D3DXMatrixRotationY(&matRotate, -(timeGetTime() / 1000.0f));
		D3DXMatrixMultiply(&matSecondTiger, &matRotate, &matTrans);
		g_pD3DDevice->SetTransform(D3DTS_WORLD, &matSecondTiger);

		for (DWORD i = 0; i < g_dwNumMaterials; ++i)
		{
			g_pD3DDevice->SetMaterial(&g_pMeshMaterials0[i]);
			g_pD3DDevice->SetTexture(0, g_pMeshTextures0[i]);

			g_pMesh0->DrawSubset(i);
		}

		g_pD3DDevice->EndScene();
	}

	g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
	g_tick++;
}
VOID Render()
{
	if ( NULL == g_pd3dDevice )
	{
		return;
	}

	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
						 D3DCOLOR_XRGB( 30, 10, 10 ), 1.0f, 0 );

	if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		SetupLights();

		SetupMatrices();

		if ( g_Tick )
		{
			g_pd3dDevice->SetTexture( 0, g_pTexture1 );
		}
		else
		{
			g_pd3dDevice->SetTexture( 0, g_pTexture2 );
		}

		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

#ifdef SHOW_HOW_TO_USE_TCI
		D3DXMATRIXA16 mTextureTransform;
		D3DXMATRIXA16 mProj;
		D3DXMATRIXA16 mTrans;
		D3DXMATRIXA16 mScale;

		g_pd3dDevice->GetTransform( D3DTS_PROJECTION , &mProj );
		D3DXMatrixTranslation( &mTrans , 0.5f , 0.5f , 0.0f );
		D3DXMatrixScaling( &mScale , 0.5f , -0.5f , 1.0f );
		mTextureTransform = mProj * mScale * mTrans;

		g_pd3dDevice->SetTransform( D3DTS_TEXTURE0 , &mTextureTransform );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4 | D3DTTFF_PROJECTED );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
#endif
		g_pd3dDevice->SetStreamSource( 0, g_pVB1, 0, sizeof( CUSTOMVERTEX ) );
		g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
		g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2 );

		if ( g_Tick )
		{
			g_pd3dDevice->SetTexture( 0, g_pTexture2 );
		}
		else
		{
			g_pd3dDevice->SetTexture( 0, g_pTexture1 );
		}

		g_pd3dDevice->SetStreamSource( 0, g_pVB2, 0, sizeof( CUSTOMVERTEX ) );
		g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
		g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2 );

		float scale = sinf( static_cast<float>( D3DX_PI * timeGetTime() / 1000 ) ) * 0.8f;
		D3DXMATRIXA16 thisMatrix, prevMatrix;

		g_pd3dDevice->GetTransform( D3DTS_WORLD, &prevMatrix );

		D3DXMATRIXA16 matFirstTiger, matTrans, matRotate;

		D3DXMatrixRotationY( &matRotate, timeGetTime() / 1000.0f );
		D3DXMatrixTranslation( &matTrans, -3.f, 2.0f, 5.0f );
		D3DXMatrixMultiply( &matFirstTiger, &matRotate, &matTrans );
		g_pd3dDevice->SetTransform( D3DTS_WORLD, &matFirstTiger );

		for ( DWORD i = 0; i < g_dwNumMaterials; ++i )
		{
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
			g_pMesh->DrawSubset( i );
		}

		g_pd3dDevice->SetTransform( D3DTS_WORLD, &prevMatrix );

		D3DXMatrixTranslation( &thisMatrix, 3.0f, 2.0f, 5.0f );
		g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix );
		D3DXMatrixScaling( &thisMatrix, -scale + 1.0f, 1.0f, 1.0f );
		g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix );

		for ( DWORD i = 0; i < g_dwNumMaterials; ++i )
		{
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
			g_pMesh->DrawSubset( i );
		}

		g_pd3dDevice->EndScene();
	}

	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
예제 #27
0
void	CObjectRightView::Render()
{
	
	if	(!DirectXStatus) {
		// Clear the backbuffer and the zbuffer
		if( FAILED( g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
										 D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ) ) ) {
			DirectXStatus = -1;
			return;
		}

		// Begin the scene
		if	(SUCCEEDED(g_pd3dDevice->BeginScene()))
		{
			// Setup the lights and materials
			if	(SetupLights()) {
				DirectXStatus = -1;
				return;
			}

			// Setup the world, view, and projection matrices
			if	(SetupMatrices()) {
				DirectXStatus = -1;
				return;
			}


			if	(g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX))) {
				DirectXStatus = -1;
				return;
			}

			g_pd3dDevice->SetVertexShader(NULL);
			g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);


			D3DMATERIAL9	mtrl;
			mtrl.Diffuse.r = mtrl.Ambient.r = mtrl.Specular.r = 0.4f;
			mtrl.Diffuse.g = mtrl.Ambient.g = mtrl.Specular.g = 0.1f;
			mtrl.Diffuse.b = mtrl.Ambient.b = mtrl.Specular.b = 0.7f;
			mtrl.Diffuse.a = mtrl.Ambient.a = mtrl.Specular.a = 1.0f;
			mtrl.Emissive.r = 0.1f;
			mtrl.Emissive.g = 0.4f;
			mtrl.Emissive.b = 0.02f;
			mtrl.Emissive.a = 0.5f;

			g_pd3dDevice->SetMaterial(&mtrl);

			STRUCT_INSTANCES	* instance = first_instance;
			while  (instance) {
				if	( (instance->parent)  &&
					  (instance->select == ITEM_CHECKED) ){
					g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, instance->startIndex, instance->primitiveCount);  
				}

				instance = instance->next;
			}

			// End the scene
			if( FAILED( g_pd3dDevice->EndScene() ) ) {
				DirectXStatus = -1;
				return;
			}
		}

		// Present the backbuffer contents to the display
		if( FAILED( g_pd3dDevice->Present( NULL, NULL, NULL, NULL ) ) ) {
			DirectXStatus = -1;
			return;
		}
		
	}
	
}
예제 #28
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    // Clear the backbuffer and the zbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                         D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );

    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
		SetupCameraMatrices();
		SetupLights((timeGetTime() / 1000) % 2);

		SetupCylinderMatrices();
		
		int TextureIndex = (timeGetTime() / 1000) % 2;

		g_pd3dDevice->SetTexture(0, g_pTexture[TextureIndex]);
		g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
		g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
		g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

#ifdef SHOW_HOW_TO_USE_TCI
		D3DXMATRIXA16 mTextureTransform;
		D3DXMATRIXA16 mProj;
		D3DXMATRIXA16 mTrans;
		D3DXMATRIXA16 mScale;

		g_pd3dDevice->GetTransform(D3DTS_PROJECTION, &mProj);
		D3DXMatrixTranslation(&mTrans, 0.5f, 0.5f, 0.0f);
		D3DXMatrixScaling(&mScale, 0.5f, -0.5f, 1.0f);
		mTextureTransform = mProj * mScale * mTrans;

		g_pd3dDevice->SetTransform(D3DTS_TEXTURE0, &mTextureTransform);
		g_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4 | D3DTTFF_PROJECTED);
		g_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);
#endif

		g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX));
		g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
		g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2);

        // Meshes are divided into subsets, one for each material. Render them in
        // a loop
		for (int loop = 0; loop < MESH_COUNT; ++loop)
		{
			// Setup the world, view, and projection matrices
			SetupMeshesMatrices(loop);

			for (DWORD i = 0; i < g_dwNumMaterials[loop]; i++)
			{
				// Set the material and texture for this subset
				g_pd3dDevice->SetMaterial(&g_pMeshMaterials[loop][i]);
				g_pd3dDevice->SetTexture(0, g_pMeshTextures[loop][i]);

				// Draw the mesh subset
				g_pMesh[loop]->DrawSubset(0);
			}
		}
		
        
        // End the scene
        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
예제 #29
0
void Draw( double t )
{
    double xpos, ypos, zpos, angle_x, angle_y, angle_z;
    static double t_old = 0.0;
    float  dt;

    // Calculate frame-to-frame delta time
    dt = (float)(t-t_old);
    t_old = t;

    // Setup viewport
    glViewport( 0, 0, width, height );

    // Clear color and Z-buffer
    glClearColor( 0.1f, 0.1f, 0.1f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Setup projection
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 65.0, (double)width/(double)height, 1.0, 60.0 );

    // Setup camera
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    // Rotate camera
    angle_x = 90.0 - 10.0;
    angle_y = 10.0 * sin( 0.3 * t );
    angle_z = 10.0 * t;
    glRotated( -angle_x, 1.0, 0.0, 0.0 );
    glRotated( -angle_y, 0.0, 1.0, 0.0 );
    glRotated( -angle_z, 0.0, 0.0, 1.0 );

    // Translate camera
    xpos =  15.0 * sin( (M_PI/180.0) * angle_z ) +
             2.0 * sin( (M_PI/180.0) * 3.1 * t );
    ypos = -15.0 * cos( (M_PI/180.0) * angle_z ) +
             2.0 * cos( (M_PI/180.0) * 2.9 * t );
    zpos = 4.0 + 2.0 * cos( (M_PI/180.0) * 4.9 * t );
    glTranslated( -xpos, -ypos, -zpos );

    // Enable face culling
    glFrontFace( GL_CCW );
    glCullFace( GL_BACK );
    glEnable( GL_CULL_FACE );

    // Enable lighting
    SetupLights();
    glEnable( GL_LIGHTING );

    // Enable fog (dim details far away)
    glEnable( GL_FOG );
    glFogi( GL_FOG_MODE, GL_EXP );
    glFogf( GL_FOG_DENSITY, 0.05f );
    glFogfv( GL_FOG_COLOR, fog_color );

    // Draw floor
    DrawFloor();

    // Enable Z-buffering
    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LEQUAL );
    glDepthMask( GL_TRUE );

    // Draw fountain
    DrawFountain();

    // Disable fog & lighting
    glDisable( GL_LIGHTING );
    glDisable( GL_FOG );

    // Draw all particles (must be drawn after all solid objects have been
    // drawn!)
    DrawParticles( t, dt );

    // Z-buffer not needed anymore
    glDisable( GL_DEPTH_TEST );
}