Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我想在qt creator(4.7)中编译这个文件_C++_Opengl_Picking - Fatal编程技术网

C++ 我想在qt creator(4.7)中编译这个文件

C++ 我想在qt creator(4.7)中编译这个文件,c++,opengl,picking,C++,Opengl,Picking,我是使用Qt和OpenGl的新手,我想编译这个文件,但我不能。我真的很想试试这个例子,因为我想了解“拣选函数”是如何工作的。我该怎么办 这是代码:(你可以在这里找到:) //picksquare.cpp //演示了使用多个名称和拾取。 //绘制了一个3x3的正方形网格。当鼠标左键 //按下按钮,光标位置下的所有方块 //他们的颜色变了。 //作者特拉维斯·阿斯特尔 //2001年10月19日 #包括 #包括 #包括 集成电路板[3][3];/*每个正方形的颜色量*/ GLuint ii=0,jj

我是使用Qt和OpenGl的新手,我想编译这个文件,但我不能。我真的很想试试这个例子,因为我想了解“拣选函数”是如何工作的。我该怎么办

这是代码:(你可以在这里找到:)

//picksquare.cpp
//演示了使用多个名称和拾取。
//绘制了一个3x3的正方形网格。当鼠标左键
//按下按钮,光标位置下的所有方块
//他们的颜色变了。
//作者特拉维斯·阿斯特尔
//2001年10月19日
#包括
#包括
#包括
集成电路板[3][3];/*每个正方形的颜色量*/
GLuint ii=0,jj=0,名称,*ptr;
//Picksquare类声明
类Picksquare:publicqglwidget
{
公众:
Picksquare(QWidget*父项=0,常量字符*名称=0):
QGLWidget(父项,名称){};
受保护的:
无效初始化EGL(无效);
无效尺寸(整数w,整数h);
void paintGL();
空心正方形(格伦模式);
无效按键事件(QKeyEvent*e);
void processHits(闪烁命中,GLuint缓冲[]);
无效鼠标压力事件(QMouseEvent*e);
};
//初始化根据现有初始化函数代码改编的函数
void Picksquare::initializeGL(void)
{
int i,j;
对于(i=0;i<3;i++)
对于(j=0;j<3;j++)
板[i][j]=0;
glClearColor(0.0,0.0,0.0,0.0);
}
//绘制功能以替换显示功能
void Picksquare::paintGL(void)
{
glClear(GLU颜色缓冲位);
绘图方块(GL_渲染);
glFlush();
}
/*画了九个正方形。在选择模式下,每个
*正方形有两个名称:一个用于行,另一个用于行
*其他用于网格上的柱。每种颜色
*正方形由其在网格上的位置确定,并且
*线路板[][]数组中的值。
*/
void Picksquare::drawSquares(格伦模式)
{
GLuint i,j;
对于(i=0;i<3;i++){
如果(模式==GL\U选择)
姓名(i);
对于(j=0;j<3;j++){
如果(模式==GL\U选择)
姓名(j);
glColor3f((GLfloat)i/3.0,(GLfloat)j/3.0,
(i)[j]/3.0);
glRecti(i,j,i+1,j+1);
如果(模式==GL\U选择)
glPopName();
}
}
}
//根据重塑功能代码调整功能大小
void Picksquare::resizeGL(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_投影);
glLoadIdentity();
gluOrtho2D(0.0,3.0,0.0,3.0);
glMatrixMode(GLU模型视图);
glLoadIdentity();
}
//processHits更改选定框的颜色
void Picksquare::processHits(闪烁命中,GLuint缓冲区[])
{
无符号整数i,j;
GLuint ii,jj,名称,*ptr;
printf(“hits=%d\n”,hits);
ptr=(GLuint*)缓冲区;
对于(i=0;ibutton()!=LeftButton)/| | state!=GLUT|u DOWN)
返回;
glGetIntegerv(GL_视口,视口);
glSelectBuffer(BUFSIZE,selectBuf);
(无效)glRenderMode(GL_选择);
glInitNames();
glPushName(0);
glMatrixMode(GL_投影);
glPushMatrix();
glLoadIdentity();
//在光标位置附近创建5x5像素拾取区域
gluPickMatrix((GLdouble)e->x(),(GLdouble)(视口[3]-e->y()),
5.0、5.0、视口);
gluOrtho2D(0.0,3.0,0.0,3.0);
绘图方块(GL_选择);
glMatrixMode(GL_投影);
glPopMatrix();
glFlush();
hits=glRenderMode(GLU渲染);
processHits(hits,选择buf);
更新();
} 
//Picksquare函数由键盘函数改编而来。此函数具有
//已修改为接受一个参数(键盘输入),而不是三个
//在键盘函数中完成的参数。
void Picksquare::keyPressEvent(QKeyEvent*e)
{
开关(e->key()){
案例27:
出口(0);
打破
}
}
/*主回路
*打开具有初始窗口大小、标题栏、,
*颜色索引显示模式,并处理输入事件。
*/
int main(int argc,字符**argv)
{
QApplication::setColorSpec(QApplication::CustomColor);
质量保证申请a(argc、argv);
如果(!QGLFormat::hasOpenGL()){
qWarning(“此系统不支持OpenGL。正在退出”);
返回-1;
}
皮克广场w;
a、 setMainWidget&w;
w、 show();
返回a.exec();
}

为什么不能编译它?@trojanfoe的意思是,编译器的输出消息是什么?没有任何进一步的信息(你尝试了什么,你到底在哪里遇到了问题),这个问题太弱了,无法回答。请添加更多信息,这样它就不会被关闭。另外,qt creator不是编译器。它是一个IDE,只是一个前端,与编译无关。
//          picksquare.cpp
//   Use of multiple names and picking are demonstrated.  
//   A 3x3 grid of squares is drawn.  When the left mouse 
//   button is pressed, all squares under the cursor position 
//   have their color changed.
//   Author  Travis Astle
//   Oct 19, 2001

#include <qgl.h>
#include <qapplication.h>
#include <qkeycode.h>

int board[3][3];   /*  amount of color for each square  */

GLuint ii =0, jj=0, names, *ptr;

// Picksquare class declaration

class Picksquare : public QGLWidget
{
public:
    Picksquare( QWidget *parent=0, const char *name=0 ) :
        QGLWidget(parent, name) {};
protected:
    void initializeGL(void);
    void resizeGL( int w, int h );
    void paintGL();
    void drawSquares(GLenum mode);
    void keyPressEvent( QKeyEvent *e);
    void processHits (GLint hits, GLuint buffer[]);
    void mousePressEvent(QMouseEvent *e);

};

// Initialize function adapted from existing init function code

void Picksquare::initializeGL(void)
{
   int i, j;
   for (i = 0; i < 3; i++) 
      for (j = 0; j < 3; j ++)
         board[i][j] = 0;
   glClearColor (0.0, 0.0, 0.0, 0.0);
}

// Paint function to replace the display function

void Picksquare::paintGL(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   drawSquares (GL_RENDER);
   glFlush();
}

/*  The nine squares are drawn.  In selection mode, each 
 *  square is given two names:  one for the row and the 
 *  other for the column on the grid.  The color of each 
 *  square is determined by its position on the grid, and 
 *  the value in the board[][] array.
 */

void Picksquare::drawSquares(GLenum mode)
{
   GLuint i, j;
   for (i = 0; i < 3; i++) {
      if (mode == GL_SELECT)
         glLoadName (i);
      for (j = 0; j < 3; j ++) {
         if (mode == GL_SELECT)
            glPushName (j);
         glColor3f ((GLfloat) i/3.0, (GLfloat) j/3.0, 
                    (GLfloat) board[i][j]/3.0);
         glRecti (i, j, i+1, j+1);
         if (mode == GL_SELECT)
            glPopName ();
      }
   }
}

// Resize function adapted from reshape function code

void Picksquare::resizeGL(int w, int h)
{
   glViewport(0, 0, w, h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluOrtho2D (0.0, 3.0, 0.0, 3.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}

//  processHits changes color of selected boxes

void Picksquare::processHits (GLint hits, GLuint buffer[])
{
   unsigned int i, j;
   GLuint ii, jj, names, *ptr;

   printf ("hits = %d\n", hits);
   ptr = (GLuint *) buffer;
   for (i = 0; i < hits; i++) { /*  for each hit  */
      names = *ptr;
      printf (" number of names for this hit = %d\n", names); ptr++;
      printf("  z1 is %g;", (float) *ptr/0x7fffffff); ptr++;
      printf(" z2 is %g\n", (float) *ptr/0x7fffffff); ptr++;
      printf ("   names are ");
      for (j = 0; j < names; j++) { /*  for each name */
         printf ("%d ", *ptr);
         if (j == 0)  /*  set row and column  */
            ii = *ptr;
         else if (j == 1)
            jj = *ptr;
         ptr++;
      }
      printf ("\n");
      board[ii][jj] = (board[ii][jj] + 1) % 3;
   }
}


/*  pickSquares() sets up selection mode, name stack, 
 *  and projection matrix for picking.  Then the 
 *  objects are drawn.
 */
#define BUFSIZE 512

void Picksquare::mousePressEvent(QMouseEvent *e)

{
   GLuint selectBuf[BUFSIZE];
   GLint hits;
   GLint viewport[4];

   if (e-> button() != LeftButton) //|| state != GLUT_DOWN)
      return;

   glGetIntegerv (GL_VIEWPORT, viewport);

   glSelectBuffer (BUFSIZE, selectBuf);
   (void) glRenderMode (GL_SELECT);

   glInitNames();
   glPushName(0);

   glMatrixMode (GL_PROJECTION);
   glPushMatrix ();
   glLoadIdentity ();

//  create 5x5 pixel picking region near cursor location        

   gluPickMatrix ((GLdouble) e->x(), (GLdouble) (viewport[3] - e->y()), 
                  5.0, 5.0, viewport);
   gluOrtho2D (0.0, 3.0, 0.0, 3.0);
   drawSquares (GL_SELECT);

   glMatrixMode (GL_PROJECTION);
   glPopMatrix ();
   glFlush ();

   hits = glRenderMode (GL_RENDER);
   processHits (hits, selectBuf);
   update();
} 

// Picksquare function adaped from keyboard function.  This function has
// been modified to accept one argument (the keyboard input), instaed of three
// arguments as is was done in the keyboard function.

void Picksquare::keyPressEvent(QKeyEvent *e)
{
   switch (e -> key()) {
      case 27:
         exit(0);
         break;
   }
}
/*  Main Loop
 *  Open window with initial window size, title bar, 
 *  color index display mode, and handle input events.
 */
int main( int argc, char **argv )
{
    QApplication::setColorSpec( QApplication::CustomColor );
    QApplication a( argc, argv );

    if ( !QGLFormat::hasOpenGL() ) {
        qWarning( "This system has no OpenGL support. Exiting." );
        return -1;
    }

    Picksquare w;
    a.setMainWidget( &w );
    w.show();
    return a.exec();
}