#include <QtOpenGL>
#include <QGLContext>
#include <QGLFormat>
#include <QGLShader>
#include <QGLShaderProgram>
#include <QDebug>
#include "GLWidget.h"
GLWidget
::GLWidget(QWidget *parent,
const QGLWidget *shareWidget, Qt
::WindowFlags f
){
/* Change to 3.0 and no triangle is drawn */
newFormat.setVersion(2,1);
setFormat(newFormat);
makeCurrent();
}
void GLWidget::initializeGL()
{
_backgroundColour = Qt::black;
_triangleColour = Qt::white;
_triangle.push_back(QVector3D(-0.75, 0.75, 0));
_triangle.push_back(QVector3D(-0.75, -0.75, 0));
_triangle.push_back(QVector3D(0.75, -0.75, 0));
}
void GLWidget::paintGL()
{
qglClearColor(_backgroundColour);
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, _triangle.constData());
glDrawArrays(GL_TRIANGLES, 0, 3);
}
void GLWidget::resizeGL(int width, int height)
{
int side = qMin(width, height);
int hoffset = (int)((width - side) / 2.0 + 0.5);
int voffset = (int)((height - side) / 2.0 + 0.5);
glViewport(hoffset, voffset, side, side);
}
#include <QtOpenGL>
#include <QGLContext>
#include <QGLFormat>
#include <QGLShader>
#include <QGLShaderProgram>
#include <QDebug>
#include "GLWidget.h"
GLWidget::GLWidget(QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f)
: QGLWidget(parent, shareWidget, f)
{
QGLFormat newFormat(format());
/* Change to 3.0 and no triangle is drawn */
newFormat.setVersion(2,1);
setFormat(newFormat);
makeCurrent();
}
void GLWidget::initializeGL()
{
_backgroundColour = Qt::black;
_triangleColour = Qt::white;
_triangle.push_back(QVector3D(-0.75, 0.75, 0));
_triangle.push_back(QVector3D(-0.75, -0.75, 0));
_triangle.push_back(QVector3D(0.75, -0.75, 0));
}
void GLWidget::paintGL()
{
qglClearColor(_backgroundColour);
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, _triangle.constData());
glDrawArrays(GL_TRIANGLES, 0, 3);
}
void GLWidget::resizeGL(int width, int height)
{
int side = qMin(width, height);
int hoffset = (int)((width - side) / 2.0 + 0.5);
int voffset = (int)((height - side) / 2.0 + 0.5);
glViewport(hoffset, voffset, side, side);
}
To copy to clipboard, switch view to plain text mode
Bookmarks