-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowtriangle.cpp
More file actions
66 lines (52 loc) · 1.34 KB
/
showtriangle.cpp
File metadata and controls
66 lines (52 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "showtriangle.h"
#include <QPainter>
#include <QPen>
ShowTriangle::ShowTriangle(QWidget *parent)
:QOpenGLWidget(parent)
{
}
//----------override funtion----------
//
//------------------------------------
void ShowTriangle::initializeGL()
{
initializeOpenGLFunctions();
glClearColor(0.0f,0.0f,0.0f,1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
}
void ShowTriangle::resizeGL(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, (float)w/h, 0.01, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
}
void ShowTriangle::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-0.5, -0.5, 0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f( 0.5, -0.5, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f( 0.0, 0.5, 0);
glEnd();
// render text in widget
glDisable(GL_DEPTH_TEST);
QPainter painter;
painter.begin(this);
QPen pen;
pen.setColor(Qt::red);
painter.setPen(pen);
painter.drawText(100, 100, "Hello Triangle");
painter.end();
glEnable(GL_DEPTH_TEST);
}