Example #1
0
File: main.c Project: CDragu/pspsdk
void setupGu(void)
{
	sceGuInit();

	sceGuStart(GU_DIRECT, list);
	sceGuDrawBuffer(GU_PSM_8888, 0, BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000, BUF_WIDTH);

	sceGuOffset(0, 0);

	sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);

	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuEnable(GU_BLEND);

	//sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
	//sceGuTexFilter(GU_LINEAR_MIPMAP_LINEAR, GU_NEAREST);
	//sceGuTexWrap(GU_REPEAT, GU_REPEAT);

	sceGuClearColor(0);
	sceGuClearDepth(0);
	sceGuClearStencil(0);

	sceGuFinish();
	sceGuSync(0, 0);
	
	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
}
void StartUpDisplay()
{
	//ScePspFVector3	vec;

	_rotationSpeed = 1.0f;
	_rotation.x = 0.0f;
	_rotation.y = 0.0f;
	_rotation.z = 0.0f;
	_bgColour = 0;
	_frame = 0;
	_viewMode = 0;
	sceGuInit();
	sceGuStart(SCEGU_IMMEDIATE, (void *)disp_list, sizeof(disp_list));

	sceGuDrawBuffer(SCEGU_PF5551, SCEGU_VRAM_BP_0, SCEGU_VRAM_WIDTH);
	sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, SCEGU_VRAM_BP_1,
		SCEGU_VRAM_WIDTH);
	sceGuDepthBuffer(SCEGU_VRAM_BP_2, SCEGU_VRAM_WIDTH);

	sceGuOffset(SCEGU_SCR_OFFSETX, SCEGU_SCR_OFFSETY);
	sceGuViewport(2048, 2048, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuDepthRange(50000, 10000);

	sceGuDisable(SCEGU_BLEND);

	sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuEnable(SCEGU_SCISSOR_TEST);

	sceGuDepthFunc(SCEGU_GEQUAL);
	sceGuEnable(SCEGU_DEPTH_TEST);

	sceGuFrontFace(SCEGU_CW);

	sceGuDisable(SCEGU_TEXTURE);
	sceGuShadeModel(SCEGU_SMOOTH);

	sceGuEnable(SCEGU_DITHER);

	//vec.x = 0.0f;
	//vec.y = 0.0f;
	//vec.z = 1.0f;
	//sceGuLightColor(0, SCEGU_DIFFUSE, 0xffffffff);
	//sceGuLight(0, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//vec.x = 1.0f;
	//vec.y = 0.0f;
	//vec.z = 0.0f;
	//sceGuLightColor(1, SCEGU_DIFFUSE, 0xff00ffff);
	//sceGuLight(1, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//vec.x = -1.0f;
	//vec.y = 0.0f;
	//vec.z = 0.0f;
	//sceGuLightColor(2, SCEGU_DIFFUSE, 0xffff00ff);
	//sceGuLight(2, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//sceGuEnable(SCEGU_LIGHT0);
	//sceGuEnable(SCEGU_LIGHT1);
	//sceGuEnable(SCEGU_LIGHT2);
	//sceGuEnable(SCEGU_LIGHTING);

	//sceGuFog(14.50, 25.0, 0x007f00ff);

	//sceGuAmbient(0xcc004cb2);
	sceGuAmbient(0xffffffff);
	sceGuColor(0xff0000ff);

	//sceGuTexMode(SCEGU_PF5551, 1, SCEGU_SINGLE_CLUT, SCEGU_TEXBUF_NORMAL);
	//sceGuTexFilter(SCEGU_LINEAR_MIPMAP_NEAREST, SCEGU_LINEAR);
	//sceGuTexFunc(SCEGU_TEX_MODULATE, SCEGU_RGB);
	//sceGuTexWrap(SCEGU_REPEAT, SCEGU_REPEAT);

	sceGumSetMatrixStack(matrix_stack, 1, 1, 2, 0);
	sceGumMatrixMode(SCEGU_MATRIX_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(SCEGU_RAD(45.0f), SCEGU_SCR_ASPECT,
		1.000000f, 100.000000f);

	sceGumMatrixMode(SCEGU_MATRIX_WORLD);

	sceGuClearDepth(0);
	sceGuClearStencil(0);

	sceGuFinish();
	sceGuSync(SCEGU_SYNC_FINISH, SCEGU_SYNC_WAIT);

	sceGuDisplay(SCEGU_DISPLAY_ON);
}
void FrontEnd::StartUpDisplay(void)
#endif
{
#ifdef PC
	UNREFERENCED_PARAMETER( hInst );

	// register window class
	WNDCLASSEX wc = 
	{
		sizeof( WNDCLASSEX ), CS_CLASSDC, MainWndProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
		L"Cross-Platform Development", NULL
	};
	wc.hInstance = hInst;
	_wc = wc;
	if( !RegisterClassEx( &wc ) )
	{
		MessageBox( 0, L"Failed to Register Class", 0, 0 );
		PostQuitMessage( 0 );
	}

	// create the window
	_d3dParameters.BackBufferHeight = 272;
	_d3dParameters.BackBufferWidth = 480;
	HWND hWnd = CreateWindow( L"Cross-Platform Development", L"Cross-Platform Development", WS_OVERLAPPEDWINDOW, 100, 100, 
		_d3dParameters.BackBufferWidth, _d3dParameters.BackBufferHeight, NULL, NULL, wc.hInstance, NULL );

	// check if the hWnd has been created
	if( !hWnd )
	{
		MessageBox( 0, L"Failed to Create Window", 0, 0 );
		PostQuitMessage( 0 );
	}

	/* Create the device */
	if ( NULL == ( _pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		MessageBox( 0, L"DirectX SDK Version Wrong", 0, 0 );
		PostQuitMessage( 0 );
	}

	// set up the structure used to create the D3DDevice
	int height = _d3dParameters.BackBufferHeight;
	int width = _d3dParameters.BackBufferWidth;
	ZeroMemory( &_d3dParameters, sizeof( _d3dParameters ) );
	_d3dParameters.Windowed = TRUE;
	_d3dParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
	_d3dParameters.BackBufferFormat = D3DFMT_UNKNOWN;
	_d3dParameters.BackBufferHeight = height;
	_d3dParameters.BackBufferWidth = width;
	_d3dParameters.EnableAutoDepthStencil = TRUE;		/* Allow directX to create and manage a z buffer for me */
	_d3dParameters.AutoDepthStencilFormat = D3DFMT_D16;	/* Use the 16bit format */

	// create D3DDevice
	if ( FAILED( _pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING, &_d3dParameters, &_pd3dDevice ) ) )
	{
		if ( FAILED( _pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING, &_d3dParameters, &_pd3dDevice ) ) )
		{
			MessageBox( 0, L"This machine cannot process vertices", 0, 0 );
			PostQuitMessage( 0 );
		}
	}

	// set up some default render modes
	_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );		/*< Solid fill rendering */
	_pd3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT );		/*< Default shading */
	_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );		/*< Culling off */ 
	_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );				/*< Lighting on */ 
	_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255) );
	_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );			/*< Turn on z buffering */
	_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );			/*< Allow writing to the z buffer */
	_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL );		/*< Render each pixel if it's less than or equal to an existing pixel */

	ShowWindow( hWnd, UpdateWindow( hWnd ) );

	/* Set up the vertex buffer for rendering */
	Vertex* vertexBuffer = false;
	if( SUCCEEDED( _pd3dDevice->CreateVertexBuffer( 36 * sizeof( D3DFVF_Vertex ), 0, 
		D3DFVF_XYZ, D3DPOOL_DEFAULT, &_vertexBuffer, NULL ) ) )
	{
		if( SUCCEEDED( _vertexBuffer->Lock( 0, 36 * sizeof( D3DFVF_Vertex ), (void**)&vertexBuffer, 0 ) ) )
		{	
			for( DWORD i = 0; i < 36; ++i )
			{
				vertexBuffer[i].x = Cube[i].x;
				vertexBuffer[i].y = Cube[i].y;
				vertexBuffer[i].z = Cube[i].z;
			}

			_vertexBuffer->Unlock();

			/* Apply a material for lighting to work */
			D3DMATERIAL9 material;
			ZeroMemory( &material, sizeof( material ) );
			material.Diffuse.r = material.Ambient.r = 1.0f;
			material.Diffuse.g = material.Ambient.g = 1.0f;
			material.Diffuse.b = material.Ambient.b = 1.0f;
			material.Diffuse.a = material.Ambient.a = 1.0f;

			_pd3dDevice->SetMaterial( &material );
			_pd3dDevice->SetStreamSource( 0, _vertexBuffer, 0, sizeof(D3DFVF_Vertex) );
			_pd3dDevice->SetFVF( D3DFVF_XYZ );
		}
	}
#else
	_rotationSpeed = 1.0f;
	_rotation.x = 0.0f;
	_rotation.y = 0.0f;
	_rotation.z = 0.0f;
	_frame = 0;
	_viewMode = -1;
	sceGuInit();
	sceGuStart(SCEGU_IMMEDIATE, (void*)_displist, sizeof(_displist));

	sceGuDrawBuffer(SCEGU_PF5551, SCEGU_VRAM_BP_0, SCEGU_VRAM_WIDTH);
	sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, SCEGU_VRAM_BP_1,
		SCEGU_VRAM_WIDTH);
	sceGuDepthBuffer(SCEGU_VRAM_BP_2, SCEGU_VRAM_WIDTH);

	sceGuOffset(SCEGU_SCR_OFFSETX, SCEGU_SCR_OFFSETY);
	sceGuViewport(2048, 2048, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuDepthRange(50000, 10000);

	sceGuDisable(SCEGU_BLEND);

	sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuEnable(SCEGU_SCISSOR_TEST);

	sceGuDepthFunc(SCEGU_GEQUAL);
	sceGuEnable(SCEGU_DEPTH_TEST);

	sceGuFrontFace(SCEGU_CW);

	sceGuDisable(SCEGU_TEXTURE);
	sceGuShadeModel(SCEGU_SMOOTH);

	sceGuEnable(SCEGU_DITHER);

	sceGumSetMatrixStack(_matrixStack, 1, 1, 2, 0);
	sceGumMatrixMode(SCEGU_MATRIX_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(DEGSTORADS(45.0f), SCEGU_SCR_ASPECT,
		1.000000f, 100.000000f);

	sceGumMatrixMode(SCEGU_MATRIX_WORLD);

	sceGuClearDepth(0);
	sceGuClearStencil(0);

	sceGuFinish();
	sceGuSync(SCEGU_SYNC_FINISH, SCEGU_SYNC_WAIT);

	sceGuDisplay(SCEGU_DISPLAY_ON);
#endif
}