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 2 years ago.
Improve this question
#include <windows.h> // for MS Windows
#include <GL/glut.h> // GLUT, include glu.h and gl.h
#include <vector>
uniform vec2 lightpos;
uniform vec3 lightColor;
uniform float screenHeight;
uniform vec3 lightAttenuation;
uniform float radius;
uniform sampler2D texture;
void main()
{
vec2 pixel=gl_FragCoord.xy;
pixel.y=screenHeight-pixel.y;
vec2 aux=lightpos-pixel;
float distance=length(aux);
float attenuation=1.0/(lightAttenuation.x+lightAttenuation.y*distance+lightAttenuation.z*distance*distance);
vec4 color=vec4(attenuation,attenuation,attenuation,1.0)*vec4(lightColor,1.0);
gl_FragColor = color;//*texture2D(texture,gl_TexCoord[0].st);
}
Errors
'uniform' does not name a type
'vec2' was not declared in this scope
'screenHeight' was not declared in this scope
expected ';' before 'aux'
'aux' was not declared in this scope
etc.
I use Dev C++ and ...
projects parameters
/GL/ header subfiles
Don't hesitate to write if any other information is needed. I added what I know. I have done the opengl project before. But know I have to make like this YouTube Video, OpenGL 2D lighting using shaders
GLSL just look like C, it's not actually C. The code has to be compiled by a different compiler (an external one like glslc or the driver provided OpenGL compiler) and it runs on the GPU as part of a render pass.
This is a shader program, not a c++ program. You have to compile it with a shader compiler.
Related
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
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
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.
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
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
My shaders have in/out keywords. But I've got GLSL compile error: 'out' qualifier only valid for function parameters in GLSL 1.10. Shaders have #version 330 directive. Calling glGetString(GL_SHADING_LANGUAGE_VERSION) returns 3.30.
Here is my project: github.com/wlad031/ssu-coursework-2016. Input folder contains shaders. Main source files are src/ShaderProgramControl.cpp and src/Shader.cpp. Where is my mistake?
In your src/FileReader.cpp you have :
if (first != '#') {
res.push_back(line);
}
And this strips out the #version 330 ...