OpenGL shading language

DirectX & XNA, OpenGL...
Post Reply
dabrorius
Posts: 31
Joined: Thu Jun 09, 2011 9:46 pm
Smallest prime number bigger than 20: 23

OpenGL shading language

Post by dabrorius » Mon Nov 28, 2011 11:40 am

Bok, pokusavam naucit glsl ali naravno hrpa problema se pojavljuje angry**

Uglavnom, uspio sam pokrenut jednostavan pixel shader koji invertira boju za svaki pixel tup**

Code: Select all

void main(void) 
{
    gl_FragColor.rgb = 1.0 - gl_Color.rgb; 
    gl_FragColor.a = 1.0;
}
Ali cim probam pokrenut neki kompliciraniji primjer zali se da gl_Vertex i gl_Normal nisu definirani :/

Sa ovim kodom loadam shader.

Code: Select all

glEnable(GL_FRAGMENT_PROGRAM_ARB);
    
    std::ifstream file("/Users/dabrorius/Documents/OpenglDemo/shader.glsl");
    file.seekg(0, std::ios_base::end);
    long file_length = file.tellg();
    file.seekg(0, std::ios_base::beg);
    file.clear();
    
    char *shaderSourceCode = new char[file_length];
    file.read(shaderSourceCode, file_length);

    
    //const char *my_fragment_shader_source = "void main (void){gl_FragColor = vec4 (0.0, 1.0, 0.0, 1.0);}";
    const char *my_fragment_shader_source = shaderSourceCode;

    GLhandleARB my_program;
    GLhandleARB my_fragment_shader;
    
    // Create Shader And Program Objects
    my_program = glCreateProgramObjectARB();
    my_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
    
    // Load Shader Sources    
    glShaderSourceARB(my_fragment_shader, 1, &my_fragment_shader_source, NULL);
    glCompileShaderARB(my_fragment_shader);
    
    // Attach The Shader Objects To The Program Object
    glAttachObjectARB(my_program, my_fragment_shader);
    
    // Link The Program Object
    glLinkProgramARB(my_program);
    
    // Use The Program Object Instead Of Fixed Function <b style="color:black;background-color:#ffff66">OpenGL</b>
    glUseProgramObjectARB(my_program);

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest