void GLCanvas::display(void) {
	glDrawBuffer(GL_BACK);

	Vec3f bg = mesh->background_color;
	// Clear the display buffer, set it to the background color
	glClearColor(bg.r(),bg.g(),bg.b(),0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Set the camera parameters
	mesh->camera->glInit(args->width, args->height);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	mesh->camera->glPlaceCamera();
	InitLight(); // light will be a headlamp!

	if (args->intersect_backfacing)
		glDisable(GL_CULL_FACE);
	else
		glEnable(GL_CULL_FACE);

	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);
	
	//	glCallList(display_list_index);
	HandleGLError(); 

	radiosity->drawVBOs();
	photon_mapping->drawVBOs();
	RayTree::drawVBOs();
	 
	// Swap the back buffer with the front buffer to display
	// the scene
	glutSwapBuffers();
}
Example #2
0
void SGFixedGLState::Init()
{
    for(int i=0; i< NUM_LIGHTS; i++)
    {
        InitLight(i);
    }

    for(int i=0; i<NUM_LIGHTS_ENABLED_AT_START; i++)
    {
        m_light[i]->lightEnabled = true;
    }

    for(int i=0; i<NUM_TEXTURES; i++)
    {
        InitTexture(i);
    }

    InitMaterial();
    InitFog();

    SetLightingEnable(true);
    SetFogEnable(false);
    SetSeparateSpecularColorEnable(false);
    Set2SidedLightingEnable(false);
    
    SetTextureEnable(false);
    SetNormalizeEnable(true);

    m_changeFog = m_changeLight = m_changeMat = m_changeTexture = true;
}
Example #3
0
/*******************************************************************************
関数名:	void InitGame(void)
引数:	なし
戻り値:	なし
説明:	ゲームの初期化処理
*******************************************************************************/
void InitGame(void)
{
	//ゲームモードの初期化
	SetGameStep(STEP_PLAY);

	//stageの初期化
	SetStageMode(STAGE0);

	// ライトの初期化
	InitLight();

	//dome
	InitMeshDome( D3DXVECTOR3( 0, 0, 0), D3DXVECTOR3( 0, 0, 0), 1500.0f, 32, 32);

	//UI
	InitTime();
	InitClock(D3DXVECTOR3(SCREEN_WIDTH/2 + 100, 70, 0));
	InitGunSight();
	InitNumLife();
	InitEnemyNum();
	
	//Model
	InitStageManager(true, INI_NUM_LIFE);
	//InitModel();

	//グローバル変数の初期化
	g_nCounterFrame = 0;
	g_nCounterShoot = 0;
	g_nCounterEShoot = 0;
	g_fTimeSpeed = 0.01f;
	g_bNeedRseet = false;
	g_bGameClear = false;
}
Example #4
0
int main(int argc, char *argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(400, 400);
	glutInitWindowPosition(0, 0);
	
	glutCreateWindow("p296 code6-8");
	glClearColor(0.4, 0.4, 0.4, 0.0);
	InitLight();

	glutDisplayFunc(MyDisplay);
	glutReshapeFunc(MyReshape);
	glutMainLoop();
	
	return 0;
}
SuperSolarSystemApp::SuperSolarSystemApp( HINSTANCE hInstance )
	:
	D3dBase( hInstance ),
	mLightTexIB( 0 ),
	mLightTexVB( 0 ),
	mColorIB( 0 ),
	mColorVB( 0 ),
	mCamera( 1.5f*MathHelper::Pi, 0.5f*MathHelper::Pi, 200.0f )
{
	mEnable4xMsaa = false;

	// 默认照相机方向
	mCamera.LookAt(
		XMFLOAT3( -200.0f, 0.0f, 10.0f )
		/*XMFLOAT3(-150.0f, 50.0f, -50.0f)*/,
		XMFLOAT3( 0.0f, 0.0f, 0.0f ),
		XMFLOAT3( 0.0f, 1.0f, 0.0f ) );

	BuildCubeFaceCamera( 0.0f, 0.0f, 0.0f );

	InitLight( );
	InitStarInformation( );
}
bool OGLSpotLight::Init(int windowWidth, int windowHeight)
{
    bool res = gs::Stage::Init(windowWidth, windowHeight);
    if (!res) {
        return false;
    }

    cubePositions.resize(10);

    res &= InitGUI();

    // Init Camera
    camera.SetPosition(glm::vec3(0, 0, 50));
    camera.SetSpeed(15.0f);
    camera.SetupProjection(45.0f, windowWidth / (float)windowHeight);

    // Init light
    InitLight();

    // Init materials
    InitCubePosition();

    // Init program
    res &= AddProgram("mesh.vert", "spotLight.frag");
    auto program = programs[0];

    // Get uniform locations
    res &= AddLightUniform(program.get());
    res &= AddMatricesUniform(program.get());
    res &= program->AddUniform("material.shininess");
    res &= program->AddUniform("samplerDiffuse1");
    program->AddUniform("samplerDiffuse2");
    program->AddUniform("samplerDiffuse3");
    program->AddUniform("samplerSpecular1");
    program->AddUniform("samplerSpecular2");

    glUniform1i(program->GetUniform("samplerDiffuse1"), 0);
    glUniform1i(program->GetUniform("samplerDiffuse2"), 1);
    glUniform1i(program->GetUniform("samplerDiffuse3"), 2);
    glUniform1i(program->GetUniform("samplerSpecular1"), 3);
    glUniform1i(program->GetUniform("samplerSpecular2"), 4);

    // Init geometry
    auto vao = std::make_unique<gs::VertexArray>();
    vao->BindVAO();

    auto vbo = std::make_unique<gs::VertexBuffer>(GL_ARRAY_BUFFER);
    vbo->BindVBO();
    OGLCube cube;
    auto& vertices = cube.GetVertices();
    cube.InitVertices(glm::vec3(0));
    glBufferData(vbo->GetTarget(), sizeof(gs::Vertex) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
    vbos.push_back(std::move(vbo));

    vao->AddAttribute(0, 3, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), 0);
    vao->AddAttribute(1, 2, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), (void*)offsetof(gs::Vertex, texCoords));
    vao->AddAttribute(2, 3, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), (void*)offsetof(gs::Vertex, normal));
    vaos.push_back(std::move(vao));

    auto diffuse = std::make_unique<gs::Texture>(IMAGE_TYPE::GLI);
    diffuse->SetContribution(LIGHT_CONTRIBUTION::DIFFUSE);
    res &= diffuse->LoadTexture("containerDiffuse.dds");
    diffuse->BindTexture(GL_TEXTURE0);
    textures.push_back(std::move(diffuse));

    auto specular = std::make_unique<gs::Texture>(IMAGE_TYPE::GLI);
    specular->SetContribution(LIGHT_CONTRIBUTION::DIFFUSE);
    res &= specular->LoadTexture("containerSpecular.dds");
    specular->BindTexture(GL_TEXTURE3);
    textures.push_back(std::move(specular));

    glEnable(GL_DEPTH_TEST);
    res = true;
    return res;
}
Example #7
0
//——————————————————————
// Direct3D初期化
//——————————————————————
HRESULT Game::InitD3d(HWND hWnd)
{
	// 「Direct3D」オブジェクトの作成
	if (NULL == (pD3d = Direct3DCreate9(D3D_SDK_VERSION)))
	{
		//メッセージボックスが出るとエラーが分かりやすい
		MessageBox(0, "Direct3Dの作成に失敗しました", "", MB_OK);
		return E_FAIL;
	}
	
	// 「DIRECT3Dデバイス」オブジェクトの作成
	D3DPRESENT_PARAMETERS d3dpp;

	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferFormat =		D3DFMT_UNKNOWN;
	d3dpp.BackBufferCount =			1;
	d3dpp.SwapEffect =				D3DSWAPEFFECT_DISCARD;
	d3dpp.Windowed =				TRUE;					//開発中はTRUE、完成したらFALSEにする
	d3dpp.EnableAutoDepthStencil =	TRUE;					//やるかやらないか、FALSEにすると前後感覚が無くなる
	d3dpp.AutoDepthStencilFormat =	D3DFMT_D16;				//16ビットにあわせてる

	if (FAILED(pD3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pDevice)))
	{
		MessageBox(0, "HALモードでDIRECT3Dデバイスを作成できません\nREFモードで再試行します", NULL, MB_OK);

		if (FAILED(pD3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd,
			D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pDevice)))
		{
			MessageBox(0, "DIRECT3Dデバイスの作成に失敗しました", NULL, MB_OK);

			return E_FAIL;
		}
	}

	//ライトの設定(影)の設定、正しく使わないと黒にしかならない。
	//今のところ特に使わないのでライトは切っておく
	/*if (FAILED(g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE)))
	{
		MessageBox(0, "ライトの設定に失敗しました", "エラー", MB_OK);
		return E_FAIL;
	}*/

	//新しいライトの設定する関数を呼ぶ。
	if (FAILED(InitLight()))
	{
		return E_FAIL;
	}
	

	//カリングしていると裏を向いたポリゴンは描画されなくなる
	//裏面を表示したい場合はカリングモードをしないに設定する
	/*if (FAILED(g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE)))
	{
		MessageBox(0, "カリングモードの設定に失敗しました", "エラー", MB_OK);
		return E_FAIL;
	}*/

	//透明化処理の設定を行う、アルファは透過する値を表している
	//SetRenderState関数を使って透明なところは透明にすることができる
	if (FAILED(g_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE) ||
		g_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA) ||
		g_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)))
	{
		MessageBox(0, "アルファブレンドの設定に失敗しました", "エラー", MB_OK);
		return E_FAIL;
	}
	/*
	今回はSetRenderState関数を3回呼ぶ必要がある。
	1つ目は「アルファブレンドを有効にする」という設定で、あとの2つが「半透明部分の表示のしかた」になる。
	*/


	//テクスチャ行列は、貼り付けたテクスチャの大きさを決める為に必要な行列。
	if (FAILED(g_pDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2)))
	{
		MessageBox(0, "テクスチャステートの設定に失敗しました", "エラー", MB_OK);
		return E_FAIL;
	}

	
	return S_OK;
}
Example #8
0
//——————————————————————
// Direct3D初期化
//——————————————————————
HRESULT Game::InitD3d(HWND hWnd)
{
   // 「Direct3D」オブジェクトの作成
   if (NULL == (pD3d = Direct3DCreate9(D3D_SDK_VERSION)))
   {
      MessageBox(0, "Direct3Dの作成に失敗しました", "", MB_OK);
      return E_FAIL;
   }

   // 「DIRECT3Dデバイス」オブジェクトの作成
   D3DPRESENT_PARAMETERS d3dpp;
   ZeroMemory(&d3dpp, sizeof(d3dpp));
   d3dpp.BackBufferFormat =			D3DFMT_UNKNOWN;
   d3dpp.BackBufferCount =			1;
   d3dpp.SwapEffect =				D3DSWAPEFFECT_DISCARD;
   d3dpp.Windowed =					TRUE;
   d3dpp.EnableAutoDepthStencil =	TRUE;
   d3dpp.AutoDepthStencilFormat =	D3DFMT_D16;
 
   if (FAILED(pD3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
	   D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pDevice)))
   {
	   MessageBox(0, "HALモードでDIRECT3Dデバイスを作成できません\nREFモードで再試行します", NULL, MB_OK);

	   if (FAILED(pD3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd,
		   D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pDevice)))
	   {
		   MessageBox(0, "DIRECT3Dデバイスの作成に失敗しました", NULL, MB_OK);
		   return E_FAIL;
	   }
   }

   //if (FAILED(g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE)))
   //{
	  // MessageBox(0, "ライトの設定に失敗しました", "エラー", MB_OK);
	  // return E_FAIL;
   //}

   if (FAILED(g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE)))
   {
	   MessageBox(0, "カリングモードの設定に失敗しました", "エラー", MB_OK);
	   return E_FAIL;
   }

   if (FAILED(g_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE) ||
	   g_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA) ||
	   g_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)))
   {
	   MessageBox(0, "アルファブレンドの設定に失敗しました", "エラー", MB_OK);
	   return E_FAIL;
   }

   if (FAILED(g_pDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2)))
   {
	   MessageBox(0, "テクスチャステートの設定に失敗しました", "エラー", MB_OK);
	   return E_FAIL;
   }

   if (FAILED(InitLight()))
   {
	   return E_FAIL;
   }

   return S_OK;
}
/*******************************************************************************
 * Function Name  : InitView
 * Inputs		  : uWidth, uHeight
 * Returns        : true if no error occured
 * Description    : Code in InitView() will be called by the Shell upon a change
 *					in the rendering context.
 *					Used to initialize variables that are dependant on the rendering
 *					context (e.g. textures, vertex buffers, etc.)
 *******************************************************************************/
bool OGLESLighting::InitView()
{
	CPVRTString ErrorStr;
	SPVRTContext sContext;
	PVRTMat4	mProjection;
	int			i;

	// Is the screen rotated?
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	// Initialize Print3D textures
	if(m_Print3D.SetTextures(&sContext, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	// Load textures
	if(!LoadTextures(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	//	Initialize VBO data
	LoadVbos();

	// Setup all materials
	float Ambient[]	= {0.1f, 0.1f, 0.1f, 1.0f};
	float Diffuse[]	= {0.5f, 0.5f, 0.5f, 1.0f};
	float Specular[]= {1.0f, 1.0f, 1.0f, 1.0f};

	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);	// Nice and shiny so we don't get aliasing from the 1/2 angle

	// Initialize all lights
	srand(0);

	for(i = 0; i < 8; ++i)
		InitLight(m_psLightData[i]);

	// Perspective matrix
	
	// Calculate the projection matrix
	mProjection = PVRTMat4::PerspectiveFovRH(20.0f*(PVRT_PIf/180.0f), (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), 10.0f, 1200.0f, PVRTMat4::OGL, bRotate);

	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(mProjection.f);

	// Modelview matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glTranslatef(0.0f, 0.0f, -500.0f);

	// Setup culling
	glEnable(GL_CULL_FACE);

	// Enable texturing
	glEnable(GL_TEXTURE_2D);

	/*
		Build an array to map the textures within the pod file
		to the textures we loaded earlier.
	*/

	m_pui32Textures = new GLuint[m_Scene.nNumMaterial];

	for(i = 0; i < (int) m_Scene.nNumMaterial; ++i)
	{
		m_pui32Textures[i] = 0;
		SPODMaterial* pMaterial = &m_Scene.pMaterial[i];

		if(!strcmp(pMaterial->pszName, "Stone"))
			m_pui32Textures[i] = m_ui32Stone;
	}

	// Set the clear colour
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	return true;
}
Example #10
0
HRESULT InitD3D( HWND hWnd )
{
	RECT rc;
    GetClientRect(hWnd, &rc);
    UINT width = rc.right - rc.left;
    UINT height = rc.bottom - rc.top;

	// Setup a DXGI swap chain descriptor
	DXGI_SWAP_CHAIN_DESC sd;
	ZeroMemory( &sd, sizeof( sd ) );

	sd.BufferCount = 1; // number of buffer
	sd.BufferDesc.Width = width; // buffer width, can we set it to the screen width?
	sd.BufferDesc.Height = height; // buffer height, can we set it to the screen height?
	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // buffer format, 32 bit color with alpha(RGBA)
	sd.BufferDesc.RefreshRate.Numerator = 60; // refresh rate?
	sd.BufferDesc.RefreshRate.Denominator = 1; // WHAT'S THIS?
	sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // use buffer as render target
	sd.OutputWindow = hWnd; // output window handle
	sd.SampleDesc.Count = 1; // WHAT'S THIS?
	sd.SampleDesc.Quality = 0; // WHAT'S THIS?
	sd.Windowed = TRUE; // full-screen mode

	// Create device and swap chain
	HRESULT hr;
	if (FAILED (hr = D3D10CreateDeviceAndSwapChain( NULL, 
	    D3D10_DRIVER_TYPE_HARDWARE,
		NULL,
		0,
		D3D10_SDK_VERSION,
		&sd, 
		&g_pSwapChain,
		&g_pd3dDevice)))
	{
		return hr;
	}

	// Create render target and bind the back-buffer
	ID3D10Texture2D* pBackBuffer;

	// Get a pointer to the back buffer
	hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID* )&pBackBuffer);
	if (FAILED(hr))
		return hr;

	// Create a render-target view
	g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView);

	// Bind the view
	g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetView, NULL); // WHAT'S OM here mean?

	// Setup the viewport
	D3D10_VIEWPORT vp;
	vp.Width = width; // this should be similar with the back-buffer width, global it!
	vp.Height = height;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	g_pd3dDevice->RSSetViewports(1, &vp);

	// Create sphere
	DXUTCreateSphere(g_pd3dDevice, 2.0f, 20, 20, &g_pSphere);	

	InitWorldViewProjMatrix(hWnd);
	InitLight();
	InitEffects();
	InitRasterState();
		                       
	return S_OK;
}