Search code examples
openglcg

OpenGL Cg Geometry Shader


I'm getting a compiler error when trying to initialize a geometry shader using OpenGL. I'm using VS2013.
Here is how I initialize it on OpenGL

myCgContext = cgCreateContext();
cgGLSetDebugMode(CG_FALSE);

cgSetParameterSettingMode(myCgContext, CG_DEFERRED_PARAMETER_SETTING);

CGprofile gpProfile = cgGLGetLatestProfile(CG_GL_GEOMETRY);


if (gpProfile == CG_PROFILE_UNKNOWN) {
    if (cgGLIsProfileSupported(CG_PROFILE_GLSLG))
        gpProfile = CG_PROFILE_GLSLG;
    else {
        fprintf(stderr, "%s: geometry profile is not available.\n", gpProfile);
        exit(0);
    }
}


cgGLSetOptimalOptions(gpProfile);
OpenGLRenderer::checkForCgError("selecting geometry profile");

CGprogram prog = cgCreateProgram(myCgContext, 
                                    CG_SOURCE, 
                                    "geometry_particles.cg",
                                    gpProfile, 
                                    "geometry_passthru",
                                    NULL);
OpenGLRenderer::checkForCgError("Geometry program");

When I call the function checkForCgError, the compiler throws the following error message: The compiler returned an error. (1) : error C0000: syntax error, unexpected '.', expecting "::" at token '.'

My geometry shader is located in the file "geometry_particles.cg" and the code is

// Geometry pass-through program for colored triangles
void geometry_passthru(AttribArray<float4> position : POSITION, 
                    AttribArray<float4> color   : COLOR)
{
    for (int i = 0; i < 3; i++) 
    {
        emitVertex(position[i] :POSITION, color[i] : COLOR);
    }
}

Any thoughts on why the compiler is throwing that error. Am I missing a flag when setting up the shader?


Solution

  • Okay, haven't seen that without closer look at source. You using cgCreateProgram, which takes program source, not file name. Compiler tried to parse given string as cg source code, which it isn't - and reported an error.

    What you wanted to use is cgCreatePgrogramFromFile, or load file contents manually. E.g.

    CGprogram program = cgCreateProgramFromFile(myCgContext,
                                            CG_SOURCE,
                                            "geometry_particles.cg",
                                            gpProfile,
                                            "geometry_passthru",
                                            NULL);
    

    About your cgc empty output - I've never used it on windows, so can't say about that. Maybe setting option to output to file (-o out_file) would help.