glUniformLocation returns -1 [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to uniform a model matrix into a vertex shader using
glUniformMatrix4fv(glGetAttribLocation(shaderProgram, "modelMatrix"),
1, GL_FALSE, glm::value_ptr(objmesh[0]->modelMatrix));
but when I use this, the model does not show. I've used
int location = glGetAttribLocation(shaderProgram, "modelMatrix");
to find the location but it only returns -1. I've also tried using a manually made matrix (as an identity matrix) in the vertex shader and when I do that it works. I've done this exact thing to another shader, just a different program.
objmesh is just a std::vector that contains a struct with a mesh's vertices, uvs and so fourth. As of now, the modelMatrix is just an identity matrix.
I uniform the matrix in the vertex shader like so: uniform mat4 modelMatrix;

Solved it: I accidentally used glGetAttribLocation instead of glGetUniformLocation

Related

What are the use cases of sampler2D uniforms in WebGL / OpenGL? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Samplers goes into a little too much depth without use cases. What are the use cases of sampler2D (texture) uniforms in a vertex shader? Are they used to pass data in ever, or what do you use them for in production games? How creative do people get with them?
sampler2D is just a way to get data from an array. Don't think of it as a texture. Think of it has a 2D array with special hardware to do interpolation between values in the array (LINEAR filtering) and values between mips. Set the sampling to NEAREST and they just become 2D arrays.
So, your question is about as generic as asking "what are arrays used for in JavaScript". They are used for whatever you want.
Probably the most common thing is bone matrices for skinned meshes. Another example but not nearly as common AFAIK is having more flexible vertex data at the expense of speed
But just to re-iterate, texture are just arrays and sampler2D is specifically for 2D arrays so when you need a random access array in a shader use a sampler2D

glsl vertex shader causes INTCONSTANT error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
opengl 3.0
glsl 130
ubuntu 18.04
intel i7 3520m
I wrate simple vertex shader and fragment shader.
#version 130
in vec4 position;
void main(){
gl_Position = position;
}
#version 130
out vec4 fragment;
void main(){
fragment = vec4(1.0,0.0,0.0,1.0);
}
But the shaders causes errors.
Compile Error in vertex shader
0:7(2): error: syntax error, unexpected INTCONSTANT, expecting $end
Compile Error in fragment shader
0:7(2): error: syntax error, unexpected INTCONSTANT, expecting $end
glShaderSource(shader,count, &string, length);
when length is set NULL. the string is null character terminated.
but I wrote ¥0 instead of \0

How to fix an issue with shaders? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm working on writing code for simpliest shader.
Here is its code.
const char* Vertex_Shader_Descrip = "#version 330/n"
"layout(location = 0) in vec3 position;/n"
"void main()/n"
"{/n"
"gl_Position = vec4(position.x, position.y, position.z, 1.0);/n"
"}/0";
glsl shader compilation fails with the error
error C0206: invalid token "<invalid atom 199709744>" in version line
Don't remember the exact version of shader, but it supports opengl 3.3
Please, could you point on my mistakes if there's any or just explain me what is wrong?
You need to use reverse slash instead of used.
const char* Vertex_Shader_Descrip = "#version 330\n"
Remove all the /n and try adding \n.

Is it possible to callback C/C++ function/code in a GLSL shader when conditions are met? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Is it possible to run C/C++ code from a GLSL shader? E.g. in fragment shader pixel X,Y is reached so call a C/C++ function then continue as normal. (Since the screen size is very small and functions will be very small as well, performance shouldn't be a huge issue.)
No. Consider the GPU as an special machine that works only with GLSL programs. But you can write that function (in GLSL language, not C/C++) and call it in the shader. If you are going to use in a fragment shader, then compile this function as a fragment shader too and link it to the program where you use it.
The calling shader must declare this function, otherwise it's ignored.

glm::vec3 array to pass shader -OpenGL -GLSL [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have a 3d glm vector:
glm::vec3 Position[5];
However when I use it like this:
location = glGetUniformLocation(_programHandle, "lightPos");
glUniform3fv(location,5, &Position[0][0]);
I get segmentation fault in shader vertex:
uniform vec3 lightPos[5];
Where is the mistake in code?
Would value_ptr(Position[0]) work any better?