gpt4 book ai didi

c++ - 'glutInitDisplayMode' 未在此范围内为 Windows 7 上的 C++ 中的 Qt 声明

转载 作者:太空宇宙 更新时间:2023-11-04 11:55:06 25 4
gpt4 key购买 nike

我正在尝试使用 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

最佳答案

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

LIBS += -lglut

关于c++ - 'glutInitDisplayMode' 未在此范围内为 Windows 7 上的 C++ 中的 Qt 声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16502325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com