0

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • I can't reproduce given error message. Does it persists if you compile it with standalone `cgc`? (`cgc -entry geometry_passthru -profile gp5gp geometry_particles.cg`). Anyway, in geometry program you have to specify input primitive type, e.g. `TRIANGLE void gemetry_passthrough(...` – keltar May 25 '14 at 07:23
  • @keltar, thanks for the info, i'm not to familiar with using cgc so I followed the instruction on the following site [link](http://www.ogre3d.org/tikiwiki/tiki-index.php?page=How+To+Compile+CG+Files) which just indicates to set up the directory to where the shader file is located. I run the commands, but did not get anything back. I dont know if I'm suppose to get a success/error message. Also, I realized that I forgot to mention that I'm working on Win8.1 if that makes any difference – user3234091 May 26 '14 at 02:23
  • If you run it in cmd, it should output compiled shader's code, or report an error. Have you added `TRIANGLE` specifier before function declaration? Does the same error still persists? – keltar May 26 '14 at 03:28
  • yes, i added triangle before the void keyword and still get the same error in VS2013, after that i launch cgc and follow the instructions on that site, i also moved the shader file to where cgc is located and run the command you provided. On both cases when running the commands no output message was generated – user3234091 May 26 '14 at 03:51

1 Answers1

0

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.

keltar
  • 17,711
  • 2
  • 37
  • 42