Salut,
Mon but:
Avoir une classe glEntity qui gere l'affichage openGL d'objects de classe Entity.
Mon Probleme:
undefined reference to `glEntity::ob'
Mon environement:
DevC++ sous windows XP, library openGL
Mes suppositions:
Les includes foirent?
(voir code plus bas)
Le make file foire?:
make.exe -f "C:\Documents and Settings\Administrator\My Documents\C_Dev\Project2\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
g++.exe main.o -o "Project2.exe" -L"C:/Dev-Cpp/lib" -lmingw32 -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lglut32 -lglu32 -lopengl32 -lgdi32 -lm -lwinmm
Mes questions:
Qu-est-ce qui foire ?
Devrais-je utiliser des pointeurs?
Si c'est a cause du make? Comment le faire moi meme?
Je sens que je dois utiliser des fonctions 'Static' dans la class qui gere l'OpenGL mais je ne sais pas pourquoi...??
Mon code:
3 fichiers: main.cpp, Entity.h et glEntity.h:
Code C/C++ :
// ------------------------main.cpp-------------------
/* Using DEV C++ and OpenGL, you need to add in your project parameters, in the linkers:
-lmingw32
-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
-lglut32
-lglu32
-lopengl32
-lgdi32
-lm
-lwinmm
*/
#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
#include <iostream>
//include the 2 class files
#include "Entity.h"
#include "glEntity.h"
using namespace std;
int main (int argc, char **argv) {
glEntity tata;
tata.ob.Xpos=1.0;
tata.ob.Ypos=-5.0;
tata.ob.Zpos=-5.0;
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Universe");
tata.initEntity();
glutDisplayFunc (tata.displayEntity);
glutIdleFunc (tata.displayEntity);
cout<<"main\n";
glutReshapeFunc (tata.reshapeEntity);
glutMainLoop ();
return 0;
}
//-----------Entity.h-------------
#include <iostream>
using namespace std;
class Entity {
public:
Entity(); // default constructor; initialize the entity
Entity(double a,double b,double c,double d,double e,double f); //constructor with parameters
~Entity(); // Destructor; to free memory space if Entity is not needed anymore
void doNothing(); // Do Nothing
void cHase(); // Chase another Entity;
void fLee(); // Flee another Entity
void mAte(); // Mate with another Entity
int feedBack(); // give feedback of estimation of impact with another Entity -1:the other is smaller 0:the other is equal 1:the other is bigger
public:
double Xpos;
double Ypos;
double Zpos;
double Xmov;
double Ymov;
double Zmov;
};
Entity::Entity(){};
Entity::Entity(double a,double b,double c,double d,double e,double f){
Xpos=a;
Ypos=b;
Zpos=c;
Xmov=d;
Ymov=e;
Zmov=f;
};
Entity::~Entity(){/* cout<< "Destructing\n"; */};
//------------glEntity.h--------------
#include <stdio.h>
#include <iostream>
using namespace std;
class glEntity {
public:
glEntity();//Declare constructor w/o parameters
glEntity(Entity(double a,double b,double c,double d,double e,double f));//Declare constructor with parameters
~glEntity();//Declare Destructor
void initEntity();
static void drawEntity(Entity ob);
static void UpdateEntity(Entity ob);
static void displayEntity(void);
static void reshapeEntity(int w, int h);
public:
static Entity ob;
};
glEntity::glEntity(){};
glEntity::glEntity(Entity(double a,double b,double c,double d,double e,double f)){
Entity ob(double a,double b,double c,double d,double e,double f);
};
// --------init functions--------
glEntity::~glEntity(){};
void glEntity::UpdateEntity(Entity ob){
ob.Xpos=ob.Xpos+0.001;
/*
ob.Xpos=ob.Xpos+ob.Xmov;
ob.Ypos=ob.Ypos+ob.Ymov;
ob.Zpos=ob.Zpos+ob.Zmov;
*/
};
void glEntity::drawEntity(Entity ob){ // pass object ob from class Entity as paramameter to the function
glPushMatrix();
glTranslatef (ob.Xpos, ob.Ypos, ob.Zpos);
glDisable (GL_DEPTH_TEST);
glEnable (GL_BLEND);
glColor3f(1.0, 1.0, 1.0); //color the cube red
glutSolidSphere (1,10, 10); //draw a solid sphere
glEnable(GL_DEPTH_TEST);
glPopMatrix();
};
void glEntity::displayEntity(void){
glClearDepth (1);
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef (0,0,-10);
UpdateEntity(ob);
cout<<ob.Xpos;
drawEntity(ob);
glutSwapBuffers();
};
void glEntity::reshapeEntity(int w, int h){
w=100;
h=100;
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode (GL_MODELVIEW);
};
void glEntity::initEntity(){
glEnable(GL_DEPTH_TEST);
ob.Xpos=2.0;
ob.Ypos=1.0;
ob.Zpos=1.0;
};
Le Compile Log:
main.o(.text+0x313):main.cpp: undefined reference to `glEntity::ob'
main.o(.text+0x339):main.cpp: undefined reference to `glEntity::ob'
main.o(.text+0x351):main.cpp: undefined reference to `glEntity::ob'
main.o(.text+0x485):main.cpp: undefined reference to `glEntity::ob'
main.o(.text+0x48d):main.cpp: undefined reference to `glEntity::ob'
main.o(.text+0x495):main.cpp: more undefined references to `glEntity::ob' follow
collect2: ld returned 1 exit status
make.exe: *** [Project2.exe] Error 1
Execution terminated
J'ai du batailler pour les fonctions openGL qui prennent void en paramametre.
Maintenant je ne sais plus quoi faire.
Toutes propositions et aides sont les bienvenues
Merci
Gweno