应用程序的奇怪行为:从“开始”启动visual c ++按钮效果很好,从编译的exe OpenGL窗口冻结自身.. [英] Strange behaviour of application: launched from "start" button of visual c++ works well, from compiled exe OpenGL windows freeze itself..

查看:69
本文介绍了应用程序的奇怪行为:从“开始”启动visual c ++按钮效果很好,从编译的exe OpenGL窗口冻结自身..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助。这真的很奇怪,我尝试了几天和几天来解决这个问题,但是没有。



我做了一个使用OpenGL在windows中表示的项目一个载体中包含的一系列立方体。



我想问你这个问题的帮助:在我的笔记本上Fujitsu Lifebook A530,win 7 64bit,4GB RAM, intel P6100双核和visual c ++ 2010,项目编译正确,如果我启动exe文件,效果很好(我可以与OpenGL表示交互,旋转,缩放等等)慢,但有效。这是由于集成显卡,英特尔高清,如此便宜和低性能卡。



但是,我有台式电脑,英特尔i7 2600 3.40Ghz,8GB DDR3和Nvidia Quadro 4000卡,这个项目编译正确,但如果我启动exe文件,OpenGL windows被阻止,没有响应......



如果我从visual C ++ 2010启动按钮(绿色播放按钮),它以启动调试开始,项目运行良好,没有OpenGL问题(我可以旋转,缩放等).OpenGL窗口不会阻塞自身或其他。



为什么? Visual C ++ 2010的环境设置在桌面PC和笔记本中是一样的,同样的Windows 7 64bit专业版,同样的库(freeglut)...



我不能理解为什么......问题是什么以及如何解决它...为什么当从他的exe文件启动应用程序时,OpenGL windows被阻止,冻结...



这是OpenGL部分应用程序的代码:



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;
};

//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....

推荐答案

我已经解决了切换到Point Cloud Library的问题。谢谢大家。
I've resolved switching to Point Cloud Library. Thanks to all.


这篇关于应用程序的奇怪行为:从“开始”启动visual c ++按钮效果很好,从编译的exe OpenGL窗口冻结自身..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆