Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C++
struct Cpoint
{
    double x;
    double y;
    double z;
    double l;
};

//vettore per disegno
vector<Cpoint> Clist;

//loca è la struct per i punti
Cpoint loca;

/*          PARTE DELLE FUNZIONI THREAD         */

void PrepareVect(cubo * temp){

//se non ci sono sottocubi
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);
        }
}
//se i sottocubi ci sono
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);

//funzioni di inizializzazione e pulizia
bool initSharedMem();
void clearSharedMem();
void initLights();
void setCamera(float posX, float posY, float posZ, float targetX, float targetY, float targetZ);
void toOrtho();
void toPerspective();

//variabili e costanti
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;

///////////////////////////////////////////////////////////////////////////////
// Funzione inizializzazione OpenGL standard
///////////////////////////////////////////////////////////////////////////////
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();
}

///////////////////////////////////////////////////////////////////////////////
// Funzione di inizializzazione globale delle variabili
///////////////////////////////////////////////////////////////////////////////
bool initSharedMem()
{
screenWidth = SCREEN_WIDTH;
screenHeight = SCREEN_HEIGHT;

mouseLeftDown = mouseRightDown = mouseMiddleDown = false;
mouseX = mouseY = 0;

cameraAngleX = cameraAngleY = 0.0f;
//cameraDistance = CAMERA_DISTANCE;
cameraDistance = 0.3f;
drawMode = 0; // 0:pieno, 1: solo contorni, 2:punti

return true;
}

///////////////////////////////////////////////////////////////////////////////
// Funzione di pulitura variabili globali
///////////////////////////////////////////////////////////////////////////////
void clearSharedMem()
{
}

///////////////////////////////////////////////////////////////////////////////
// Inizializzazione Luci
///////////////////////////////////////////////////////////////////////////////
void initLights()
{
GLfloat lightKa[] = {.2f, .2f, .2f, 1.0f};  // luce ambientale
GLfloat lightKd[] = {.7f, .7f, .7f, 1.0f};  // luce diffusa
GLfloat lightKs[] = {1, 1, 1, 1};           // luce speculare

glLightfv(GL_LIGHT0, GL_AMBIENT, lightKa);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightKd);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightKs);

// posizione delle luci
float lightPos[4] = {0, 0, 20, 1}; 
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

//Attiva tutti i settaggi delle luci
glEnable(GL_LIGHT0);                        

}

///////////////////////////////////////////////////////////////////////////////
//  Posizione della telecamera e direzioni
///////////////////////////////////////////////////////////////////////////////
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); // eye(x,y,z), 

focal(x,y,z), up(x,y,z)
}

///////////////////////////////////////////////////////////////////////////////
// Impostazione proiezione ortogonale
///////////////////////////////////////////////////////////////////////////////
void toOrtho()
{
// Imposta il viewport di tutta la finestra
glViewport(0, 0, (GLsizei)screenWidth, (GLsizei)screenHeight);

// Imposta il frustum di visione
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, screenWidth, 0, screenHeight, -1, 1);

// passaggio a modelview per interattività
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}



///////////////////////////////////////////////////////////////////////////////
// Impostazione come perspective
///////////////////////////////////////////////////////////////////////////////
void toPerspective()
{
// Imposta il viewport di tutta la finestra
glViewport(0, 0, (GLsizei)screenWidth, (GLsizei)screenHeight);

//frustum perspective
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

//gluPerspective(60.0f, (float)(screenWidth)/screenHeight, 1.0f, 1000.0f);

gluPerspective(60.0f, (float)(screenWidth)/screenHeight, 10.0f, 0.0f); // FOV,    AspectRatio, NearClip, FarClip

// switch to modelview matrix in order to set scene
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

///////////////////////////////////////////////////////////////////////////////
// Funzione disegno principale
///////////////////////////////////////////////////////////////////////////////
void draw()
{

// clear buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glPushMatrix();

//spostamento del disegno
glTranslatef(0, 0, -cameraDistance);
glRotatef(cameraAngleX, 1, 0, 0);   // pitch
glRotatef(cameraAngleY, 0, 1, 0);   // heading

//lancio funzione di disegno vera e propria
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();  
             }
//reset
glPopMatrix();
glutSwapBuffers();

}

///////////////////////////////////////////////////////////////////////////////
//  Funzione di reshape
///////////////////////////////////////////////////////////////////////////////
void reshape(int w, int h)
{



 screenWidth = w;
   screenHeight = h;
   toPerspective();
}


//////////////////////////////////////////////////////////////////////////////
//  Funzione di refresh temporizzato della finestra
///////////////////////////////////////////////////////////////////////////////

void timerCB(int millisec){
//glutTimerFunc(millisec, timerCB, millisec);
glutPostRedisplay();
}

///////////////////////////////////////////////////////////////////////////////
// Funzione rilevamento movimenti del mouse
///////////////////////////////////////////////////////////////////////////////
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;
}
}

///////////////////////////////////////////////////////////////////////////////
// Funzione per rilevamento bottoni mouse
///////////////////////////////////////////////////////////////////////////////
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;
}
}

///////////////////////////////////////////////////////////////////////////////
// Inizializzazione di GLUT
///////////////////////////////////////////////////////////////////////////////
void initGLUT(){
//parametri fake per il lancio di InitGlut
char *myargv[1];
int myargc = 1;
myargv[0]=strdup("MyOpenGL");

//Inizializzazione Glut basso livello
glutInit(&myargc,myargv);

//Lancio funzioni di settaggio finestra,visualizzazione ed altro
glutInitDisplayMode( GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH |GLUT_STENCIL);    
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(850,100);
glutCreateWindow("Ricostruzione attuale");

    //callback delle funzioni richiamate
    glutDisplayFunc(draw);
    glutTimerFunc(50,timerCB,50);
    glutReshapeFunc(reshape);
    glutMouseFunc(Mouse);
    glutMotionFunc(Motion);

}

int main(int argc, char **argv)
{
   ....
// Lancia funzione di inizializzazione variabili globali
    initSharedMem();

    //initiGLUT
    initGLUT();
    init();

    //ciclo OpenGL
    glutMainLoop();
....
return 0;
}

Please, help me...I can't find a solution....
Posted
Comments
Rage 2-May-14 12:24pm    
This is not necessarily the hardware, but could very well be some memory handling problems (which could explain it behaves randomly in Release Mode and correctly in Debug Mode). Have you correctly deleted the objects you have been creating all through the program ?
Can you shrink it down until you have a part that works on your PC, just to try and find where it blocks ?
Rage 2-May-14 12:26pm    
Which version of OpenGL are you using ? You might check this :

https://developer.nvidia.com/opengl-driver

1 solution

I've resolved switching to Point Cloud Library. Thanks to all.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900