target openglES 2 (with vao ext)

This commit is contained in:
papush! 2021-01-02 17:45:42 +01:00
parent dafdc38f16
commit 8ad1cf1b89
5 changed files with 19 additions and 50 deletions

View File

@ -1,10 +1,6 @@
#version 330 core
in vec3 norm;
in vec2 uv;
in vec3 frag_pos;
out vec4 final_col;
varying vec3 norm;
varying vec2 uv;
varying vec3 frag_pos;
uniform sampler2D tex;
@ -16,5 +12,5 @@ void main() {
float diff = max(dot(normalize(norm), light_dir), 0.0);
vec3 diffuse = diff * light_col;
final_col = texture(tex, uv) * vec4(ambient + diffuse, 1);
gl_FragColor = texture2D(tex, uv) * vec4(ambient + diffuse, 1);
}

View File

@ -1,12 +1,10 @@
#version 330 core
attribute vec3 in_pos;
attribute vec3 in_norm;
attribute vec2 in_uv;
layout(location = 0) in vec3 in_pos;
layout(location = 1) in vec3 in_norm;
layout(location = 2) in vec2 in_uv;
out vec3 norm;
out vec2 uv;
out vec3 frag_pos;
varying vec3 norm;
varying vec2 uv;
varying vec3 frag_pos;
uniform mat4 proj;
uniform mat4 view;

View File

@ -1,23 +1,8 @@
#version 330 core
// in vec3 tex_coord;
// out vec4 final_col;
// uniform samplerCube skybox;
// void main() {
// // final_col = texture(skybox, tex_coord);
// final_col = vec4(0, 0, 0, 1);
// }
in vec3 tex_coords;
out vec4 final_col;
varying vec3 tex_coords;
uniform samplerCube tex;
void main() {
final_col = texture(tex, tex_coords);
gl_FragColor = textureCube(tex, tex_coords);
// final_col = vec4(1, 0, 1, 1);
}

View File

@ -1,22 +1,8 @@
#version 330 core
#version 120
// layout(location = 0) in vec3 in_pos;
attribute vec3 in_pos;
// out vec3 tex_coords;
// uniform mat4 proj;
// uniform mat4 view;
// void main() {
// // vec4 pos = proj * view * vec4(in_pos, 1.0);
// // gl_Position = pos.xyww;
// gl_Position = proj * vec4(in_pos, 1.0);
// tex_coords = in_pos;
// }
layout(location = 0) in vec3 in_pos;
out vec3 tex_coords;
varying vec3 tex_coords;
uniform mat4 proj;
uniform mat4 view;

View File

@ -41,6 +41,7 @@ void OpenGLWidget::loadSkybox() {
if (!skybox_program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/skybox.frag")) {
qFatal("Error compiling skybox.frag: %s", skybox_program.log().toLocal8Bit().constData());
}
skybox_program.bindAttributeLocation("in_pos", 0);
if (!skybox_program.link()) {
qFatal("Error linking the skybox shader program: %s", skybox_program.log().toLocal8Bit().constData());
}
@ -111,6 +112,9 @@ void OpenGLWidget::initializeGL() {
if (!main_program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/main.frag")) {
qFatal("Error compiling main.frag: %s", main_program.log().toLocal8Bit().constData());
}
main_program.bindAttributeLocation("in_pos", 0);
main_program.bindAttributeLocation("in_norm", 1);
main_program.bindAttributeLocation("in_uv", 2);
if (!main_program.link()) {
qFatal("Error linking the main shader program: %s", main_program.log().toLocal8Bit().constData());
}