Lab 04: Oct 2, 2018

Overview

Today's lab is to show you how to render using indexed primitives in OpenGL. An auxilliary task is to set up lights and render using them.

Task

You have been given an array of vertices and an array of indices for a geometric object. Your task is to use the indexed rendering methods to provide the vertices and indices to OpenGL for rendering.

		// Enable the vertex position array and bind it to our vertex positions
		glEnableClientState(GL_NORMAL_ARRAY);				// Enable the normal buffer
		glNormalPointer(GL_FLOAT, 0, gsVertexNormals);		// Supply an array of normals

		// Enable the vertex position array and bind it to our vertex positions
		glEnableClientState(GL_VERTEX_ARRAY);				// Enable the vertex buffer
		glVertexPointer(3, GL_FLOAT, 0, gsVertexPositions);	// Supply an array of vertices

		// Draw using the vertex buffers and the supplied index buffer
		glDrawElements(GL_TRIANGLES, 60, GL_UNSIGNED_BYTE, gsIndices);


You have been given the properties for a light. Your task is to use the light setup methods to enable and define the light for rendering in OpenGL.

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_SPECULAR, gsLightSpecularColour);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, gsLightDiffuseColour);
	glLightfv(GL_LIGHT0, GL_AMBIENT, gsLightAmbientColour);
	glLightfv(GL_LIGHT0, GL_POSITION, gsLightPosition);
You are free to modify (add to) the lab04.cpp or makefile as you wish.

Code Files

Lab4.cpp
makefile