私はチュートリアルに従って、qt で opengl の小さなコードを作成しています。リンクは http://www.youtube.com/watch?v=1nzHSkY4K18です。
しかし、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 は 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){
}