C++ 上的 OpenGL VS2008:即使在同一台计算机上,相同的代码也会有不同的行为

发布于 2024-12-11 09:01:43 字数 2291 浏览 0 评论 0原文

我有两个完全相同的代码 OpenGL C++,在不同的项目中使用 VS2008 编译,但是当我编译它们时,它的行为不同。其中之一可以识别条件 if ( mod == GLUT_ACTIVE_CTRL && button == GLUT_WHEEL_UP ) 而其中之一则不能。

这是完整的功能:

void mouse(int button, int state, int x, int y) {

int mod = glutGetModifiers();
mouseState = state;
mouseButton = button;
double modelview[16], projection[16];

int viewport[4];
float z = 0 ;

/*Read the projection, modelview and viewport matrices
using the glGet functions.*/
glGetIntegerv( GL_VIEWPORT, viewport );
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
//glGetDoublev( GL_PROJECTION_MATRIX, projection );

//Read the window z value from the z-buffer 
glReadPixels( x, viewport[3]-y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z );   

// Used for wheels, has to be up    
if (state == GLUT_UP )  {       
    if ( mod == GLUT_ACTIVE_CTRL && button == GLUT_WHEEL_UP ){                  
        printf("Wheel Up\n");
        zoom += 0.1;
    }
    else if (mod == GLUT_ACTIVE_CTRL &&  button == GLUT_WHEEL_DOWN ){
        printf("Wheel Down\n"); 
        zoom -= 0.1;
    }


    else if (mod == GLUT_ACTIVE_ALT && button == GLUT_WHEEL_UP) {
        //printf("Z++\n");
        translation_z = translation_z + 0.1;
        //printf("Z = %f", translation_z);
    }

    else if (mod == GLUT_ACTIVE_ALT && button == GLUT_WHEEL_DOWN) {
        //printf("Z--\n");
        translation_z = translation_z - 0.1;
    }

    else if (mod == GLUT_ACTIVE_SHIFT && button == GLUT_WHEEL_UP) {
        //printf("Shift Wheel Up. Z axis rotation goes here.\n");
        zrotation += (5*(z - oldZ)); // about x-axis
    }

    else if (mod == GLUT_ACTIVE_SHIFT && button == GLUT_WHEEL_DOWN) {
        //printf("Shift Wheel Down. Z Axis rotation goes here\n");
        zrotation -= (5*(z - oldZ)); // about x-axis
        //translation_z = translation_z - 0.1;
    }


}
else if (state == GLUT_DOWN) {
    //printf("Glut Down before z processing\n");

    if (button == GLUT_LEFT_BUTTON){
        cursorX = x;
        cursorY = y;
        mode = SELECT;
        //printf("Left is down\n");
    }

    oldX = x;
    oldY = y;
}
}

`

并且我在此处上传了两个项目

I have two exact same codes OpenGL C++ , compiled using VS2008 in different project , but when i compile them, it behaves differently. One of them can recognize the condition if ( mod == GLUT_ACTIVE_CTRL && button == GLUT_WHEEL_UP ) and one of them is not.

Here is the complete function:

void mouse(int button, int state, int x, int y) {

int mod = glutGetModifiers();
mouseState = state;
mouseButton = button;
double modelview[16], projection[16];

int viewport[4];
float z = 0 ;

/*Read the projection, modelview and viewport matrices
using the glGet functions.*/
glGetIntegerv( GL_VIEWPORT, viewport );
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
//glGetDoublev( GL_PROJECTION_MATRIX, projection );

//Read the window z value from the z-buffer 
glReadPixels( x, viewport[3]-y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z );   

// Used for wheels, has to be up    
if (state == GLUT_UP )  {       
    if ( mod == GLUT_ACTIVE_CTRL && button == GLUT_WHEEL_UP ){                  
        printf("Wheel Up\n");
        zoom += 0.1;
    }
    else if (mod == GLUT_ACTIVE_CTRL &&  button == GLUT_WHEEL_DOWN ){
        printf("Wheel Down\n"); 
        zoom -= 0.1;
    }


    else if (mod == GLUT_ACTIVE_ALT && button == GLUT_WHEEL_UP) {
        //printf("Z++\n");
        translation_z = translation_z + 0.1;
        //printf("Z = %f", translation_z);
    }

    else if (mod == GLUT_ACTIVE_ALT && button == GLUT_WHEEL_DOWN) {
        //printf("Z--\n");
        translation_z = translation_z - 0.1;
    }

    else if (mod == GLUT_ACTIVE_SHIFT && button == GLUT_WHEEL_UP) {
        //printf("Shift Wheel Up. Z axis rotation goes here.\n");
        zrotation += (5*(z - oldZ)); // about x-axis
    }

    else if (mod == GLUT_ACTIVE_SHIFT && button == GLUT_WHEEL_DOWN) {
        //printf("Shift Wheel Down. Z Axis rotation goes here\n");
        zrotation -= (5*(z - oldZ)); // about x-axis
        //translation_z = translation_z - 0.1;
    }


}
else if (state == GLUT_DOWN) {
    //printf("Glut Down before z processing\n");

    if (button == GLUT_LEFT_BUTTON){
        cursorX = x;
        cursorY = y;
        mode = SELECT;
        //printf("Left is down\n");
    }

    oldX = x;
    oldY = y;
}
}

`

and I uploaded both of the project here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪之魂 2024-12-18 09:01:43

源和项目设置似乎完全相同。
不过,我看不到任何添加的包含路径,您在两个项目中本地都有 opengl 的副本吗?

我现在能想到的唯一一件事就是来自您来源的评论...

//Use patched version of GLUT (http://www.realmtech.net/opengl/glut.php) in case the wheel interaction does not work.

1)这听起来可能与您遇到的确切问题有关。

2)您是否可能在一个项目中使用该修补版本,但在另一个项目中没有使用?

编辑:
在其中一个项目中,您将滚轮向下和滚轮向上的 printf 行注释掉了,这是您如何判断人们不认识滚轮的吗?

Both the source and the project settings appear to be exactly the same.
I can't see any added include paths though, do you have a copy of opengl locally in both projects?

Only other thing I can think of right now is this comment from your source...

//Use patched version of GLUT (http://www.realmtech.net/opengl/glut.php) in case the wheel interaction does not work.

1) This sounds like it might relate to the exact problem you are having.

2) Did you maybe use that patched version in one project, but not the other?

Edit:
In one of the projects you have the printf lines for wheel down and wheel up commented out, is this by any chance how you tell that one doesn't recognize the wheel?

南风起 2024-12-18 09:01:43

我发现问题,在无法识别滚轮向上/向下条件的项目中(尽管它应该),我包含:

freeglut.lib glut32.lib opengl32.lib user32.lib

这可以通过仅包含以下库来解决:

opengl32.lib user32.lib

感谢@melak47 建议检查项目设置。

I found the problem, In the project that can not recognize wheel up/down condition (despite that it should), I included:

freeglut.lib glut32.lib opengl32.lib user32.lib

This can be solved by including only the following libs:

opengl32.lib user32.lib

Thank you @melak47 for suggesting to check the project settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文