为什么OpenGl菜单在Centos 7上出现异常

时间:2019-03-01 22:31:16

标签: c opengl menu centos7 glut

我已经使用OpenGL为Centos 6编写了一个程序。在最新的Centos 6安装上运行良好。现在,我升级到了最新版本的Centos 7,还安装了gcc 8.3.0。我可以很好地编译该程序,并且可以运行,但是当右键单击菜单使用菜单时,不再选择菜单项。为此,我必须再次按鼠标右键。另外,覆盖菜单部分在背景图像上留下较暗的边框。其余的OpenGL似乎可以正常工作。可能是什么原因造成的?

编译行:

gcc -O3 -m64 -ftree-vectorize -mtune=native -march=native -mfpmath=387 -mpc80 -pedantic -fopenmp -mcmodel=large -funroll-loops -flto $1.c -o $1 -L/usr/local/lib -lGL -lglut -lGLU -lm -lgmp

我没有编译任何GL库。

yum list installed | grep -i libGL

glade3-libgladeui.x86_64                2:3.8.3-6.el7                  @base

libGLEW.x86_64                          1.10.0-5.el7                   @base

libGLEWmx.x86_64                        1.10.0-5.el7                   @base

libglade2.x86_64                        2.6.4-11.el7                   @anaconda

libglade2-devel.x86_64                  2.6.4-11.el7                   @base

libglvnd.x86_64                         1:1.0.1-0.8.git5baa1e5.el7     @anaconda

libglvnd-core-devel.x86_64              1:1.0.1-0.8.git5baa1e5.el7     @anaconda

libglvnd-devel.x86_64                   1:1.0.1-0.8.git5baa1e5.el7     @anaconda

libglvnd-egl.x86_64                     1:1.0.1-0.8.git5baa1e5.el7     @anaconda

libglvnd-gles.x86_64                    1:1.0.1-0.8.git5baa1e5.el7     @anaconda

libglvnd-glx.x86_64                     1:1.0.1-0.8.git5baa1e5.el7     @anaconda

libglvnd-opengl.x86_64                  1:1.0.1-0.8.git5baa1e5.el7     @anaconda

mesa-libGL.x86_64                       18.0.5-4.el7_6                 @updates

mesa-libGL-devel.x86_64                 18.0.5-4.el7_6                 @updates

mesa-libGLES.x86_64                     18.0.5-4.el7_6                 @updates

mesa-libGLES-devel.x86_64               18.0.5-4.el7_6                 @updates

mesa-libGLU.x86_64                      9.0.0-4.el7                    @anaconda

mesa-libGLU-devel.x86_64                9.0.0-4.el7                    @anaconda

mesa-libGLw.x86_64                      8.0.0-4.el7                    @anaconda

mesa-libGLw-devel.x86_64                8.0.0-4.el7                    @anaconda

mesa-libglapi.x86_64                    18.0.5-4.el7_6                 @updates

pygtk2-libglade.x86_64                  2.24.0-9.el7                   @anaconda

yum list installed | grep -i glut

freeglut.x86_64                         3.0.0-8.el7                    @anaconda

freeglut-devel.x86_64                   3.0.0-8.el7                    @anaconda

printf(“%s \ n”,glGetString(GL_VERSION)) 4.6.0 NVIDIA 410.93

显示问题的示例程序

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <GL/glut.h>
#include <GL/freeglut.h>

#define DEFAULTWINDOWSIZEX 2728
#define DEFAULTWINDOWSIZEY 2046

int M2DWindow;
int M2DWindowSizeX = DEFAULTWINDOWSIZEX, M2DWindowSizeY = DEFAULTWINDOWSIZEY;
int Menuitem = -1;
long verbose = 2;
int MouseXOld = -1, MouseYOld = -1;
int TwoDMenu;

static inline void HandleKeyInput2D ( unsigned char, int, int );
static inline void HandleSpecialKeyInput ( int, int, int );
void Handle2DWindowReshape ( int, int );
void Handle2DWindowMouse ( int, int, int, int );
void MovingMouse ( int, int );
void Handle2DMenu ( int );
void Handle2DMenu2 ( int );

void HandleKeyInput2D ( unsigned char key, int mousex, int mousey )
{
   if ( verbose >= 2 ) {
      printf ( "\nHandleKeyInput2D\n" );
      printf ( "Key %c (numeric %d) pressed\n", key, (int) key );
   }
}

void Handle2DWindowMouse ( int button, int mousestate, int mousex, int mousey )
{
   if ( verbose >= 2 )
   printf ( "\nHandle2DWindowMouse Starts: Button %d, state %2d, x %d, y %d\n",
   button, mousestate, mousex, mousey );
}

void MovingMouse ( int mousex, int mousey )
{
   if ( verbose >= 2 ) printf ( "\nMovingMouse starts: xold %d, yold %d, xnew %d, ynew %d\n", MouseXOld,
   MouseYOld, mousex, mousey );
   if ( verbose >= 2 ) printf ( "\nMovingMouse ends\n" );
}

void HandleSpecialKeyInput ( int key, int mousex, int mousey )
{
   if ( verbose >= 2 ) printf ( "\nHandleSpecialKeyInput: Key %d\n", key );
}

void Handle2DWindowReshape ( int x, int y )
{
   if ( verbose >= 2 ) printf ( "\nHandle2DWindowReshape: %d %d\n", x, y );
}

void Handle2DMenu ( int menuitem )
{
   if ( verbose >= 2 ) printf ( "\nHandle2DMenu: Menu Item %d selected\n", menuitem );
   Menuitem = menuitem;
}

void Update2D ()
{
  if ( verbose >= 2 ) printf ( "\nUpdate2D start 2DWindowSizeX %d 2DWindowSizeY %d\n",
  M2DWindowSizeX, M2DWindowSizeY );
}

void InitMenus ()
{
   glutSetWindow ( M2DWindow ); 
   TwoDMenu = glutCreateMenu ( Handle2DMenu );
   glutAddMenuEntry( "Zoom in to 10%", 70 );
   glutAddMenuEntry( "Zoom out to 1000%", 71 );
   glutAttachMenu ( GLUT_RIGHT_BUTTON );
}

void Handle2DMenu2 ( int menuitem )
{
   if ( verbose >= 2 ) printf ( "\nHandle2DMenu2: Menu Item %d selected\n", menuitem );
}

void Init2DWindow ()
{
   glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
   glutInitWindowPosition ( 900, 100 );
   glutInitWindowSize ( M2DWindowSizeX, M2DWindowSizeY );
   M2DWindow = glutCreateWindow ( "2D" );
   glutDisplayFunc ( Update2D );
   glClearColor ( 0.0, 0.0, 0.0, 0.0 );
   glClear (GL_COLOR_BUFFER_BIT);
   glutSwapBuffers();
   glClear (GL_COLOR_BUFFER_BIT);
   glFlush ();
   glutKeyboardFunc ( HandleKeyInput2D );
   glutMouseFunc ( Handle2DWindowMouse );
   glutMotionFunc ( MovingMouse );
   glutSpecialFunc ( HandleSpecialKeyInput );
   glutReshapeFunc ( Handle2DWindowReshape );
}

void MainLoop ()
{
   glutSetWindow ( M2DWindow );
   if ( Menuitem >= 0 ) {
      if ( verbose >= 2 ) printf ( "\nMainLoop: Menu item %d processing starts...", Menuitem);
      Handle2DMenu2 ( Menuitem );
      if ( verbose >= 2 ) printf ( "\nMainLoop: Menu item %d processing ends", Menuitem );
      Menuitem = -1;
   }
}

int main ( int argc, char * argv [])
{
   setbuf ( stdout, NULL );
   glutInit ( &argc, argv );
   Init2DWindow ();
   InitMenus ();
   glutIdleFunc ( MainLoop );
   printf("%s\n%s\n%s\n", glGetString(GL_VERSION),glGetString(GL_VENDOR),glGetString(GL_RENDERER));
   glutMainLoop ();
   return ( 0 );
}

编译为 gcc -g -m64 -mtune = native -march = native testmenu.c -I / usr / local / lib / gcc / x86_64-pc-linux-gnu / 8.3.0 / include -o testmenu -L / usr / local / lib64 -L / usr / local / lib -lGL -lglut -lGLU

0 个答案:

没有答案