Esempio n. 1
0
/*************************************************************************
 GameMain()

 The work of the application is done here. This is called every frame.
*************************************************************************/
bool GameMain(float elapsedTime)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  gluLookAt(2.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

  DrawLight(elapsedTime);
  DrawFloor(elapsedTime);
  return true;
} // end GameMain()
Esempio n. 2
0
void Render()
{
	float alpha = GetTickCount()/10.0f;

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glColor3f(1,1,1);
	DrawLight();
	DrawGround();
	DrawCylinder(alpha, true);
	DrawCylinder(alpha, false);

}
Esempio n. 3
0
void StreetLight::Display() {
	glPushMatrix();
	glPushAttrib(GL_ALL_ATTRIB_BITS);

	glTranslatef(pos[0], pos[1], pos[2]);
	glScalef(scale[0], scale[1], scale[2]);
	glRotatef(rotation[1], 0.f, 1.f, 0.f);
	glRotatef(rotation[0], 1.f, 0.f, 0.f);
	glRotatef(rotation[2], 0.f, 0.f, 1.f);

	DrawLight();

	glPopAttrib();
	glPopMatrix();
}
Esempio n. 4
0
void NLight::Draw(NCamera* View)
{
    //If the light isn't on the current level of the map, don't draw it! This is required because 2d lighting!
    if (GetGame()->GetMap()->GetLevel() != GetGame()->GetMap()->GetLevel(GetRealPos()))
    {
        return;
    }
    //Clear out the stencil buffer with 0's so we have a clean slate to work with.
    glClear(GL_STENCIL_BUFFER_BIT);
    glEnable(GL_STENCIL_TEST);
    //Make it so whatever we draw replaces everything it touches in the stencil to 1.
    glStencilFunc(GL_ALWAYS,0x1,0x1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
    //Draw all our shadow volumes.
    DrawShadow(View);
    //Now we make it so we can only draw on 0's, we also don't want to replace anything in the stencil buffer so we lock it up.
    glStencilFunc(GL_EQUAL,0x0,0x1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    //Finally draw the light into whatever's not shadow.
    DrawLight(View);
    glDisable(GL_STENCIL_TEST);
}
Esempio n. 5
0
	void PrelightPipeline::Execute(const std::shared_ptr<SceneManager> &sceneManager)
	{
		// pre
		m_DrawCall = 0;
		m_CurrentCamera = nullptr;
		m_CurrentShader = nullptr;
		SortPassByIndex();

		// find visible nodes, 1 cam 1 query
		std::unordered_map<std::string, RenderQuery::Ptr> queries;

		for (auto pair : m_PassMap)
		{
			auto pass = pair.second;
			auto camNode = pass->GetCameraNode();

			if (camNode == nullptr)
			{
				LOGW << "Camera for pass " + pass->GetName() + " not found!";
				continue;
			}

			auto it = queries.find(camNode->GetName());
			if (it != queries.end())
				continue;

			RenderQuery::Ptr query = RenderQuery::Create();

			sceneManager->GetRenderQuery(camNode->GetComponent<Camera>()->GetFrustum(), query);
			query->Sort(camNode->GetWorldPosition(), false);

			queries.emplace(camNode->GetName(), query);
		}

		// draw passes

		for (unsigned int i = 0; i < m_SortedPasses.size(); i++)
		{
			auto passName = m_SortedPasses[i];
			auto pass = m_PassMap[passName];

			auto drawMode = pass->GetDrawMode();

			m_CurrentCamera = pass->GetCameraNode();
			m_CurrentShader = pass->GetFirstShader();

			if (m_CurrentCamera == nullptr)
				continue;

			auto query = queries[m_CurrentCamera->GetName()];

			pass->Bind();

			if (drawMode == DrawMode::RENDERABLE)
			{
				for (const auto &node : query->OpaqueNodes)
					DrawRenderable(pass, node);
			}
			else if (drawMode == DrawMode::LIGHT)
			{
				glDepthMask(GL_FALSE);

				for (const auto &node : query->LightNodes)
					DrawLight(pass, node);

				glDepthMask(GL_TRUE);
				glEnable(GL_DEPTH_TEST);
				glCullFace(GL_BACK);
			}
			else 
			{
				DrawQuad(pass);
			}

			pass->UnBind();
		}

		// post
		m_CurrentCamera = nullptr;
		m_CurrentShader = nullptr;
	}
Esempio n. 6
0
void EditorViewWindow::DrawScene ()
{
	glEnable (GL_DEPTH_TEST);

	// setup the view matrix
	Matrix tr;
	GetViewMatrix (cam.mat);
	cam.mat.transpose (&tr);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf ((const float*)&tr);

	if (!bHideGrid)
		DrawGrid ();
	
	if (bLockLightToCam)
		lightPos = cam.GetOrigin();

	if(bLighting && !bLockLightToCam)
		DrawLight();

	// Clear the modelview matrix so the light is not transformed
//	glLoadIdentity ();

	if (bCullFaces) {
		if (mode==MAP_3D)
			glFrontFace (GL_CW);
		else
			glFrontFace (GL_CCW);
		glEnable (GL_CULL_FACE);
	}

	glEnable (GL_DEPTH_TEST);

	if(rendermode==M3D_WIRE)
		glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
	else
		glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);

	if (bLighting) {
		glEnable (GL_LIGHTING);
		glEnable (GL_LIGHT0);
		float pos[4]={lightPos.x, lightPos.y, lightPos.z,1.0f};
		glLightfv (GL_LIGHT0, GL_POSITION, pos);
		float diffuse[]={1,1,1,1};
		glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
		float specular[]={0.5f,0.5f,0.5f,0.0f};
		glLightfv (GL_LIGHT0, GL_SPECULAR, specular);
		//glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE);
		//const float params[] = { 0.3f, 0.3f, 0.3f, 1.0f };
		//glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, params);
		//glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, specular);
		//glEnable (GL_COLOR_MATERIAL);
	} else {
		glDisable (GL_LIGHTING);
		glDisable (GL_COLOR_MATERIAL);
	}

	// Load the modelview transform again
	glLoadMatrixf ((const float*)&tr);

	glColor3ub (255,255,255);
	editor->RenderScene (this);

	glDisable (GL_LIGHT0);
	glDisable (GL_LIGHTING);
	glDisable (GL_COLOR_MATERIAL);
	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
	glDisable (GL_DEPTH_TEST);
	glDisable (GL_CULL_FACE);
}
/*******************************************************************************
 * Function Name  : RenderScene
 * Returns		  : true if no error occured
 * Description    : Main rendering loop function of the program. The shell will
 *					call this function every frame.
 *******************************************************************************/
bool OGLESLighting::RenderScene()
{
	unsigned int i;
	PVRTMat4 RotationMatrix;

	// Clear the buffers
	glEnable(GL_DEPTH_TEST);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Lighting

	// Enable lighting (needs to be specified every frame as Print3D will turn it off
	glEnable(GL_LIGHTING);

	// Increase number of frames
	++m_i32FrameNo;
	m_i32FrameNo = m_i32FrameNo % 3600;

	RotationMatrix = PVRTMat4::RotationY((-m_i32FrameNo * 0.1f) * PVRT_PIf / 180.0f);
	
	// Loop through all lights
	for(i = 0; i < 8; ++i)
	{
		// Only process lights that we are actually using
		if(i < g_ui32LightNo)
		{
			// Transform light
			StepLight(m_psLightData[i]);

			// Set light properties
			glLightfv(GL_LIGHT0 + i, GL_POSITION, &m_psLightData[i].Position.x);
			glLightfv(GL_LIGHT0 + i, GL_AMBIENT,  &m_psLightData[i].Ambient.x);
			glLightfv(GL_LIGHT0 + i, GL_DIFFUSE,  &m_psLightData[i].Diffuse.x);
			glLightfv(GL_LIGHT0 + i, GL_SPECULAR, &m_psLightData[i].Specular.x);

			// Enable light
			glEnable(GL_LIGHT0 + i);
		}
		else
		{
			// Disable remaining lights
			glDisable(GL_LIGHT0 + i);
		}
	}

	// Draw Scene

	// Enable client states
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	// Save matrix by pushing it on the stack
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	// Add a small Y rotation to the model
	glMultMatrixf(RotationMatrix.f);

	// Loop through and draw all meshes
	for(i = 0; i < m_Scene.nNumMeshNode; ++i)
	{
		SPODNode& Node = m_Scene.pNode[i];

		// Loads the correct texture using our texture lookup table
		glBindTexture(GL_TEXTURE_2D, m_pui32Textures[Node.nIdxMaterial]);

		DrawMesh(Node.nIdx);
	}

	// Disable normals as the light quads do not have any
	glDisableClientState(GL_NORMAL_ARRAY);

	// Restore matrix
	glPopMatrix();

	// draw lights

	// No lighting for lights
	glDisable(GL_LIGHTING);

	// Disable Z writes
	glDepthMask(GL_FALSE);

	// Set additive blending
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE,GL_ONE);

	// Set texture and texture environment
	glBindTexture(GL_TEXTURE_2D, m_ui32Light);

	// Render all lights in use
	for(i = 0; i < g_ui32LightNo; ++i)
		DrawLight(m_psLightData[i]);

	// Disable blending
	glDisable(GL_BLEND);

	// Restore Z writes
	glDepthMask(GL_TRUE);

	// Disable client states
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	// Display info text
	m_Print3D.DisplayDefaultTitle("Lighting", "8 point lights", ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}
Esempio n. 8
0
void Mesh::drawVBOs() {
  // scale it so it fits in the window
  Vec3f center; bbox.getCenter(center);
  float s = 1/bbox.maxDim();
  glScalef(s,s,s);
  glTranslatef(-center.x(),-center.y(),-center.z());

  // setup the light
  Vec3f light_position = LightPosition();
  GLfloat position[4] = { float(light_position.x()),float(light_position.y()),float(light_position.z()),1 };
  glLightfv(GL_LIGHT1, GL_POSITION, position);

  // --------------------------
  // Render Mesh 
  InsertColor(mesh_color);
  glEnable(GL_TEXTURE_2D);
  if (args->glsl_enabled) {
    glUseProgramObjectARB(GLCanvas::program);
    glActiveTexture(GL_TEXTURE0);

    // Height Map
    glActiveTexture(GL_TEXTURE0);
    GLint mapLoc = glGetUniformLocationARB(GLCanvas::program, "terrainMap");
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glUniform1iARB(mapLoc, 0);

    // Normal Map
    glActiveTexture(GL_TEXTURE1);
    GLint normLoc = glGetUniformLocationARB(GLCanvas::program, "normalMap");
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glUniform1iARB(normLoc, 1);

    // Stone Texture
    glActiveTexture(GL_TEXTURE2);
    GLint stoneLoc = glGetUniformLocationARB(GLCanvas::program, "texStone");
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    glUniform1iARB(stoneLoc, 2);

    // Grass Texture
    glActiveTexture(GL_TEXTURE3);
    GLint grassLoc = glGetUniformLocationARB(GLCanvas::program, "texGrass");
    glBindTexture(GL_TEXTURE_2D, texture[3]);
    glUniform1iARB(grassLoc, 3);

    // Snow Texture
    glActiveTexture(GL_TEXTURE4);
    GLint snowLoc = glGetUniformLocationARB(GLCanvas::program, "texSnow");
    glBindTexture(GL_TEXTURE_2D, texture[4]);
    glUniform1iARB(snowLoc, 4);

    glActiveTexture(GL_TEXTURE0);
  }
  else {
    glBindTexture(GL_TEXTURE_2D, texture[0]);
  }
  DrawMesh();
  if (args->glsl_enabled) {
    glUseProgramObjectARB(0);
  }
  glDisable(GL_TEXTURE_2D);

  DrawPlateVisualization();
  
  // -------------------------
  // Render Light (for debugging)
  glColor3f(1,1,0);
  DrawLight();
    
  HandleGLError(); 
}