how to avoid macro loops

Started by
31 comments, last by rip-off 11 years, 3 months ago

[quote name='proanim' timestamp='1356714928' post='5015107']
also no effect.
[/quote]

We are currently talking about these compilation errors:


Fragment shader failed to compile with the following errors:
ERROR: 2:1: error(#307) Profile "smooth" is not supported
ERROR: 2:1: error(#76) Syntax error: unexpected tokens following #version
ERROR: error(#273) 2 compilation errors.  No code generated

right?

If yes, then glsl compiler definitely considers shader source as a one line like:

#version 330layout (location = 0) in vec3 inPosition;layout (location = 1) in vec3 inColor;smooth out vec3 theColor;

which isn't legal and the only stuff I can suggest here is to try out windows EOL sequence of \r\n instead of pure \n in a shaderSource above

If no, than please provide something more valuable rather than `also no effect', glsl compilation log at least (if nothing is printed and nothing is rendered than its worth printing shader compilation status log with out the check `if (compileStatus == GL_FALSE)')

Advertisement

Well this is only simple trinagle on the screen that should make use of color shader. The works by default, and somewhere on the half of this topic there was a solution that improved my original shader loading function (and it works no problem). But then since it was suggested not to read the file line by line and do extra work after, I would like to try and make that work.

And this approach gives white triangle instead of rainbow color effect that you see in usual tutorials that use color shader. That is what i mean by having 'no effect'. As far as I can tell there is no errors in the function or in shaders, this problem is very wierd to me since even if I supply vertex shader which I am having problems (like const GLchar* from above) with for whatever reason, it doesn't work.

[quote name='proanim' timestamp='1356721348' post='5015133']
And this approach gives white triangle instead of rainbow color effect that you see in usual tutorials that use color shader.
[/quote]

How do you render your polygon?

As the others have mentioned, you really have (at least) two distinct problems here. The first is loading the file contents into memory, and the second relates to loading and applying shaders. You should approach these as different problems, and solve and test them in isolation.

As others have demonstrated, use a hard coded string literal to test your shader code.

Likewise, write a small program to demonstrate and test file loading. For example, you can load a file into a string fairly simply using streambuf iterators:

#include <string>
#include <iterator>
#include <fstream>
#include <iostream>

std::string read(std::istream &stream) {
    std::istreambuf_iterator<char> begin(stream);
    std::istreambuf_iterator<char> end;
    return std::string(begin, end);
}

int main() {
    std::ifstream in("ReadMe.txt");
    if(in) {
         std::string data = read(in);
         std::cout << "The file contents are:\n";
         std::cout << data;
    } else {
        std::cerr << "Failed to open the file" << std::endl;
        return 1;

    }
}
It is also possible to make read() a one liner, but it falls afoul of the most vexing parse.

Once you've verified that you can load strings correctly, and that you can create and use shaders correctly, then is the time to create a program that does both. Breaking a complex task into simpler sub-tasks is called "divide and conquer" and is absolutely necessary for writing functioning and maintainable software.

This topic is closed to new replies.

Advertisement