Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/samples/gles1/FlatShading.cpp
2578 views
1
//
2
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
7
// Based on Hello_Triangle.c from
8
// Book: OpenGL(R) ES 2.0 Programming Guide
9
// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
10
// ISBN-10: 0321502795
11
// ISBN-13: 9780321502797
12
// Publisher: Addison-Wesley Professional
13
// URLs: http://safari.informit.com/9780321563835
14
// http://www.opengles-book.com
15
16
#include "SampleApplication.h"
17
18
#include <algorithm>
19
20
#include "util/gles_loader_autogen.h"
21
22
class FlatShadingSample : public SampleApplication
23
{
24
public:
25
FlatShadingSample(int argc, char **argv)
26
: SampleApplication("FlatShadingSample", argc, argv, 1, 0)
27
{}
28
29
bool initialize() override
30
{
31
glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
32
mRotDeg = 0.0f;
33
34
return true;
35
}
36
37
void draw() override
38
{
39
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
40
41
GLfloat vertices[] = {
42
-0.5f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f,
43
0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f,
44
};
45
46
GLfloat colors[] = {
47
1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
48
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
49
};
50
51
GLuint indices[] = {
52
0, 1, 2, 2, 3, 0,
53
54
4, 1, 0, 4, 2, 1, 4, 3, 2, 4, 0, 3,
55
};
56
57
glEnable(GL_DEPTH_TEST);
58
59
glEnableClientState(GL_VERTEX_ARRAY);
60
glEnableClientState(GL_COLOR_ARRAY);
61
glVertexPointer(3, GL_FLOAT, 0, vertices);
62
glColorPointer(4, GL_FLOAT, 0, colors);
63
64
for (int i = 0; i < 6; i++)
65
{
66
for (int j = 0; j < 6; j++)
67
{
68
if ((i + j * 6) % 2 == 0)
69
{
70
glShadeModel(GL_FLAT);
71
}
72
else
73
{
74
glShadeModel(GL_SMOOTH);
75
}
76
77
glPushMatrix();
78
79
glTranslatef(-0.7f + i * 0.3f, -0.7f + j * 0.3f, 0.0f);
80
81
glRotatef(mRotDeg + (5.0f * (6.0f * i + j)), 0.0f, 1.0f, 0.0f);
82
glRotatef(20.0f + (10.0f * (6.0f * i + j)), 1.0f, 0.0f, 0.0f);
83
GLfloat scale = 0.2f;
84
glScalef(scale, scale, scale);
85
glDrawElements(GL_TRIANGLES, sizeof(indices) / sizeof(GLuint), GL_UNSIGNED_INT,
86
indices);
87
88
glPopMatrix();
89
}
90
}
91
92
mRotDeg += 0.1f;
93
}
94
95
private:
96
float mRotDeg = 0.0f;
97
};
98
99
int main(int argc, char **argv)
100
{
101
FlatShadingSample app(argc, argv);
102
return app.run();
103
}
104
105