Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/samples/hello_triangle/HelloTriangle.cpp
1695 views
1
//
2
// Copyright 2014 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 "util/shader_utils.h"
19
20
class HelloTriangleSample : public SampleApplication
21
{
22
public:
23
HelloTriangleSample(int argc, char **argv)
24
: SampleApplication("HelloTriangle", argc, argv, 2, 0)
25
{}
26
27
bool initialize() override
28
{
29
constexpr char kVS[] = R"(attribute vec4 vPosition;
30
void main()
31
{
32
gl_Position = vPosition;
33
})";
34
35
constexpr char kFS[] = R"(precision mediump float;
36
void main()
37
{
38
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
39
})";
40
41
mProgram = CompileProgram(kVS, kFS);
42
if (!mProgram)
43
{
44
return false;
45
}
46
47
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
48
49
return true;
50
}
51
52
void destroy() override { glDeleteProgram(mProgram); }
53
54
void draw() override
55
{
56
GLfloat vertices[] = {
57
0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f,
58
};
59
60
// Set the viewport
61
glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
62
63
// Clear the color buffer
64
glClear(GL_COLOR_BUFFER_BIT);
65
66
// Use the program object
67
glUseProgram(mProgram);
68
69
// Load the vertex data
70
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
71
glEnableVertexAttribArray(0);
72
73
glDrawArrays(GL_TRIANGLES, 0, 3);
74
}
75
76
private:
77
GLuint mProgram;
78
};
79
80
int main(int argc, char **argv)
81
{
82
HelloTriangleSample app(argc, argv);
83
return app.run();
84
}
85
86