I need help setting up my OpenGL shader, I just don't know what I'm doing wrong. I wrapped OpenGL shader system into a class called ShaderProgram. It's constructor is the next.
the vpath variable refers to the vertex shader file path and the fpath variable to
fragment shader file path.
the get_file_lines is a private method that stores the file lines in a string to be
compiled by OpenGL, it attaches them in the next format.
line + '\0'
So in a loop all the lines end up being added separated by the '\0' character. As I
understand you can pass them in that way to OpenGL and it should compile correctly, but I'm not sure.
I'm using this window flags.
The problem is that when I setup the shader it does nothing, no effect is applied to the screen output. Also I've tried using external shaders from the internet but the results are the same, obviously calling glUseProgram().
I use this code for drawing, implementing VAO and VBOs.
and this one to load the information to VAO.
The Allegro version I have is 5.0.11.
A small recommendation: You shouldn't use manual line breaks when writing text on the web unless you're actually starting a new paragraph. Using manual line breaks in the middle of your sentences makes the formatting look all messed up, depending on where you are reading the text
My name is
Pattrick. <- bad
My name is Pattrick. <- good
the get_file_lines is a private method that stores the file lines in a string to be compiled by OpenGL, it attaches them in the next format.
Does that function return a bool or an int on error? I kinda expected it to return a bool, in which case it would early-out of the constructor on success, but I assume it returns an int on error?
line + '\0'
So in a loop all the lines end up being added separated by the '\0' character. As I understand you can pass them in that way to OpenGL and it should compile correctly, but I'm not sure.
Actually, I don't think so. When you do that, each single line of the file is null-terminated and I assume the function would only read the first line in that case. Instead, you should separate them with \n and only put a \0 at the end of the string (which probably is there already anyways). If you want to have \0 at the end of each line, you actually have to pass an array to that function containing a pointer to the start of each line and then pass the number of lines in that array to glShaderSource() where you are currently passing a 1. Just changing the \0 to \n should be easier, though. I also recommend querying the error message of OpenGL's shader compiler. There should be a function for that. That way you'll know exactly what went wrong and don't have to take a wild guess. Just print the error message, if there is any, to the Debugger.
Also where and how exactly are you binding your shader program? I didn't see that anywhere in your code snippets above.
Allegro 5.0.11? The new Allegro 5.2 comes with shader support, maybe you could try that instead of rolling your own?
I've tried making the modifications that you told me RPG Hacker , and I achieved some progress. But the shader just doesn't work , using the shader's information extracted through the function "glGetShaderInfoLog" I got this error in both of the shaders.
(0) : error C0000: syntax error, unexpected $end at token "<EOF>"
This is the file reading method.
It returns true if a problem occurs.
The shader class constructor, not really good code, it's just for the current testing.
Then this methods for enabling and disabling the shader.
The vertex shader.
And the fragment shader.
Those shaders are basically useless but are just for testing, the only thing I want to know is why is OpenGL generating that error seen before, maybe is the way I extract the string using c_str() in lines 9 and 28. Also I've separated the lines using '\n' instead of '\0'.
bool get_shader_file_lines(std::string &path, std::string dest){
Is that your actual code? If so, you're not passing dest by reference, you're passing it by value (thus making a copy of it, all modifications inside the function are lost once it returns). Change that std::string dest into a std::string& dest.
That error message (unexpected token) specifically means that the string contains something the compiler didn't expect. This should be relatively easy to determine. Just put a breakpoint at this line
glShaderSource(vertex_shaderID, 1, &vcode, &vcode_size);
and look at the contents of of vcode. You will probably find that it only points to an empty string (\0) since the function didn't modify its contents.
Well, this entire question was useless because that was causing the problem, sorry for wasting your time with such stupid mistake. I'm going to mark RPG Hacker as the one that answered the question because he showed me were the error was. the next time I should pay more attention .
Don't worry, oversights like that happen to the best of us.
Glad to hear the problem is solved.