<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.programmingexamples.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.programmingexamples.net/w/index.php?action=history&amp;feed=atom&amp;title=OpenGL%2FLighting</id>
		<title>OpenGL/Lighting - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.programmingexamples.net/w/index.php?action=history&amp;feed=atom&amp;title=OpenGL%2FLighting"/>
		<link rel="alternate" type="text/html" href="http://www.programmingexamples.net/w/index.php?title=OpenGL/Lighting&amp;action=history"/>
		<updated>2026-06-10T08:05:32Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.5</generator>

	<entry>
		<id>http://www.programmingexamples.net/w/index.php?title=OpenGL/Lighting&amp;diff=361&amp;oldid=prev</id>
		<title>Daviddoria: Created page with '==Lighting.cxx== &lt;source lang=&quot;cpp&quot;&gt; #include &lt;iostream&gt; #include &lt;glut.h&gt;  using namespace std;  void display(); void LookAt(); void DrawCube();  void DrawSphere(const float sca…'</title>
		<link rel="alternate" type="text/html" href="http://www.programmingexamples.net/w/index.php?title=OpenGL/Lighting&amp;diff=361&amp;oldid=prev"/>
				<updated>2010-11-24T00:44:54Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;==Lighting.cxx== &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; #include &amp;lt;iostream&amp;gt; #include &amp;lt;glut.h&amp;gt;  using namespace std;  void display(); void LookAt(); void DrawCube();  void DrawSphere(const float sca…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Lighting.cxx==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;glut.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
void display();&lt;br /&gt;
void LookAt();&lt;br /&gt;
void DrawCube();&lt;br /&gt;
&lt;br /&gt;
void DrawSphere(const float scale, const float alpha);&lt;br /&gt;
&lt;br /&gt;
void AmbientLighting();&lt;br /&gt;
void PointLight(const float x, const float y, const float z,  const float amb, const float diff, const float spec);&lt;br /&gt;
&lt;br /&gt;
int WindowHeight = 1000;&lt;br /&gt;
int WindowWidth = 1000;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  glutInit(&amp;amp;argc, argv);&lt;br /&gt;
  //glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);&lt;br /&gt;
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);&lt;br /&gt;
  glutInitWindowSize(WindowWidth, WindowHeight);&lt;br /&gt;
  glutInitWindowPosition(0, 0);&lt;br /&gt;
&lt;br /&gt;
  glutCreateWindow(&amp;quot;Lighting Example&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
  glutDisplayFunc(display);&lt;br /&gt;
&lt;br /&gt;
  glDepthFunc(GL_LESS);&lt;br /&gt;
  glEnable(GL_DEPTH_TEST);&lt;br /&gt;
  glEnable(GL_NORMALIZE);&lt;br /&gt;
&lt;br /&gt;
  AmbientLighting();&lt;br /&gt;
  PointLight(1,1,1, 0, 1, 1);&lt;br /&gt;
  //PointLight(10,10,10);&lt;br /&gt;
  //PointLight(0,0,0, 0, 1, 1);&lt;br /&gt;
&lt;br /&gt;
  LookAt();&lt;br /&gt;
&lt;br /&gt;
  glutMainLoop();&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void AmbientLighting()&lt;br /&gt;
{&lt;br /&gt;
  glEnable(GL_LIGHTING);&lt;br /&gt;
&lt;br /&gt;
  double amb = .3;&lt;br /&gt;
  GLfloat global_ambient[] = {amb,amb,amb, 0.1};&lt;br /&gt;
  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void PointLight(const float x, const float y, const float z, const float amb, const float diff, const float spec)&lt;br /&gt;
{&lt;br /&gt;
  glEnable(GL_LIGHTING);&lt;br /&gt;
&lt;br /&gt;
  /*&lt;br /&gt;
  GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };&lt;br /&gt;
  GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };&lt;br /&gt;
  GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };&lt;br /&gt;
  */&lt;br /&gt;
  GLfloat light_ambient[] = { amb,amb,amb, 1.0 };&lt;br /&gt;
  GLfloat light_diffuse[] = {diff, diff, diff, 1.0 };&lt;br /&gt;
  GLfloat light_specular[] = {spec, spec, spec, 1.0 };&lt;br /&gt;
&lt;br /&gt;
  GLfloat light_position[] = {x,y,z, 0.0 };&lt;br /&gt;
&lt;br /&gt;
  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);&lt;br /&gt;
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);&lt;br /&gt;
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);&lt;br /&gt;
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);&lt;br /&gt;
&lt;br /&gt;
  glEnable(GL_LIGHT0); //enable the light after setting the properties&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void DrawSphere(const float radius, const float alpha)&lt;br /&gt;
{&lt;br /&gt;
  glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;&lt;br /&gt;
  glEnable ( GL_COLOR_MATERIAL ) ;&lt;br /&gt;
  glColor4f(1.0f, 0.0f, 0.0f, alpha);&lt;br /&gt;
&lt;br /&gt;
  //equivalent to doing this:&lt;br /&gt;
  //float diffuse[4] =  {1.0f, 1.0f, 0.0f, alpha};&lt;br /&gt;
      //glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  GLUquadricObj *quadratic;&lt;br /&gt;
  quadratic = gluNewQuadric();&lt;br /&gt;
  gluQuadricNormals(quadratic, GLU_SMOOTH);&lt;br /&gt;
  gluSphere(quadratic, radius, 32, 32);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void LookAt()&lt;br /&gt;
{&lt;br /&gt;
  glMatrixMode(GL_PROJECTION);&lt;br /&gt;
  glLoadIdentity();&lt;br /&gt;
  gluPerspective(70, 1, 1, 100);&lt;br /&gt;
&lt;br /&gt;
  glMatrixMode(GL_MODELVIEW);&lt;br /&gt;
  glLoadIdentity();&lt;br /&gt;
&lt;br /&gt;
  gluLookAt(2, 2, 10, 2, 0, 0, 0, 1, 0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void display()&lt;br /&gt;
{&lt;br /&gt;
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&lt;br /&gt;
  glEnable(GL_DEPTH_TEST);&lt;br /&gt;
&lt;br /&gt;
  DrawSphere(1, 1);&lt;br /&gt;
  DrawSphere(1.1, .5);&lt;br /&gt;
  DrawSphere(1.2, .2);&lt;br /&gt;
&lt;br /&gt;
  glutSwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==CMakeLists.txt==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
cmake_minimum_required(VERSION 2.6)&lt;br /&gt;
&lt;br /&gt;
PROJECT(OpenGLLighting)&lt;br /&gt;
&lt;br /&gt;
set(CMAKE_CXX_FLAGS &amp;quot;${CMAKE_CXX_FLAGS} -fopenmp&amp;quot;) #g++&lt;br /&gt;
&lt;br /&gt;
INCLUDE_DIRECTORIES(/usr/include/GL/)&lt;br /&gt;
&lt;br /&gt;
LINK_DIRECTORIES(/usr/lib)&lt;br /&gt;
&lt;br /&gt;
ADD_EXECUTABLE(Lighting Lighting.cpp)&lt;br /&gt;
&lt;br /&gt;
TARGET_LINK_LIBRARIES(Lighting glut GLU GL Xmu X11)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daviddoria</name></author>	</entry>

	</feed>