1

我正在尝试使用 C++ 在 Windows 7 上的 Qt Creator 中运行程序。我已将 GL/glut.h 更改为 GL/glu.h 但是当我运行它时,出现以下错误: C:\CSC\Qt\Projects\QTunes\glwidget.h:51: error: 'GLUT_DOUBLE' was not在此范围内声明 C:\CSC\Qt\Projects\QTunes\glwidget.h:51: 错误: 'GLUT_RGB' 未在此范围内声明 C:\CSC\Qt\Projects\QTunes\glwidget.h:51: 错误: 'GLUT_DEPTH' 未在此范围内声明 C:\CSC\Qt\Projects\QTunes\glwidget.h:51: 错误: 'glutInitDisplayMode' 未在此范围内声明

这是我在 stackvoerflow 上的第一篇文章,如果格式不正确,很抱歉,但这里是代码:

#ifndef MyGLDRAWER_H
#define MyGLDRAWER_H

#include <fstream>
#include <cmath>
#include <cassert>
#include <cstring>
#include <GL/glu.h>
#include <QGLWidget>
#include <iostream>
#include <QKeyEvent>
#include <QDebug>

using namespace std;

// user-defined datatypes
typedef float vector3f[3];
typedef struct {
int     width;
int     height;
GLuint      texId;
char        imageFilename[512];
} Record;

// global variables

// I made these values static because I could not compile the code without doing so.
// I have preserved the function of the program, by doing so.
// It shouldn't be much of a problem having them that way.

static Record  *_records;       // list of records (albums)
static int   _recordCount;      // number of records
static int   _shift = 0;
static float     _scrollOffset=0;   // -1<offset<1 current scroll position
static int   _scrollDir;        // current scroll velocity
static float     _scrollTime = 150; // total scrolling time (per push)
static int   _scrollUpdateInterval = 5; // scrolling time increment
static int   _bScrolling=0;     // scrolling boolean: 1=true; 0=false
static int   _Timer;

 class MyGLDrawer : public QGLWidget
 {
     Q_OBJECT        // must include this if you use Qt signals/slots

public:
     MyGLDrawer(QWidget *parent)
         : QGLWidget(parent) {

         qDebug()<<"porkydorky";
    initRecords();
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
    setMouseTracking(true);
    setFocusPolicy(Qt::StrongFocus);
}



protected:

    void initRecords();
    void display();
    //void resize(int,int); resizeGL
    void keyPress(unsigned char, int, int);
    void specialKeyPress(int, int, int);
    void scrollRecords(int);
    void scrollTimer(int);
    void drawRecords();
    void drawRecord (Record*, bool flip = true);
    //void quit();
    int  readPPM(char*, int&, int&, unsigned char *&);


    void initializeGL() // virtual function copied from
    {

    glEnable(GL_DEPTH_TEST);
    glClearColor(0,0,0,0);

    // load textures
    glEnable(GL_TEXTURE_2D);
    int     ww, hh;
    unsigned char  *texData;
    for(int i=0; i<_recordCount; i++)
    {
        readPPM(_records[i].imageFilename, ww, hh, texData);
        glGenTextures  (1, &_records[i].texId);
        glBindTexture  (GL_TEXTURE_2D,  _records[i].texId);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexImage2D   (GL_TEXTURE_2D, 0, 3, ww, hh, 0, GL_RGB,
            GL_UNSIGNED_BYTE, texData);

    }
    glDisable(GL_TEXTURE_2D);

    }
void resizeGL(int width, int height) // virtual function. must be defined in .h file
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90., (float) width/height, 1.0, 1000);
    glMatrixMode(GL_MODELVIEW);
}
void paintGL()
{
    display();
}

void timerEvent(QTimerEvent *event)
{
    scrollTimer(0);

}

void keyPressEvent( QKeyEvent *k )
{    

switch ( k->key()){
case Qt::Key_Right:
    scrollRecords(1);
    break;
case Qt::Key_Left:
    scrollRecords(-1);
   break;
}
//scrollRecords(1);
}


 };

#endif
4

1 回答 1

1

您可以在 .pro 文件中添加:

LIBS += -lglut
于 2015-01-08T05:57:05.047 回答