Hey, I'm not sure if this should go in the Linux section, but I think it's just general. I've this program here I'm writing as I'm learning OpenGL (and more C++ too), and there doesn't seem to be anything wrong with the code, but I'm getting an error I've never gotten before.
Here is my complete error:
Code:
g++ "3D_Shape_Making.c" -lagl -lGL -lGLU `allegro-config --cflags` `allegro-config --libs` -Wl,-V (in directory: /home/lorgonjortle/C++/AllegroGL/3D_Shape_Creator)
Compilation failed.
GNU ld (GNU Binutils for Ubuntu) 2.19.1
Supported emulations:
elf_i386
i386linux
elf_x86_64
/tmp/cchOhgKj.o: In function `__static_initialization_and_destruction_0(int, int)':
3D_Shape_Making.c:(.text+0x132): undefined reference to `Cube::Cube()'
/tmp/cchOhgKj.o: In function `Draw()':
3D_Shape_Making.c:(.text+0x360): undefined reference to `Cube::Z'
3D_Shape_Making.c:(.text+0x36a): undefined reference to `Cube::Y'
3D_Shape_Making.c:(.text+0x374): undefined reference to `Cube::X'
collect2: ld returned 1 exit status
Can any of you tell what it is just by looking? I'll include the source too....
MAIN.CPP
Code:
#include <allegro.h>
#include <alleggl.h>
#include <iostream>
#include <GL/glu.h>
#include <fstream>
#include "Cube.h"
#include "Log.h"
using namespace std;
volatile int Count = 0;
int angle = 1;
bool Show[50] = {false};
int Auto_Rotate[50] = {-1}; //-1 false - 1 true
float scaleX = .7, scaleY = .7, scaleZ = .7;
int Xangle = 0, Yangle = 0, Zangle = 0;
Cube Cube_Object[50];
int Active = 0; //Will be 0 - 50
void TimerFunc(void){
Count++;
angle += 1;
if(angle > 360){
angle-=360; //To keep it more precise
}
}
void Init(void){
int width = 800;
int height = 600;
Save_Text("3D Shape creator V1 - Cubes\n\n");
Save_Text("Height: 600\n");
Save_Text("Width: 800\n");
allegro_init();
install_allegro_gl();
install_keyboard();
install_timer();
Save_Text("Initializing...\nAllegro...\nAllegroGL...\nKeyboard...\nTimer...\n");
allegro_gl_clear_settings();
allegro_gl_set(AGL_DOUBLEBUFFER, true);
allegro_gl_set(AGL_COLOR_DEPTH, 16);
allegro_gl_set(AGL_Z_DEPTH, 16);
allegro_gl_set(AGL_SUGGEST, AGL_DOUBLEBUFFER | AGL_Z_DEPTH | AGL_COLOR_DEPTH);
Save_Text("Double Buffer...\nColor Depth...\nZ Depth...\n");
set_gfx_mode(GFX_OPENGL_WINDOWED, width, height, 0, 0);
Save_Text("GFX Mode...\n");
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,.1,200.0f);
glViewport(0, 0, width, height);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Save_Text("Viewport set...\nEnabled Depth Testing...\nCompletely Initialized.");
}
void Draw(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
for(int i = 0; i < 50; i++){
if(Show[i] == true){
//Cube is active, draw it
glPushMatrix();
if(Auto_Rotate[i] == -1){ //If it's false, then rotate based on keys
glRotatef(Xangle, 1, 0, 0);
glRotatef(Yangle, 0, 1, 0);
glRotatef(Zangle, 0, 0, 1);
}
if(Auto_Rotate[i] == 1){ //If true, then rotate based on int angle which is updated in the timer
glRotatef(angle, 1, 0, 0);
glRotatef(angle, 0, 1, 0);
}
glScalef(scaleX, scaleY, scaleZ);
glBegin(GL_QUADS);
for(int k = 0; k < 25; k++){ //Draw all of the vertices - 24 of them
glVertex3f(Cube_Object[k].X[k], Cube_Object[k].Y[k], Cube_Object[k].Z[k]);
}
glEnd();
glPopMatrix();
}
}
}
int main(){
SetupLog();
Init();
LOCK_VARIABLE(Count);
LOCK_FUNCTION(TimerFunc);
install_int_ex(TimerFunc, BPS_TO_TIMER(60));
Save_Text("\n\n-------------------------\nNOW ACCEPTING INPUT\n----------------------\n");
while(!key[KEY_ESC]){
while(Count > 0){
if((key[KEY_D] && Show[Active] == true)){
Show[Active] = false;
scaleX = scaleY = scaleZ = .7;
Yangle = Xangle = Zangle = 0;
Save_Text("Object deleted\n");
}
if(key[KEY_C]){
for(int i = 0; i < 50; i++){
if(Show[i] == false){
Show[i] = true;
break;
}
}
Save_Text("Cube created.\n");
}
if(key[KEY_UP] && !key[KEY_R] && key[KEY_S]){
scaleY += .05;
}
if(key[KEY_DOWN] && !key[KEY_R] && key[KEY_S]){
scaleY -= .05;
}
if(key[KEY_RIGHT] && !key[KEY_R]){
scaleX += .05;
}
if(key[KEY_LEFT] && !key[KEY_R]){
scaleX -= .05;
}
if(key[KEY_PGDN] && !key[KEY_R]){
scaleZ -= .05;
}
if(key[KEY_PGUP] && !key[KEY_R]){
scaleZ += .05;
}
if(key[KEY_R] && key[KEY_RIGHT]){
Yangle += 1;
}
if(key[KEY_R] && key[KEY_LEFT]){
Yangle -= 1;
}
if(key[KEY_R] && key[KEY_UP]){
Xangle += 1;
}
if(key[KEY_R] && key[KEY_DOWN]){
Xangle -= 1;
}
if(key[KEY_R] && key[KEY_PGDN]){
Zangle -= 1;
}
if(key[KEY_R] && key[KEY_PGUP]){
Zangle += 1;
}
if(key[KEY_S] && key[KEY_RSHIFT]){
scaleY *= .9;
scaleX *= .9;
scaleZ *= .9;
}
if(key[KEY_S] && key[KEY_LSHIFT]){
scaleY *= 1.1;
scaleX *= 1.1;
scaleZ *= 1.1;
}
if(key[KEY_A] && key[KEY_RSHIFT] && Auto_Rotate[Active] == -1){
Auto_Rotate[Active] = 1;
Save_Text("Auto Rotate commenced.\n");
}
if(key[KEY_A] && key[KEY_LSHIFT] && Auto_Rotate[Active] == 1){
Auto_Rotate[Active] = -1;
Save_Text("Auto Rotate has been stopped.\n");
}
Count--;
}
//Draw things
Draw();
allegro_gl_flip();
}
Save_Text("Program ended.\n");
return 0;
}
LOG.H
Code:
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
ofstream Write;
void SetupLog(void){
//Pretend like it's doing something
cout << "Log File in: ";
system("pwd");
//Write date into log
system("date > log.log");
}
void Save_Text(string Text){
Write.open("log.log", ios::app);
Write << Text;
Write.close();
}
CUBE.H
Code:
class Cube{
public:
static const float X[24];
static const float Y[24];
static const float Z[24];
Cube();
~Cube(){};
};
CUBE>CPP
Code:
#include "Log.h"
#include "Cube.h"
const float Cube::X[24] =
{
-.5, .5, .5, -.5,
-.5, .5, .5, -.5,
-.5, -.5, .5, .5,
-.5, -.5, .5, .5,
.5, .5, .5, .5,
-.5, -.5, -.5, -.5
};
const float Cube::Y[24] =
{
.5, .5, -.5, -.5,
.5, .5, -.5, -.5,
.5, .5, .5, .5,
-.5, -.5, -.5, -.5,
.5, .5, -.5, -.5,
.5, .5, -.5, -.5
};
const float Cube::Z[24] =
{
0, 0, 0, 0,
-1, -1, -1, -1,
0, -1, -1, 0,
0, -1, -1, 0,
0, -1, -1, 0,
0, -1, -1, 0
};
Cube::Cube(){
Save_Text("Another cube object created. ~Constructor\n");
}
Thanks for any help,
Lorgon Jortle
PS - If you have any hints on coding style or efficiency, tip me. I'm a beginner still.