0
|
1 |
/**
|
|
2 |
* ShaderShark
|
|
3 |
* Copyright © 2023 František Kučera (Frantovo.cz, GlobalCode.info)
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation, version 3 of the License.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*/
|
|
17 |
|
|
18 |
#pragma once
|
|
19 |
|
|
20 |
#include <string>
|
|
21 |
#include <stdexcept>
|
|
22 |
|
|
23 |
#include <epoxy/gl.h>
|
|
24 |
#include <epoxy/glx.h>
|
|
25 |
#include <GL/glu.h>
|
|
26 |
|
|
27 |
#include <glm/glm.hpp>
|
|
28 |
#include <glm/ext.hpp>
|
|
29 |
|
|
30 |
inline
|
|
31 |
void quads(GLfloat tx, GLfloat ty, GLfloat x, GLfloat y, GLfloat z) {
|
|
32 |
glTexCoord2f(tx, ty);
|
|
33 |
glVertex3f(x, y, z);
|
|
34 |
}
|
|
35 |
|
|
36 |
inline
|
|
37 |
void checkError(std::ostream* out) {
|
|
38 |
GLenum code = glGetError();
|
|
39 |
if (code == GL_NO_ERROR) {
|
|
40 |
if (out) *out << "GL check: OK" << std::endl;
|
|
41 |
} else {
|
|
42 |
const char* string = (const char*) gluErrorString(code);
|
|
43 |
if (out) *out << "GL check: " << string << std::endl;
|
|
44 |
else throw std::logic_error(std::string("GL error: ") + string);
|
|
45 |
}
|
|
46 |
}
|
|
47 |
|
|
48 |
inline
|
|
49 |
GLenum toShaderType(const std::string& fileName) {
|
|
50 |
if (fileName.ends_with(".vert")) return GL_VERTEX_SHADER;
|
|
51 |
else if (fileName.ends_with(".frag")) return GL_FRAGMENT_SHADER;
|
|
52 |
else throw std::invalid_argument("Expecting *.vert or *.frag file");
|
|
53 |
}
|
|
54 |
|
|
55 |
inline
|
|
56 |
void dump(const char* name, const glm::vec3& value) {
|
|
57 |
std::cerr << "dump: " << name << " = ["
|
|
58 |
<< value.x << ", "
|
|
59 |
<< value.y << ", "
|
|
60 |
<< value.z << "]" << std::endl;
|
|
61 |
} |