• Advertisement
Sign in to follow this  

how to avoid macro loops

This topic is 1850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
When I get to delete[] shaderSource; line
vertex shader is the same as i posted and fragment shader doesn't have extra symbols at the end huh.png Edited by proanim

Share this post


Link to post
Share on other sites

Can you confirm that when source is explicitly defined in code lie this:

    const GLchar* shaderSource = "#version 330\n"
        "layout (location = 0) in vec3 inPosition;\n"
        "layout (location = 1) in vec3 inColor;\n"
        "smooth out vec3 theColor;\n"
        "void main()\n"
        "{\n"
            "gl_Position = vec4(inPosition, 1.0);\n"
            "theColor = inColor;\n"
        "}\n"

    glShaderSource(uiShader, 1, &shaderSource, NULL);
    glCompileShader(uiShader);

    // dont call delete[] on const arrays, you will get SIGSEGV

    GLint compileStatus;
    glGetShaderiv(uiShader, GL_COMPILE_STATUS, &compileStatus);

    if (compileStatus == GL_FALSE) {
        GLint infoLogLength;
        glGetShaderiv(uiShader, GL_INFO_LOG_LENGTH, &infoLogLength);
        
        GLchar* infoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(uiShader, infoLogLength, NULL, infoLog);
        
		ofstream outfile;
		outfile.open ("log.txt");
		outfile << infoLog << endl;
		outfile.close();

        delete[] infoLog;
    }

it compiles without errors?

Edited by santa01

Share this post


Link to post
Share on other sites

It compiles without errors but it doesn't have any effect. I tried your way, there was no effect from the shader but the debugger did show correct output from shaderSource. I also tried to use it this way

 

bool CShader::loadVertexShader(int a_iType)
{
	const GLchar* shaderSource = "#version 330\n"
        "layout (location = 0) in vec3 inPosition;\n"
        "layout (location = 1) in vec3 inColor;\n"
        "smooth out vec3 theColor;\n"
        "void main()\n"
        "{\n"
            "gl_Position = vec4(inPosition, 1.0);\n"
            "theColor = inColor;\n"
        "}\n";

	uiShader = glCreateShader(a_iType);
    glShaderSource(uiShader, 1, &shaderSource, NULL);
    glCompileShader(uiShader);

	ofstream outfile;
	outfile.open ("log.txt", fstream::out | fstream::app);
	outfile << shaderSource << endl;
	outfile << endl;
	outfile.close();

	GLint compileStatus;
    glGetShaderiv(uiShader, GL_COMPILE_STATUS, &compileStatus);
 
    if (compileStatus == GL_FALSE)
	{
        GLint infoLogLength;
        glGetShaderiv(uiShader, GL_INFO_LOG_LENGTH, &infoLogLength);
        
        GLchar* infoLog = new GLchar[infoLogLength + 1];
        glGetShaderInfoLog(uiShader, infoLogLength, NULL, infoLog);
        
		ofstream outfile;
		outfile.open ("log.txt");
		outfile << infoLog << endl;
		outfile.close();
 
        delete[] infoLog;
    }

	return 1;
}

 

also no effect. I did this just in case I don't miss anything when doing this part

 

// Load shaders and create shader program
//shVertex.loadShader("data/shaders/color.vert", GL_VERTEX_SHADER);
shVertex.loadVertexShader(GL_VERTEX_SHADER);
shFragment.loadShader("data/shaders/color.frag", GL_FRAGMENT_SHADER);

Share this post


Link to post
Share on other sites

What do you mean by "no effect?" If things aren't drawing/showing, it possible your draw calls and/or vertex data are incorrect.

Share this post


Link to post
Share on other sites

[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)')

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

[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?

Share this post


Link to post
Share on other sites
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. Edited by rip-off

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement