PDA

View Full Version : Linker error on Nividia + win32



Pushpak
02-25-2005, 11:42 AM
Hi,

I have written a very basic shader and am trying to get it to run. I can load and compile the vertex shader and the fragment shader. When linking, however, the log returns : "error C3001: no program defined"

Here is my code snipper


// Create an empty program object
PFNGLCREATEPROGRAMOBJECTARBPROC programObject =
(PFNGLCREATEPROGRAMOBJECTARBPROC) wglGetProcAddress("glCreateProgramObjectARB");

program_handle = programObject();

// Now attach the vertex and fragment shaders to this program object
PFNGLATTACHOBJECTARBPROC attachObject =
(PFNGLATTACHOBJECTARBPROC) wglGetProcAddress("glAttachObjectARB");

attachObject( program_handle, vertex_shader_handle );
attachObject( program_handle, fragment_shader_handle );

// Now link it all together to send to the GPU
PFNGLLINKPROGRAMARBPROC linkObjects =
(PFNGLLINKPROGRAMARBPROC) wglGetProcAddress("glLinkProgramARB");

linkObjects( program_handle );

// see if we had any errors
int result=-1;
PFNGLGETOBJECTPARAMETERIVARBPROC getObjectParamI =
(PFNGLGETOBJECTPARAMETERIVARBPROC) wglGetProcAddress("glGetObjectParameterivARB");

getObjectParamI( program_handle, GL_OBJECT_LINK_STATUS_ARB, &result );

if( result == GL_FALSE )
{
Log( Fmt("Could not link the specified objects. See log for details."));
PFNGLGETINFOLOGARBPROC getLogInfo =
(PFNGLGETINFOLOGARBPROC) wglGetProcAddress("glGetInfoLogARB");

getLogInfo( program_handle, 1024, &length, log );
Log(Fmt("%s", log) );
} Is there something wrong here ? I have defined the vertex_shader_handle, fragment_shader_handle and program_handle as member variables of my class and they have been initialized appropriately.

jra101
02-25-2005, 01:44 PM
Can you post the shaders as well as the code you are using to compile the vertex and fragment shaders?

Pushpak
02-25-2005, 02:30 PM
here is the code

vertex shader:


varying vec3 N;
varying vec3 v;

void main(void)
{
v = vec3(gl_ModelViewMatrix * gl_Vertex);
N = normalize(gl_NormalMatrix * gl_Normal);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
} fragment shader:


varying vec3 N;
varying vec3 v;

void main (void)
{

vec3 L = normalize(gl_LightSource[0].position.xyz - v);

// we are in Eye Coordinates, so EyePos is (0,0,0)
vec3 E = normalize(-v);
vec3 R = normalize(-reflect(L,N));

//calculate Ambient Term:
vec4 Iamb = gl_FrontLightProduct[0].ambient;

//calculate Diffuse Term:
vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L),0.0);

// calculate Specular Term:
vec4 Ispec = gl_FrontLightProduct[0].specular * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shinine ss);

// write Total Color:
gl_FragColor = vec4(0.5,0.5,0.5,1.0) + Iamb + Idiff + Ispec;
} Its just a basic Phong shading model.

thanks for your reply :-)

pushpak

Pushpak
02-25-2005, 03:11 PM
and here is the code to compile the shaders.
I have also added the code to validate the program object after attaching the shaders, and that returns success !!


void CShaderView::OnShaderCompileshaders()
{
// TODO: CheckExtensionSupport();

// Logging support
char *log = new char[1024];
int length=0;

// Compile the Vertex Shader
Log( Fmt("Compiling vertex shader: " ) + vertex_shader_filename );

// Define a vertex shader handle
PFNGLCREATESHADEROBJECTARBPROC shaderObject =
(PFNGLCREATESHADEROBJECTARBPROC) wglGetProcAddress("glCreateShaderObjectARB");

vertex_shader_handle = shaderObject(GL_VERTEX_SHADER_ARB);
Log( Fmt("Creating handle ...."));

// Load the source code
PFNGLSHADERSOURCEARBPROC shaderSource =
(PFNGLSHADERSOURCEARBPROC) wglGetProcAddress("glShaderSourceARB");

shaderSource(vertex_shader_handle, 1,
(const GLcharARB **) (&vertex_shader_program),
NULL );

Log( Fmt("Loading Vertex Shader source ...."));

PFNGLCOMPILESHADERARBPROC compileShader =
(PFNGLCOMPILESHADERARBPROC) wglGetProcAddress("glCompileShaderARB");

Log( Fmt("Compiling Vertex Shader source ...."));
compileShader( vertex_shader_handle );

// Check status of compilation
PFNGLGETOBJECTPARAMETERIVARBPROC statusCheck =
(PFNGLGETOBJECTPARAMETERIVARBPROC) wglGetProcAddress("glGetObjectParameterivARB");
PFNGLGETINFOLOGARBPROC info =
(PFNGLGETINFOLOGARBPROC) wglGetProcAddress("glGetInfoLogARB");

int result;
statusCheck( vertex_shader_handle, GL_OBJECT_COMPILE_STATUS_ARB, &result );

if( result == GL_FALSE )
{
Log( Fmt("Compilation Failed. Transcript of log follows...."));
info( vertex_shader_handle, 1024, &length, log );

Log( Fmt("%s", log ));
}
else
{
Log( Fmt("Compilation Successful ..."));
}

/////////////////////////////////////////////////////////////////////////
// Compile the Fragment Shader
Log( Fmt("Compiling fragment shader: " ) + fragment_shader_filename );

// Define the fragment handle
PFNGLCREATESHADEROBJECTARBPROC fragmentObject =
(PFNGLCREATESHADEROBJECTARBPROC) wglGetProcAddress("glCreateShaderObjectARB");

// Define the handle
Log( Fmt("Creating handle ...."));
fragment_shader_handle = fragmentObject(GL_FRAGMENT_SHADER_ARB);

// Load the source
Log( Fmt("Loading Fragment Shader source ...."));
shaderSource(fragment_shader_handle, 1,
(const GLcharARB **) (&fragment_shader_program),
NULL );

// Compile the shader
Log( Fmt("Compiling Fragment Shader source ...."));
compileShader( fragment_shader_handle );

// check status
statusCheck( fragment_shader_handle, GL_OBJECT_COMPILE_STATUS_ARB, &result );

if( result == GL_FALSE )
{
Log( Fmt("Compilation Failed. Transcript of log follows...."));
info( vertex_shader_handle, 1024, &length, log );

Log( Fmt("%s", log ));
}
else
{
Log( Fmt("Compilation Successful ..."));
}
//////////////////////////////////////////////////////////////////////////


delete [] log;
log = NULL;

return;
}thanks
pushpak

Pushpak
02-25-2005, 04:19 PM
Got it !!!!

Basically I had my file reading code incorrect !! have rectified that and now everything works like a charm :-)

Thanks for replying !!

pushpak