From 8ad1cf1b89b8acae55e36d6bd4562dffd1bcc714 Mon Sep 17 00:00:00 2001 From: papush! Date: Sat, 2 Jan 2021 17:45:42 +0100 Subject: [PATCH] target openglES 2 (with vao ext) --- shaders/main.frag | 12 ++++-------- shaders/main.vert | 14 ++++++-------- shaders/skybox.frag | 19 ++----------------- shaders/skybox.vert | 20 +++----------------- src/opengl_widget.cc | 4 ++++ 5 files changed, 19 insertions(+), 50 deletions(-) diff --git a/shaders/main.frag b/shaders/main.frag index 8eb47ec..7120521 100644 --- a/shaders/main.frag +++ b/shaders/main.frag @@ -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); } diff --git a/shaders/main.vert b/shaders/main.vert index 33e6849..d05a0da 100644 --- a/shaders/main.vert +++ b/shaders/main.vert @@ -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; diff --git a/shaders/skybox.frag b/shaders/skybox.frag index f5f8edb..e056670 100644 --- a/shaders/skybox.frag +++ b/shaders/skybox.frag @@ -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); } diff --git a/shaders/skybox.vert b/shaders/skybox.vert index ac4ac5e..2ab8497 100644 --- a/shaders/skybox.vert +++ b/shaders/skybox.vert @@ -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; diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc index 5a82d23..adc851e 100644 --- a/src/opengl_widget.cc +++ b/src/opengl_widget.cc @@ -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()); }