error c2373 : redefinition different type modifiers
that error occurs at Cube::displayCB', Cube::reshapeCB, 'Cube::timerCB', all the files end "~CB".
How can i solve them ?
#ifdef __APPLE__
#include
#else
#include
#endif
#include <windows.h>
#include
#pragma comment(lib,"ws2_32.lib")
#pragma comment (lib, "opengl32.lib")
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <vector>
#include "Vectors.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define L 480 //(110cm = 1.1m)
#define W 400 //pallet size is given! (mm)
#define H 1440
const int SCREEN_WIDTH = 400;
const int SCREEN_HEIGHT = 300;
const int TEXT_WIDTH = 8;
const int TEXT_HEIGHT = 13;
const float FOV_Y = 60.0f;
const int CUBE_ROWS = 2;
const int CUBE_COLS = 4;
const int CUBE_SLICES = 1;
const float CAMERA_DISTANCE = 17.0f;
const float x = 0.0;
const float y = 0.0;
const float z = 0.0;
void *font = GLUT_BITMAP_8_BY_13;
int screenWidth;
int screenHeight;
bool mouseLeftDown;
bool mouseRightDown;
float mouseX, mouseY;
float cameraDistance;
float cameraAngleX, cameraAngleY;
int drawMode;
int hitId;
std::vector<vector3> cubePositions;
GLfloat normals[] = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 };
GLubyte indices[] = { 0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4, 8, 9,10, 10,11, 8, 12,13,14, 14,15,12, 16,17,18, 18,19,16, 20,21,22, 22,23,20 };
GLfloat Start_vertices[] = {0,0,0 , 1,1,1};
class Cube {
public:
float box_l;
float box_w;
float box_h;
GLfloat vertices[];
private : static Cube* thisCube;
public: Cube(float x,float y,float z);
void Sets_Vertices();
void Draw_Cube();
int initGLUT(int argc, char **argv);
void initGL();
void drawString(const char *str, int x, int y, float color[4], void *font);
void drawString3D(const char *str, float pos[3], float color[4], void *font);
bool initSharedMem();
void clearSharedMem();
void initLights();
void setCamera(float posX, float posY, float posZ, float targetX, float targetY, float targetZ);
void showInfo();
void toOrtho();
void toPerspective();
void drawCubes();
int selectCube();
int processHits(int hitCount, GLuint* buffer);
static void displayCB();
static void reshapeCB(int w, int h);
static void timerCB(int millisec);
static void idleCB();
static void keyboardCB(unsigned char key, int x, int y);
static void mouseCB(int button, int stat, int x, int y);
static void mouseMotionCB(int x, int y);
static void mousePassiveMotionCB(int x, int y);
static void exitCB();
};
Cube::Cube(float x, float y, float z){
box_l=x;
box_w=y;
box_h=z;
thisCube=this;
}
Cube* Cube::thisCube = NULL;
void Cube::Sets_Vertices(){
GLfloat vertices[] = { x-box_l, y-box_w, z+box_h, x+box_l, y-box_w, z+box_h, x+box_l, y+box_w, z+box_h, x-box_l, y+box_w, z+box_h, x+box_l, y-box_w, z-box_h, x+box_l, y+box_w, z-box_h, x+box_l, y+box_w, z+box_h, x+box_l, y-box_w, z+box_h, x-box_l, y+box_w, z+box_h, x+box_l, y+box_w, z+box_h, x+box_l, y+box_w, z-box_h, x-box_l, y+box_w, z-box_h, x-box_l, y-box_w, z+box_h, x-box_l, y+box_w, z+box_h, x-box_l, y+box_w, z-box_h, x-box_l, y-box_w, z-box_h, x-box_l, y-box_w, z+box_h, x-box_l, y-box_w, z-box_h, x+box_l, y-box_w, z-box_h, x+box_l, y-box_w, z+box_h, x-box_l, y-box_w, z-box_h, x-box_l, y+box_w, z-box_h, x+box_l, y+box_w, z-box_h, x+box_l, y-box_w, z-box_h }; }
int Cube::initGLUT(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(100, 100);
int handle = glutCreateWindow(argv[0]);
glutDisplayFunc(displayCB);
glutTimerFunc(33, timerCB, 33); glutReshapeFunc(reshapeCB);
glutKeyboardFunc(keyboardCB);
glutMouseFunc(mouseCB);
glutMotionFunc(mouseMotionCB);
glutPassiveMotionFunc(mousePassiveMotionCB);
return handle;
}
void Cube::initGL()
{
glShadeModel(GL_SMOOTH); glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glClearColor(0, 0, 0, 0); glClearStencil(0); glClearDepth(1.0f); glDepthFunc(GL_LEQUAL);
initLights();
float white[] = {1,1,1,1};
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 128);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
}
void Cube::drawString(const char *str, int x, int y, float color[4], void *font)
{
glPushAttrib(GL_LIGHTING_BIT | GL_CURRENT_BIT); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D);
glDepthFunc(GL_ALWAYS);
glColor4fv(color); glRasterPos2i(x, y);
while(*str)
{
glutBitmapCharacter(font, *str);
++str;
}
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glDepthFunc(GL_LEQUAL);
glPopAttrib();
}
void Cube::drawString3D(const char *str, float pos[3], float color[4], void *font)
{
glPushAttrib(GL_LIGHTING_BIT | GL_CURRENT_BIT); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D);
glColor4fv(color); glRasterPos3fv(pos);
while(*str)
{
glutBitmapCharacter(font, *str);
++str;
}
glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glPopAttrib();
}
bool Cube::initSharedMem()
{
screenWidth = SCREEN_WIDTH;
screenHeight = SCREEN_HEIGHT;
cameraAngleX = cameraAngleY = 0.0f;
cameraDistance = CAMERA_DISTANCE;
mouseLeftDown = mouseRightDown = false;
mouseX = mouseY = 0;
drawMode = 0;
hitId = -1;
const float STEP = 4.0f;
float startX[] = {0,0,0,4.8,4.8,4.8,9.6,9.6};
float startY[] = {0,4,0,0,4,0,0,4,0};
float startZ[]= {0,0,1,0,0,1,0,0,1};
int cur=0;
int maxbox=CUBE_COLS*CUBE_ROWS*CUBE_SLICES;
Vector3 position;
for(int k = 0; k < maxbox; k++,cur++) {
position.set(startX[cur],startY[cur],startZ[cur]);
cubePositions.push_back(position);
}
return true;
}
void Cube::clearSharedMem()
{
}
void Cube::initLights()
{
GLfloat lightKa[] = {0.0f, 0.0f, 0.0f, 1.0f}; GLfloat lightKd[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat lightKs[] = {1, 1, 1, 1}; glLightfv(GL_LIGHT0, GL_AMBIENT, lightKa);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightKd);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightKs);
float lightPos[4] = {0, 1, 1, 0};
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glEnable(GL_LIGHT0); }
void Cube::setCamera(float posX, float posY, float posZ, float targetX, float targetY, float targetZ)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(posX, posY, posZ, targetX, targetY, targetZ, 0, 1, 0); }
void Cube::showInfo()
{
glPushMatrix(); glLoadIdentity();
glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, screenWidth, 0, screenHeight);
float color[4] = {1, 1, 0, 1};
std::stringstream ss;
ss << "Mouse: (" << mouseX << ", " << mouseY << ")";
drawString(ss.str().c_str(), 2, screenHeight-TEXT_HEIGHT, color, font);
ss.str("");
ss << "Hit Cube ID: " << hitId;
drawString(ss.str().c_str(), 2, screenHeight-(TEXT_HEIGHT*2), color, font);
ss.str("");
ss << "Move the mouse over a cube.";
drawString(ss.str().c_str(), 2, 2, color, font);
ss.str("");
ss << std::resetiosflags(std::ios_base::fixed | std::ios_base::floatfield);
glPopMatrix();
glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
void Cube::toOrtho()
{
glViewport(0, 0, (GLsizei)screenWidth, (GLsizei)screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, screenWidth, 0, screenHeight, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Cube::toPerspective()
{
glViewport(0, 0, (GLsizei)screenWidth, (GLsizei)screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(FOV_Y, (float)(screenWidth)/screenHeight, 1.0f, 10000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Cube::drawCubes()
{
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glVertexPointer(3, GL_FLOAT, 0, vertices);
Vector3 pos;
for(int i = 0; i < (int)cubePositions.size(); ++i)
{
glPushMatrix();
glPushName(i);
pos = cubePositions.at(i);
glTranslatef(pos.x, pos.y, pos.z);
if(i == hitId)
glColor3f(1.0f, 0.0f, 0.0f);
else
glColor3f(0.7f, 0.7f, 0.7f);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
glPopName(); glPopMatrix();
}
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);
}
int Cube::selectCube()
{
const int BUFFER_SIZE = 512;
GLuint selectionBuffer[BUFFER_SIZE];
memset(selectionBuffer, 0, sizeof(int) * BUFFER_SIZE);
int viewport[4] = {0, 0, screenWidth, screenHeight};
glSelectBuffer(BUFFER_SIZE, selectionBuffer);
glRenderMode(GL_SELECT);
glInitNames();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(mouseX, screenHeight - mouseY, 3, 3, viewport);
gluPerspective(FOV_Y, (float)screenWidth / screenHeight, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(0, 0, -cameraDistance);
glRotatef(cameraAngleX, 1, 0, 0); glRotatef(cameraAngleY, 0, 1, 0);
glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
glShadeModel(GL_FLAT);
drawCubes();
glEnable(GL_BLEND);
glEnable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glFlush();
int hitCount = glRenderMode(GL_RENDER);
if(hitCount > 0)
{
return processHits(hitCount, selectionBuffer);
}
else
{
return -1; }
}
int Cube::processHits(int hitCount, GLuint* buffer)
{
if(hitCount <= 0 || !buffer)
return -1;
GLuint nameCount, minZ, maxZ;
GLuint hitZ = 0xffffffff;
int hitId = 0;
for(int i = 0; i < hitCount; ++i)
{
nameCount = *buffer++;
minZ = *buffer++;
maxZ = *buffer++;
if(minZ < hitZ)
{
hitZ = minZ;
hitId = (int)*buffer;
}
for(int j = 0; j < (int)nameCount; ++j, ++buffer)
{
;
}
}
return hitId;
}
void CALLBACK Cube::displayCB()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glPushMatrix();
glTranslatef(0, 0, -cameraDistance);
glRotatef(cameraAngleX, 1, 0, 0); glRotatef(cameraAngleY, 0, 1, 0);
thisCube->drawCubes();
thisCube->showInfo();
glPopMatrix();
glutSwapBuffers();
}
void CALLBACK Cube::reshapeCB(int width, int height)
{
screenWidth = width;
screenHeight = height;
thisCube->toPerspective();
}
void CALLBACK Cube::timerCB(int millisec)
{
glutTimerFunc(millisec, timerCB, millisec);
glutPostRedisplay();
}
void CALLBACK Cube::idleCB()
{
glutPostRedisplay();
}
void CALLBACK Cube::keyboardCB(unsigned char key, int x, int y)
{
switch(key)
{
case 27: exit(0);
break;
case 'd': case 'D':
drawMode = ++drawMode % 3;
if(drawMode == 0) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}
else if(drawMode == 1) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
}
else {
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
}
break;
case 'r':
case 'R':
break;
case ' ':
break;
default:
;
}
}
void CALLBACK Cube::mouseCB(int button, int state, int x, int y)
{
mouseX = x;
mouseY = y;
if(button == GLUT_LEFT_BUTTON)
{
if(state == GLUT_DOWN)
mouseLeftDown = true;
else if(state == GLUT_UP)
mouseLeftDown = false;
}
else if(button == GLUT_RIGHT_BUTTON)
{
if(state == GLUT_DOWN)
mouseRightDown = true;
else if(state == GLUT_UP)
mouseRightDown = false;
}
}
void CALLBACK Cube:: mouseMotionCB(int x, int y){
if(mouseLeftDown)
{
cameraAngleY += (x - mouseX);
cameraAngleX += (y - mouseY);
mouseX = x;
mouseY = y;
}
if(mouseRightDown)
{
cameraDistance -= (y - mouseY) * 0.2f;
mouseY = y;
}
}
void CALLBACK Cube::mousePassiveMotionCB(int x, int y)
{
mouseX = x;
mouseY = y;
if(!mouseLeftDown && !mouseRightDown)
{
hitId = thisCube->selectCube();
}
}
void CALLBACK Cube::exitCB()
{
thisCube->clearSharedMem();
}
void main(int argc, char **argv)
{
Cube box1={2.0,1.0,1.0};
box1.initSharedMem();
box1.initGLUT(argc, argv);
box1.initGL();
glutMainLoop();
glutMainLoop();
}</vector3></math.h></string.h></stdlib.h></stdio.h></vector></iomanip></string></sstream></iostream></cstdlib></windows.h>