The main code is listed as the following:

c++ code:
Code :
readShaderSource("directsampler", &VertexShaderSource, &FragmentShaderSource);
success=installShaders(VertexShaderSource, FragmentShaderSource);
 
......
 
GLint baseImageLoc;
 
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 666);
 
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,128,128,0,GL_RGB,GL_UNSIGNED_BYTE,myDemonTextureImage);
 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
 
glUseProgram(progi);
baseImageLoc = getUniLoc(progi, "baseImage");
glUniform1i(baseImageLoc, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 666);
 
......
 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
	glTexCoord2f(0, 0);
	glVertex2f(-0.8, 0.8);
 
	glTexCoord2f(1, 0);
	glVertex2f(0.8, 0.8);
 
	glTexCoord2f(0.5, 1);
	glVertex2f(0.0, -0.8);
glEnd();
glutSwapBuffers();

vertex shader:
Code :
 
varying vec2 texcoord;
 
void main()
{
	gl_Position = ftransform();
	texcoord = vec2(gl_MultiTexCoord0);
}

fragment shader:
Code :
 
uniform sampler2D baseImage;
 
varying vec2 texcoord;
 
void main(void)
{
	gl_FragColor=texture2D(baseImage,texcoord);
}

The most error-prone part is the c++ code, because v/f shaders are both compiled and linked well.
Any idea will be appreciated and thanks in advance!