首页 文章

对于Windows 7中的C中的Qt,此范围中未声明'glutInitDisplayMode'

提问于
浏览
1

我正试图在C中使用Windows 7中的Qt Creator运行程序 . 我已经将GL / glut.h更改为GL / glu.h但是当我运行它时,我得到以下错误:C:\ CSC \ Qt \ Projects \ QTunes \ glwidget.h:51:错误:'GLUT_DOUBLE'不是在此范围内声明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

1 回答

  • 1

    你可以添加.pro文件:

    LIBS += -lglut
    

相关问题