Qt 5.10 Book Examples
OGLQuad.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // OGLQuad.cpp
3 // ======================================================================
4 // This file is a part of the book
5 // "Qt 5.10 Professional programming with C++"
6 // http://qt-book.com
7 // ======================================================================
8 // Copyright (c) 2017 by Max Schlee
9 // ======================================================================
10 
11 #include <QOpenGLFunctions>
12 #include "OGLQuad.h"
13 
14 // ----------------------------------------------------------------------
15 OGLQuad::OGLQuad(QWidget* pwgt/*= 0*/) : QOpenGLWidget(pwgt)
16 {
17 }
18 
19 // ----------------------------------------------------------------------
20 /*virtual*/void OGLQuad::initializeGL()
21 {
22  QOpenGLFunctions* pFunc =
23  QOpenGLContext::currentContext()->functions();
24  pFunc->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
25 }
26 
27 // ----------------------------------------------------------------------
28 /*virtual*/void OGLQuad::resizeGL(int nWidth, int nHeight)
29 {
30  glMatrixMode(GL_PROJECTION);
31  glLoadIdentity();
32  glViewport(0, 0, (GLint)nWidth, (GLint)nHeight);
33  glOrtho(0, 100, 100, 0, -1, 1);
34 }
35 
36 // ----------------------------------------------------------------------
37 /*virtual*/void OGLQuad::paintGL()
38 {
39  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
40 
41  glBegin(GL_QUADS);
42  glColor3f(1, 0, 0);
43  glVertex2f(0, 100);
44 
45  glColor3f(0, 1, 0);
46  glVertex2f(100, 100);
47 
48  glColor3f(0, 0, 1);
49  glVertex2f(100, 0);
50 
51  glColor3f(1, 1, 1);
52  glVertex2f(0, 0);
53  glEnd();
54 }
virtual void initializeGL()
Definition: OGLQuad.cpp:20
OGLQuad(QWidget *pwgt=0)
Definition: OGLQuad.cpp:15
virtual void paintGL()
Definition: OGLQuad.cpp:37
virtual void resizeGL(int nWidth, int nHeight)
Definition: OGLQuad.cpp:28