2013-03-28 72 views
1

我關注的教程寫一小塊的OpenGL代碼qt.here的鏈接 http://www.youtube.com/watch?v=1nzHSkY4K18QT glBegin沒有聲明?

但是當我bluid代碼的6:13它顯示了幾個錯誤的認爲

..\testopgl\glwidget.cpp: In member function 'virtual void GLWidget::paintGL()': 
..\testopgl\glwidget.cpp:17:20: error: 'glColor3f' was not declared in this scope 
..\testopgl\glwidget.cpp:19:25: error: 'glBegin' was not declared in this scope 
..\testopgl\glwidget.cpp:20:31: error: 'glVertex3f' was not declared in this scope 
..\testopgl\glwidget.cpp:23:11: error: 'glEnd' was not declared in this scope 
..\testopgl\glwidget.cpp: At global scope: 

我真的不明白的是,當我只把glClear(GL_COLOR_BUFFER_BIT)它建立正常的,但是會出現誤差,即使我只是把glColor3f(),請問GLWidget不支持日e glColor *()或glBegin()命令?

這是我的代碼。

testopgl.pro

#------------------------------------------------- 
# 
# Project created by QtCreator 2013-03-28T09:48:44 
# 
#------------------------------------------------- 

QT  += core gui opengl 

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 

TARGET = testopgl 
TEMPLATE = app 


SOURCES += main.cpp\ 
     mainwindow.cpp \ 
    glwidget.cpp 

HEADERS += mainwindow.h \ 
    glwidget.h 

FORMS += mainwindow.ui 

glwidget.h

#ifndef GLWIDGET_H 
#define GLWIDGET_H 

#include <QGLWidget> 

class GLWidget : public QGLWidget 
{ 
    Q_OBJECT 
public: 
    explicit GLWidget(QWidget *parent = 0); 

    void initializeGL(); 
    void paintGL(); 
    void resizeGL(int w,int h); 
}; 

#endif // GLWIDGET_H 

glwidget.cpp

#include "glwidget.h" 


GLWidget::GLWidget(QWidget *parent) : 
    QGLWidget(parent) 
{ 
} 

void GLWidget::initializeGL(){ 
    glClearColor(1,1,0,1); 
} 

void GLWidget::paintGL(){ 
    glClear(GL_COLOR_BUFFER_BIT); 


    glColor3f(1,0,0); 

    glBegin(GL_TRIANGLES); 
     glVertex3f(-0.5,-0.5,0); 
     glVertex3f(0.5,-0.5,0); 
     glVertex3f(0.0,0.5,0); 
    glEnd(); 


} 

void GLWidget::resizeGL(int w,int h){ 

} 

回答

2

你提到的功能根本就沒有出現在任何現代版GL的,所以您所聽到的教程聽起來很不合時宜。

因此,通過QT構建版暴露的GL版本可能沒有這些功能。可能重新配置/重建QT以使用舊版本的GL,但我會建議開始瞭解並使用現代可編程接口。

+0

謝謝JasonD.I發現了另一個教程,它也如你所說的說。 – 2013-03-28 07:13:48