Hi guys,
I made my first Open GL program using class and objects but i'm getting whole bunch of errors " [Linker error] undefined reference to `ClassName::MethodName(params)'
Every time when i make new program in open GL i get big messy code of creating a window in one main class. So i decided to make a different class ".h" which creates a window and i can use it over and over again for my other programs and have less code in main class. However, the plan didn't work and i've no clue how to solve it. I've added all the libraries in projct options and required hearders within program. Please someone help, here is my code:
Code in my class:
Code:
#ifndef _MAIN_H
#define _MAIN_H
#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLU32 Library
#include <gl\glaux.h> // Header File For The Glaux Library
class CreateWindow
{
public:
GLvoid ReSizeGLScene(GLsizei width, GLsizei height);
int InitGL(GLvoid);
GLvoid KillGLWindow(GLvoid);
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag);
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
//////////////////////////////////////
// Global Variables
//////////////////////////////////////
extern WNDCLASS wc; // Windows Class Structure
extern HGLRC hRC; // Permanent Rendering Context
extern HDC hDC; // Private GDI Device Context
extern HWND hWnd; // Holds Our Window Handle
extern HINSTANCE hInstance; // Holds The Instance Of The Application
extern bool keys[256]; // Array Used For The Keyboard Routine
extern bool active; // Window Active Flag Set To TRUE By Default
extern bool fullscreen; // Fullscreen Flag Set To Fullscreen Mode By Default
#endif /*MAIN_H*/
Code in my creatingWindow program ".cpp"
I'm not pasting the code for all the methods/functions. I hope you guys will get the idea.
Code:
#include "Main.h"
GLvoid CreateWindow::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
int CreateWindow::InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
return TRUE; // Initialization Went OK
}
Here is the code in my main program which i compile and get the errors.
Code:
CreateWindow objWindow;
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
objWindow.ReSizeGLScene(width, height);
}
int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
objWindow.InitGL();
}
When i compile i get following errors:
"[Linker error] undefined reference to `CreateWindowA::ReSizeGLScene(int, int)' "
"[Linker error] undefined reference to `CreateWindowA::InitGL()' "
Please someone help me or guide me to solve it. I would really apperciate the help. Thank you!!