Okay, so I'm trying to implement a singleton into my code for the use of the camera. I don't ever want more than one camera so it makes sense (also we get bonus marks for using a singleton camera, I'm a programming student by the way). I have been trying this for about 2 hours and I just cannot seem to get it to work. Here are the errors I am getting:
Error 1 error LNK2019: unresolved external symbol "public: static class Camera * __cdecl Camera::GetInstance(void)" (?GetInstance@Camera@@SAPAV1@XZ) referenced in function "void __cdecl ChangeSize(int,int)" (?ChangeSize@@YAXHH@Z) C:\Users\GW2\Desktop\Scotts Class Project\Scotts Class Project\Main.obj
Error 2 error LNK1120: 1 unresolved externals C:\Users\GW2\Desktop\Scotts Class Project\Debug\Scotts Class Project.exe 1
The code is below and any and all input is greatly appreciated.
Main.cpp
Camera.h
Camera.cpp
Error 1 error LNK2019: unresolved external symbol "public: static class Camera * __cdecl Camera::GetInstance(void)" (?GetInstance@Camera@@SAPAV1@XZ) referenced in function "void __cdecl ChangeSize(int,int)" (?ChangeSize@@YAXHH@Z) C:\Users\GW2\Desktop\Scotts Class Project\Scotts Class Project\Main.obj
Error 2 error LNK1120: 1 unresolved externals C:\Users\GW2\Desktop\Scotts Class Project\Debug\Scotts Class Project.exe 1
The code is below and any and all input is greatly appreciated.
Main.cpp
Code:
#include <glut.h>
#include <stdio.h>
#include "Particles.h"
#include "DotGrid.h"
#include "Particle.h"
#include "V_randomizer.h"
#include "Camera.h"
//#include "V_randomizer.h"
#define ARRAY_AMMOUNT 1000
/// Simple prototypes for the callbacks
void RenderScene(void);
void HandleTimer(int ID);
void FunctionKeys(int key, int x, int y);
void Keyboard(unsigned char key, int x, int y);
void ChangeSize(GLsizei w, GLsizei h);
//Particle* p;
Particles pp(ARRAY_AMMOUNT);
DotGrid d(0.9,8);
V_Randomizer* random;
//V_Randomizer* rand;
double x,y,z,rotation;
void init(void)
{
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 150.0 };
GLfloat light_position[] = { 1.0, 200.0, 1.0, 10.0 };
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void main(int argc, char **argv){
//p = new Particle();
random = new V_Randomizer();
//p->vy = random->box_muller(0.0,2.0);
rotation = 45.0;
//create a pointer for the particle
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("This is the window title");
init ();
/// Java does the same sort of thing here,
/// simply pass the name of a function that should
/// be called whenever an event occurs.
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
glutKeyboardFunc(Keyboard);
glutSpecialFunc(FunctionKeys);
glutTimerFunc(1000,HandleTimer,1);/// See HandleTimer(...)
//rand = new V_Randomizer();
//pp = new Particles(ARRAY_AMMOUNT); //creates the particle array
//for (int i = 0; i < ARRAY_AMMOUNT; i++)
//{
// pp[i] = new Particle(rand->box_muller(-4,10) , rand->box_muller(-6,8) , rand->box_muller(-9,9)); //fills the array
//}
glutMainLoop(); /// This starts the main loop which will
/// call the appropreate subroutine
/// given the event
//delete pp; //gets the particle the heck out of dodge
}
/// If the window changes size this subroutine will be called
/// note: This subroutine will be called upon the creation of the window since, logically,
/// the window has changed from nothing to something
void ChangeSize(GLsizei w, GLsizei h){
Camera::GetInstance();
}
/// Whenever the scene needs to be redrawn this function is called
void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);/// Clears the screen
/// PLACE DRAWING CODE HERE
glPushMatrix();
glutSolidSphere (1.0, 20, 16);
//p->render();
glRotated(rotation, 1.0,0.0,0.0);
d.createGrid();
//for (int i = 0; i < ARRAY_AMMOUNT; i++){
// pp.render();
//}
glPopMatrix();
glFlush(); ///Shove everything through the "pipeline"
}
void HandleTimer(int ID){
pp.update(0.033);
//p->update(0.033);
/// This function send a message to the main loop that it's time to call
/// the DisplayFunc which I called "RenderScene"
glutPostRedisplay();
/// The first value is the number of millseconds before the next event
/// The second arg is a pointer to the callback function
/// The third is the ID number of this timer
glutTimerFunc(0.033,HandleTimer,1);
}
void FunctionKeys(int key, int x, int y){
/// this function is called whenever a button off the standard keybord is pressed
/// for example the function keys or the arrow keys - hint
/// Look for the following
if(key == GLUT_KEY_UP)
{
printf("UP arrow\n");
rotation+=1;
printf("%lf", rotation);
}
if(key == GLUT_KEY_DOWN)
{
printf("DOWN arrow\n");
rotation+=-1;
printf("%lf", rotation);
}
/// GLUT_KEY_DOWN
/// GLUT_KEY_RIGHT
/// GLUT_KEY_LEFT
}
void Keyboard(unsigned char key, int x, int y){
printf("%c<%d> %d %d\n",key,key,x,y);
if(key=='q' || key=='Q' || key == 27) exit(0);
}
Camera.h
Code:
class Camera{
private:
Camera();
~Camera();
Camera* Instance;
public:
void Render(GLsizei w, GLsizei h);
void Update(double _time);
void Pan();
static Camera* GetInstance();
};
Camera.cpp
Code:
#include "Camera.h"
#include <stdio.h>
#include <glut.h>
Camera* Camera::Instance = 0;
class Camera{
//Camera* Camera::Instance = 0;
Camera::Camera(){
}
Camera::~Camera(){
}
void Render(GLsizei w, GLsizei h)
{
//x = 0.0;
//y = 3.0;
//z = -10.0;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat aspectRatio = (GLfloat)w /(GLfloat)h;
/*if(w < h){
glOrtho(-10.0,10.0,-10.0 / aspectRatio, 10.0 / aspectRatio,10.0,-10.0);
}else{
glOrtho(-10.0* aspectRatio,10.0 * aspectRatio,-10.0 , 10.0 ,10.0,-10.0);
}*/
gluPerspective(120.0,aspectRatio,1.0,500.0);
::gluLookAt(x,y,z,0.0,0.0,0.0,0.0,1.0,0.0);
}
void Update(double _time)
{
}
void Pan()
{
}
Camera GetInstance()
{
if(Instance == 0)
{
Instance = new Camera();
}
return Instance;
}
}