Thank you for the help, I’ve got it working now 
However I am now having issues with my lighting. Would you be able to assist me with it? It’s not behaving as I expect.
void init()
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CCW); // Counter clock-wise polygons face out
glEnable(GL_CULL_FACE); // Do not calculate inside of jet
// Create light components
GLfloat ambientLight[] = { 0.4f, 0.4f, 0.4f, 0.7f };
GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7, 1.0f };
GLfloat specularLight[] = { 0.0f, 1.0f, 3.0f, 1.0f };
GLfloat position[] = {0.0f, 10.0f, -10.0f};
// Assign created components to GL_LIGHT0
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight);
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
}
This is the settings for the lighting, and below is the code for the object.
void DrawBase()
{
float mcolor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor);
float specReflection[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_SPECULAR, specReflection);
glMateriali(GL_FRONT, GL_SHININESS, 96);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Translate the whole scene out and into view
// This is the initial viewing transformation
glTranslatef(0.0f, 0.0f, -35.0f);
glBegin(GL_QUADS);
//Left side
glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-12.0f, -12.0f, 0.0f);
glVertex3f(-12.0f, -12.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, 0.0f);
//Front
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(-12.0f, -11.0f, 0.0f);
glVertex3f(-12.0f, -12.0f, 0.0f);
glVertex3f(12.0f, -12.0f, 0.0f);
glVertex3f(12.0f, -11.0f, 0.0f);
//Right side
glNormal3f(1.0f, 0.0f, 0.0f);
glVertex3f(12.0f, -11.0f, 0.0f);
glVertex3f(12.0f, -11.0f, -7.0f);
glVertex3f(12.0f, -12.0f, -7.0f);
glVertex3f(12.0f, -12.0f, 0.0f);
//Back
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(12.0f, -12.0f, -7.0f);
glVertex3f(12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -12.0f, -7.0f);
//Top
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, 0.0f);
glVertex3f(12.0f, -11.0f, 0.0f);
//Bottom
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(12.0f, -12.0f, -7.0f);
glVertex3f(-12.0f, -12.0f, -7.0f);
glVertex3f(-12.0f, -12.0f, 0.0f);
glVertex3f(12.0f, -12.0f, 0.0f);
glEnd();
}
The object lights up, but it does not appear to be coming from any direction, the ambient light appears to be the only thing that affects it. What am I doing wrong?
I’ll post the full code here below just in case you want to look at that:
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <vector.h>
#define GLUT_DISABLE_ATEXIT_HACK
#include "GL/glee.h"
#include "GL/glut.h"
#include "GL/glu.h"
#include "GL/gltools.h" // OpenGL toolkit
#include "GL/gl.h"
using namespace std;
void DrawBase()
{
float mcolor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor);
float specReflection[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_SPECULAR, specReflection);
glMateriali(GL_FRONT, GL_SHININESS, 96);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Translate the whole scene out and into view
// This is the initial viewing transformation
glTranslatef(0.0f, 0.0f, -35.0f);
glBegin(GL_QUADS);
//Left side
glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-12.0f, -12.0f, 0.0f);
glVertex3f(-12.0f, -12.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, 0.0f);
//Front
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(-12.0f, -11.0f, 0.0f);
glVertex3f(-12.0f, -12.0f, 0.0f);
glVertex3f(12.0f, -12.0f, 0.0f);
glVertex3f(12.0f, -11.0f, 0.0f);
//Right side
glNormal3f(1.0f, 0.0f, 0.0f);
glVertex3f(12.0f, -11.0f, 0.0f);
glVertex3f(12.0f, -11.0f, -7.0f);
glVertex3f(12.0f, -12.0f, -7.0f);
glVertex3f(12.0f, -12.0f, 0.0f);
//Back
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(12.0f, -12.0f, -7.0f);
glVertex3f(12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -12.0f, -7.0f);
//Top
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, -7.0f);
glVertex3f(-12.0f, -11.0f, 0.0f);
glVertex3f(12.0f, -11.0f, 0.0f);
//Bottom
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(12.0f, -12.0f, -7.0f);
glVertex3f(-12.0f, -12.0f, -7.0f);
glVertex3f(-12.0f, -12.0f, 0.0f);
glVertex3f(12.0f, -12.0f, 0.0f);
glEnd();
}
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawBase();
glutSwapBuffers();
}
void init()
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CCW); // Counter clock-wise polygons face out
glEnable(GL_CULL_FACE); // Do not calculate inside of jet
// Create light components
GLfloat ambientLight[] = { 0.4f, 0.4f, 0.4f, 0.7f };
GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7, 1.0f };
GLfloat specularLight[] = { 0.0f, 1.0f, 3.0f, 1.0f };
GLfloat position[] = {0.0f, 10.0f, -10.0f};
// Assign created components to GL_LIGHT0
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight);
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
}
void TimerFunc(int value)
{
glutPostRedisplay();
glutTimerFunc(100, TimerFunc, 1);
}
void ChangeSize(int w, int h)
{
GLfloat nRange = 100.0f;
static float ratio = 1.0f * w / h;
// Prevent a divide by zero
if(h == 0)
h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ACCUM | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("OpenGL Atom");
init();
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
glutTimerFunc(500, TimerFunc, 1);
glutMainLoop();
return 0;
}