LWJGL GLSL shader not compiling - opengl

I am using the lastest recomended version of LWJGL 3, and while trying to compile shaders i get errors.
Shader:
#version 330
in vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}
Error:
Vertex shader failed to compile with the following errors:
ERROR: 0:1: error(#307) Invalid profile "in"
ERROR: 0:1: error(#76) Syntax error: unexpected tokens following #version
ERROR: 0:1: error(#364) Invalid: unexpected token in symbol.
ERROR: error(#273) 3 compilation errors. No code generated
I wasnt able to find anything related to this error online. Does anyone here know?

Looks as if the end of line characters (\n) are missing in the code string which means that the compiler treats the in keyword as profile qualifier for the #version directive.

Related

How to interpret GLSL shader compilation errors

My OpenGL application encounters errors when it compiles my fragment shader program, with output that includes
0:4(13): error: syntax error, unexpected BASIC_TYPE_TOK, expecting LOWP or MEDIUMP or HIGHP
Specifically, how to interpret the "0:4(13)" prefix to the error message? Anyone know where this is documented? I could not find a description of error message format at the Khronos Shader Compilation wiki.

How do we interpret Mesa compiler error message?

I have built MESA with OpenSWR on Windows. I am getting an error in my shader code that I cannot understand/correct. The same code runs fine using just GLEW/Nvidia drivers.
Here's the error message:
name= identfshader, error= 0:27(8): error: syntax error, unexpected NEW_IDENTIFIER, expecting ',' or ';'
If I understand this correctly, the problem occurs in line 27, column 8. Is this what 0:27(8) stands for?
If somebody could explain to me how to determine the line number in the shader code where this is happening I'll be happy to post a snippet of that part of the code for further help.
Thanks.

glbinding, Qt and error "glbinding is not compatible with gl.h"

I'm writing a new project and want to replace GLEW with glbinding.
My setup is like this:
VS 2015, Qt 5.6, glbinding 2.0
I tried to compile quite simple code - only window (QWindow) with OpenGL context (QOpenGLContext) but got an error: glbinding is not compatible with gl.h
When I was tracking this bug I found out that file (which is imported by the glbinding/gl/gl.h) nogl.h is causing this message with the code below:
#ifdef __gl_h_
#error "glbinding is not compatible with gl.h"
#else
#define __gl_h_
#endif
Then I noticed that this is caused by the QtGui/qopenglcontext.h header (which I need for creating OpenGL context...). So when I don't include qopenglcontext.h my program compiles without error. I also noticed that this error message appears only when I include glbinding/gl/gl.h after QtGui/qopenglcontext.h. If I reverse the include order I get a bunch of errors like this:
1>C:\Qt\Qt5.6.0\5.6\msvc2015_64\include\QtGui/qopenglext.h(117): error C2065: 'GLenum': undeclared identifier
1>C:\Qt\Qt5.6.0\5.6\msvc2015_64\include\QtGui/qopenglext.h(117): error C2146: syntax error: missing ')' before identifier 'mode'
1>C:\Qt\Qt5.6.0\5.6\msvc2015_64\include\QtGui/qopenglext.h(118): error C2065: 'GLenum': undeclared identifier
1>C:\Qt\Qt5.6.0\5.6\msvc2015_64\include\QtGui/qopenglext.h(118): error C2146: syntax error: missing ')' before identifier 'target'
After all I still don't know how to solve this and what exactly is causing this error...
glbinding – like practically every other OpenGL loader – has to fiddle with the OpenGL symbol tokens to avoid namespace clashing. To this end it must interact with the OpenGL definitions in a specific way, which means you must not have included any OpenGL header, or something that includes such in turn at the moment you include the glbinding header. The preprocessor fiddling glbinding performs will prevent gl.h getting included in a way that causes trouble.
So what you must do is: Include the glbinding headers in your C++ compilation unit files before everything else (Qt headers, OpenGL helper libraries and so on).

error C2146 trying to compile a basic HLSL shader in C++

i've just started to learn the basics of HLSL using C++, im following the tutorials on a book, the first basic shader is:
float4 VS_Main( float4 pos:POSITION):SV_POSITION
{
return pos;
}
but i get a lot of errors at compile time:
error C2146: syntax error: ';' missing before the identifier 'VS_Main'
error C4430: missing type specifier, int assumed. Note: default-int is no longer supported
error C2146: syntax error : ')' missing before the identifier 'pos'
error C2059: syntax errorlooks like a function definition, but there is no formal parameter list.
error C2059: syntax error: '{'
it really looks like the compiler cant handle HLSL at all...maybe VS2012 express doesnt support HLSL?
thanks in advance
HLSL is not C++. You should compile shaders with shader compiler, and C++ with C++ compiler — do not mix. There are two options for compiling HLSL.
Use command-line utility fxc.exe that is included in DirectX SDK (docs and usage here at MSDN). It generates a file that you should load in runtime by some of the ways described here.
Compile your shader at runtime by using D3DCompileFromFile function.
There are pros and cons about each of the variants. In short, pre-compiling at build time gives you some time gain at runtime, while compiling at runtime is more flexible and comfortable at development stage (no need to remember to recompile it or to use post-build scripts) but is more error-prone. Choose by yourself.
The code looks fine for HLSL. If you want to compile it from within VS2012 set the ".fx" file to build using the HLSL shader compiler. Right click the file select properties. Then select General and Item Type should be set to HLSL compiler.
If you really want to make shaders using C++ you could look into C++AMP to see if it may suit your needs.
it really looks like the compiler cant handle HLSL at all...maybe VS2012 express doesnt support HLSL?
No C++ compiler does. It is not supposed to be handled by the compiler.
You need to turn it into a resource and copy it into the bin directory using post-build scripts, and load the HLSL at runtime.
See also: http://www.directxtutorial.com/Lesson.aspx?lessonid=11-4-5

GLSL shader programming #version header error: unrecognized preprocessing directive

I just started GLSL shader programing, but however I get
unrecognized preprocessing directive
whenever I put #version directive at the preprocessor directives header stack, though I included all opengl related headers and files within my source file,
Shader:
#version 400
in vec3 Color;
out vec4 FragColor;
void main()
{
FragColor = vec4(Color, 1.0);
}
how can I fix this issue?
The #version directive must occur in a shader before anything else, except for comments and white space.
Even preprocessor directives are illegal ( NVIDIA accepts it but AMD does not! ).
If this doesn't help, give us some more information. E.g. glGetString(GL_VERSION) and glGetString(GL_VENDOR).
Refering to your comments you missunderstand how a shader is compiled. A shader cannot be compiled by a C++ compiler. Put your shader into a text file and load it at runtime, then call the compilation methods of OpenGL.
The #version pre-processor command is run at the c++ compile time, glsl is only text based and shouldn't be compiled. If you #include "file" in a header or .cpp in the program it will trigger the compile and error. Therefore don't #include glsl files into you application.