I need your help. It's really strange, and I try for days and days for resolve this issue, but don't.
I have made a project that use OpenGL to represent in a windows a series of cubes contained in an vector.
I want to ask your help about this issue: on my notebook Fujitsu Lifebook A530, with win 7 64bit, 4GB RAM, intel P6100 dual core and visual c++ 2010, the project compiled correcty, and if I launch exe file, works well (I can interact with OpenGL representation, rotate, zoom...etc...) slow, but works. It's due to integrated video card, Intel HD, so cheap and low performance card.
But, I have a desktop PC, intel i7 2600 3.40Ghz, 8GB DDR3 and Nvidia Quadro 4000 card, this project compiled correctly, but if I launch exe file, OpenGL windows it's blocked, "not responding"...
If I launch project from visual C++ 2010 start button (green play button), it start in "start debug" and project runs well, without problem with OpenGL (I can rotate, zoom, etc)..OpenGL window don't block itself or other.
Why?? The enviromental settings of Visual C++ 2010 it's the same in desk PC and notebook, same Windows 7 64bit professional, same library (freeglut)...
I can't understand why...what's the problem and how can fix it...why when launch application from his exe file, OpenGL windows it's blocked, freeze...
This is the code of OpenGL part of application:
struct Cpoint
{
double x;
double y;
double z;
double l;
};
vector<Cpoint> Clist;
Cpoint loca;
void PrepareVect(cubo * temp){
if (temp->lista_sottocubi.size() == 0)
{
if (temp->livello == LMAXI) {
double centro[3]={(temp->V[6].x)/2, (temp->V[6].y)/2,(temp->V[6].z)/2};
loca.x = centro[0];
loca.y = centro[1];
loca.z = centro[2];
loca.l = temp->lato;
Clist.push_back(loca);
}
}
else {
for (int i=0;i<(int)temp->lista_sottocubi.size();i++){
PrepareVect(&temp->lista_sottocubi[i]);
}
}
}
void cubelist(){
Clist.clear();
PrepareVect(&prova);
}
void mouseCB(int button, int stat, int x, int y);
void mouseMotionCB(int x, int y);
bool initSharedMem();
void clearSharedMem();
void initLights();
void setCamera(float posX, float posY, float posZ, float targetX, float targetY, float targetZ);
void toOrtho();
void toPerspective();
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const float CAMERA_DISTANCE = 10.0f;
int screenWidth;
int screenHeight;
bool mouseLeftDown;
bool mouseRightDown;
bool mouseMiddleDown;
float mouseX, mouseY;
float cameraAngleX;
float cameraAngleY;
float cameraDistance;
int drawMode;
void init()
{
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_COLOR_MATERIAL);
initLights();
}
bool initSharedMem()
{
screenWidth = SCREEN_WIDTH;
screenHeight = SCREEN_HEIGHT;
mouseLeftDown = mouseRightDown = mouseMiddleDown = false;
mouseX = mouseY = 0;
cameraAngleX = cameraAngleY = 0.0f;
cameraDistance = 0.3f;
drawMode = 0;
return true;
}
void clearSharedMem()
{
}
void initLights()
{
GLfloat lightKa[] = {.2f, .2f, .2f, 1.0f}; GLfloat lightKd[] = {.7f, .7f, .7f, 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, 0, 20, 1};
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glEnable(GL_LIGHT0);
}
void 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);
focal(x,y,z), up(x,y,z)
}
void toOrtho()
{
glViewport(0, 0, (GLsizei)screenWidth, (GLsizei)screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, screenWidth, 0, screenHeight, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void toPerspective()
{
glViewport(0, 0, (GLsizei)screenWidth, (GLsizei)screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, (float)(screenWidth)/screenHeight, 10.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void draw()
{
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);
for(int i=0;i<(int)Clist.size();i++){
glPushMatrix();
glTranslatef(Clist[i].x,Clist[i].y,Clist[i].z);
glColor3ub(0,0,255);
glutSolidCube(Clist[i].l);
glPopMatrix();
}
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w, int h)
{
screenWidth = w;
screenHeight = h;
toPerspective();
}
void timerCB(int millisec){
glutPostRedisplay();
}
void Motion(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 Mouse(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;
}
else if(button == GLUT_MIDDLE_BUTTON)
{
if(state == GLUT_DOWN)
{
mouseMiddleDown = true;
}
else if(state == GLUT_UP)
mouseMiddleDown = false;
}
}
void initGLUT(){
char *myargv[1];
int myargc = 1;
myargv[0]=strdup("MyOpenGL");
glutInit(&myargc,myargv);
glutInitDisplayMode( GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH |GLUT_STENCIL);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(850,100);
glutCreateWindow("Ricostruzione attuale");
glutDisplayFunc(draw);
glutTimerFunc(50,timerCB,50);
glutReshapeFunc(reshape);
glutMouseFunc(Mouse);
glutMotionFunc(Motion);
}
int main(int argc, char **argv)
{
....
initSharedMem();
initGLUT();
init();
glutMainLoop();
....
return 0;
}
Please, help me...I can't find a solution....