GLSL vertex shader for texture display not compiling - opengl

I've got a vertex shader that doesn't want to compile, but I see absolutely no reason for the error it is giving. It's failing with the following error:
ERROR: D:\local\Temp\f46179fe-8934-4135-820a-bed1e54b98bf.tmp:22: 'texture2D' : no matching overloaded function found
ERROR: D:\local\Temp\f46179fe-8934-4135-820a-bed1e54b98bf.tmp:22: 'assign' : cannot convert from ' const float' to ' smooth out 4-component vector of float'
ERROR: D:\local\Temp\f46179fe-8934-4135-820a-bed1e54b98bf.tmp:22: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
SPIR-V is not generated for failed compile or link
Here is the code:
#version 460
//Passes variables from uniforms to frag_hud shader
layout(location = 0) in vec3 pos;
layout(location = 1) in vec2 vert_tex_coord;
uniform float vert_col_dist;
uniform sampler2D vert_hud01;
uniform sampler2D vert_hud02;
uniform sampler2D vert_hud03;
out vec2 tex_coord;
out float col_dist;
out vec4 hud01;
out vec4 hud02;
out vec4 hud03;
void main() {
gl_Position = vec4(pos, 1.0);
tex_coord = vec2(vert_tex_coord.x, vert_tex_coord.y);
col_dist = vert_col_dist;
hud01 = texture2D(vert_hud01, vert_tex_coord);
hud02 = texture2D(vert_hud02, vert_tex_coord);
hud03 = texture2D(vert_hud03, vert_tex_coord);
}

Figured it out. Needed to use texture() instead of texture2D().

Related

DEBUG_TYPE_ERROR when passing glm::vec2 type using glUniformMatrix2fv

I am trying to pass the frame size (X, Y) to my fragment shader. When I execute the GLAD function glUniformMatrix2fv, I get the following error:
GL CALLBACK: ** GL ERROR ** type = "0x824c", severity = "0x9146", message = Error has been generated. GL error GL_INVALID_OPERATION
I use this method to pass glm::vec4 datatypes (using glUniformMatrix4fv) for many other shaders without issue. I've looked up the error type, 0x824c, and it appears to be a DEBUG_TYPE_ERROR. I have checked the function call in the relevant documention, and it appears to be correct. What am I missing?
Drawing code:
uFrameSizeID = glGetUniformLocation(shader->id(), "uFrameSize");
glUniformMatrix2fv(uFrameSizeID, 1, GL_FALSE, glm::value_ptr(
glm::vec2(static_cast<float>(X_RESOLUTION), static_cast<float>(Y_RESOLUTION))));
Fragment Shader:
layout(location = 0) out vec4 FragColor;
in VertexData
{
vec4 color;
vec2 texCoords;
} fs_in;
uniform sampler2D uTexture;
uniform sampler2D uDistortionMapX;
uniform sampler2D uDistortionMapY;
uniform vec4 uWindow; // = [x0, y0, dx, dy]
uniform vec2 uFrameSize; // = [X, Y] float
void main()
{
vec2 v2_dist_vec;
v2_dist_vec.x = texture(uDistortionMapX, fs_in.texCoords).r;
v2_dist_vec.y = texture(uDistortionMapY, fs_in.texCoords).r;
FragColor = texture(uTexture, fs_in.texCoords + v2_corr_vec);
}
glUniformMatrix2fv passes a 2x2 matrix. But in your shader you use uniform vec2 uFrameSize; which is a pair of floats. You must use glUniform2fv, or even simpler glUniform2f:
uFrameSizeID = glGetUniformLocation(shader->id(), "uFrameSize");
glUniform2f(uFrameSizeID, static_cast<float>(X_RESOLUTION), static_cast<float>(Y_RESOLUTION));

GLSL Error: "Type should be float or int"

I am trying to compile a shader, and it is compiling on Intel HD on one PC, but not on AMD drivers on another PC.
Vertex Shader:
#version 330
precision mediump float;
precision lowp sampler2D;
uniform mat4 ProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 WorldViewMatrix;
in vec3 position;
in vec2 TexCoord;
out vec2 texCoord;
void main() {
texCoord = TexCoord;
gl_Position = ProjectionMatrix * ModelViewMatrix * WorldViewMatrix * vec4(position, 1);
}
Fragment Shader:
#version 330
precision mediump float;
precision lowp sampler2D;
uniform vec4 TextureHueColor;
uniform sampler2D TextureUnit;
in vec2 texCoord;
out vec4 gl_FragColor;
void main() {
gl_FragColor = texture(TextureUnit, texCoord) * TextureHueColor;
}
On AMD drivers, I am getting:
Vertex shader failed to compile with the following errors:
ERROR: 0:3: error(#228) Type should be float or int
ERROR: error(#273) 1 compilation errors. No code generated
I am a beginner, and have no idea what is wrong with this shader, to me it looks fine. Anyone spot what's wrong?
Default precision qualifiers in GLSL 3.30 cannot be applied to sampler types. Or any type other than int or float.
Also, FYI: when using desktop GLSL (as opposed to GLSL ES), the precision qualifiers accomplish nothing. They're ignored; they exist solely for compatibility with GLSL ES shaders.

GLSL Vertex Shader Compilation Error

This is my following Error which is ERROR #160 in GLSL.
#version 330 core
layout (location = 0) in vec3 position;
out vec4 pos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(position, 1.0f);
pos = position;
}
and this is the error which was created when trying to compile this GLSL program.
ERROR: Vertex Shader Program Compilation Failed! Vertex shader failed to compile with the following errors:
ERROR: 0:13: error(#160) Cannot convert from: "in highp 3-component vector of vec3" to: "default out highp 4-component vector of vec4"
ERROR: error(#273) 1 compilation errors. No code generated
I have no knowledge on debugging GLSL so if there is anyone who can help it would e much appreciated.
Well, your error is pretty clear. Since you assign position to pos, and pos is a vec4 while position is a vec3, and there is no implicit conversion for this, the compiler complains. To fix this, simply create a vec4 from you position, e.g.
pos = vec4(position, 1.0f);
However, you should think about why you would need a vec4 for your position down the pipeline, or whether having pos be a vec3 would be sufficient or not.

Shader creation Opengl

I am using OpenGl 3 and the tutorial from BennyBox on Youtube.
Using this method:
static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage){
GLint success = 0;
GLchar error [1024] = {0};
if(isProgram){
glGetProgramiv(shader, flag, &success);
}else{
glGetShaderiv(shader, flag, &success);
}
if(success == GL_FALSE){
if(isProgram){
glGetProgramInfoLog(shader, sizeof(error), NULL, error);
}else{
glGetShaderInfoLog(shader,sizeof(error), NULL, error);
}
std::cerr<< errorMessage<< ": " << error<< "'"<<std::endl;
}
}
I should be able to load shader file (fragment and vertex shaders). It works with basic shaders but when I try to modify them to that point:
#version 120
attribute vec3 position;
attribute vec2 texCoord;
varying vec2 texCoord;
void main(){
gl_Position = vec4(position, 1.0);
texCoord0 = texCoord;
}
The I get:
Error compiling shader!: 'ERROR: 0:6: 'texCoord' : redefinition
ERROR: 0:11: 'texCoord0' : undeclared identifier
ERROR: 0:11: 'assign' : cannot convert from 'attribute 2-component vector of float' to 'float'
and the fragment shader:
#version 120
uniform sampler2D diffuse;
varying vec2 texCoord0;
void main(){
gl_FragColor = texture2D(diffuse, texCoord0);
}
gives:
Unable to load shader: ./res/basicShader.fs
Error linking shader program: 'Attached vertex shader is not compiled.
I have the exact same code as the video, and it runs fine using basic coloring shader. I am on Visual Studio 2012.
There are two errors in your vertex shader.
First, you are declaring texCoord twice.
attribute vec2 texCoord;
varying vec2 texCoord;
Then you are trying to use a varying called texCoord0, without ever declaring it.
texCoord0 = texCoord;
Your vertex shader should look like this:
#version 120
attribute vec3 position;
attribute vec2 texCoord;
varying vec2 texCoord0;
void main(){
gl_Position = vec4(position, 1.0);
texCoord0 = texCoord;
}

Compilation errors using shaders

My application is returning an error:
Fragment shader failed to compile with the following errors:
ERROR: 0:5: error(#132) Syntax error: 'out' parse error
ERROR: error(#273) 1 compilation errors. No code generated
whenever I execute the following code:
fragment.fs
#version 330
in vec4 color
out vec4 fragColor;
void main() {
fragColor = color;
}
vertex.vs
#version 330
layout (location = 0) in vec3 position;
out vec4 color;
uniform float uniformFloat;
void main() {
color = vec4(clamp(position, 0.0, 1.0), 1.0);
gl_Position = vec4(position, 1.0);
}
How could I fix this?
You forgot the semicolon after in vec4 color in the fragment shader.