Hi all,

I am new to open GLES application development. I developed an Open GLES application using shaders. The shaders are compiled successfully, but linking the shader is failing with no log messages.

Following is the code snippet:
BOOL InitOGLES(NativeWindowType window)
{
EGLConfig configs;
EGLint matchingConfigs;

static const EGLint configAttribs[] =
{
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_LUMINANCE_SIZE, EGL_DONT_CARE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_SAMPLES, 0,
EGL_NONE
};

glesDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
assert(eglGetError()==EGL_SUCCESS);

eglInitialize(glesDisplay, NULL, NULL);
assert(eglGetError()==EGL_SUCCESS);
eglBindAPI(EGL_OPENGL_ES_API);

eglChooseConfig(glesDisplay, configAttribs, &configs, 1, &matchingConfigs);
assert(eglGetError()==EGL_SUCCESS);

assert(matchingConfigs == 1);

glesSurface = eglCreateWindowSurface(glesDisplay, configs, window, NULL);
assert(eglGetError()==EGL_SUCCESS);

glesContext=eglCreateContext(glesDisplay,configs,0 ,NULL);
assert(eglGetError()==EGL_SUCCESS);

eglMakeCurrent(glesDisplay, glesSurface, glesSurface, glesContext);
assert(eglGetError()==EGL_SUCCESS);

eglSwapBuffers(glesDisplay, glesSurface);
assert(eglGetError() == EGL_SUCCESS);

const CHAR* g_strVSProgram =
"attribute vec4 g_vVertex; \n"
"attribute vec4 g_vColor; \n"
"varying vec4 g_vVSColor; \n"
" \n"
"void main() \n"
"{ \n"
" gl_Position = vec4( g_vVertex.x, g_vVertex.y, \n"
" g_vVertex.z, g_vVertex.w ); \n"
" g_vVSColor = g_vColor; \n"
"} \n";
const CHAR* g_strFSProgram =
"#ifdef GL_FRAGMENT_PRECISION_HIGH \n"
" precision highp float; \n"
"#else \n"
" precision mediump float; \n"
"#endif \n"
" \n"
"varying vec4 g_vVSColor; \n"
" \n"
"void main() \n"
"{ \n"
" gl_FragColor = g_vVSColor; \n"
"} \n";
GLuint vertexShader=0;
GLuint fragmentShader=0;
GLint linked;

// Create vertex shader
GLuint hVertexShader = glCreateShader( GL_VERTEX_SHADER );
if(hVertexShader == 0)
return 0;

glShaderSource( hVertexShader, 1, &g_strVSProgram, NULL );
glCompileShader( hVertexShader );

GLint nCompileVertexResult = 0;
glGetShaderiv(hVertexShader, GL_COMPILE_STATUS,&nCompileVertexResult);
if (!nCompileVertexResult)
{
GLint infoLen = 0;
glGetShaderiv(hVertexShader, GL_INFO_LOG_LENGTH, &infoLen);
if(infoLen > 1)
{
CHAR Log[1024];
GLint nLength;
glGetShaderInfoLog(hVertexShader, 1024, &nLength, Log);
return FALSE;
}
glDeleteShader(hVertexShader);
}

//Create fragment shader
GLuint hFragmentShader = glCreateShader( GL_FRAGMENT_SHADER );
glShaderSource( hFragmentShader, 1, &g_strFSProgram, NULL );
glCompileShader( hFragmentShader );

GLint nCompileResult = 0;
//Check the compile status
glGetShaderiv(hFragmentShader, GL_COMPILE_STATUS,&nCompileResult);
if (!nCompileResult)
{
GLint infoLen = 0;
glGetShaderiv(hFragmentShader, GL_INFO_LOG_LENGTH, &infoLen);
if(infoLen > 1)
{
CHAR Log[1024];
GLint nLength;
glGetShaderInfoLog(hFragmentShader, 1024, &nLength, Log);
return FALSE;
}
glDeleteShader(hFragmentShader);
}

// Create the program object
programObject = glCreateProgram();
if(programObject == 0)
return 0;
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
// Bind vPosition to attribute 0
glBindAttribLocation(programObject, 0, "g_vVertex");
glBindAttribLocation(programObject, 1, "g_vColor");

// Link the program
glLinkProgram(programObject);
// Check the link status
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
if(!linked)
{
GLint infoLen = 0;
glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
if(infoLen != 0)
{
CHAR Log[1024];
GLint nLength;
glGetProgramInfoLog(programObject, 1024, &nLength, Log);
RETAILMSG(DBG,(_T("Log %s\r\n"),Log));
return FALSE;
}
glDeleteProgram(programObject);
glDeleteShader( hVertexShader );
glDeleteShader( hFragmentShader );
return FALSE;
}

return TRUE;
}

void Render()
{

FLOAT fSize = 0.5f;
FLOAT VertexPositions[] =
{
0.0f, +fSize*g_fAspectRatio, 0.0f, 1.0f,
-fSize, -fSize*g_fAspectRatio, 0.0f, 1.0f,
+fSize, -fSize*g_fAspectRatio, 0.0f, 1.0f,
};
FLOAT VertexColors[] = {1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f
};
// Clear the backbuffer and depth-buffer
glClearColor( 0.0f, 0.0f, 0.5f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

// Set the shader program and the texture
glUseProgram( g_hShaderProgram );

// Draw the colored triangle
glVertexAttribPointer( 0, 4, GL_FLOAT, 0, 0, VertexPositions );

glEnableVertexAttribArray( 0 );

glVertexAttribPointer( 1, 4, GL_FLOAT, 0, 0, VertexColors);

glEnableVertexAttribArray( 1 );

glDrawArrays( GL_TRIANGLE_STRIP, 0, 3 );

glDisableVertexAttribArray( 0 );

glDisableVertexAttribArray( 1 );

eglSwapBuffers(glesDisplay, glesSurface);
assert(eglGetError() == EGL_SUCCESS);

}

Can any one please tell me what is wrong in this code.

Thanks and regards,
Sowmya