   Failing to locate uniform variables.
  Hi there. Once again I'm stuck with my program but this time it has to do with my uniform variables in a shader (not mine). I'm trying to do a multipass rendering but when I go through the first pass (simply called firstPass() in the code and called in the display function) it fails to locate the uniform variables found in the first.vert shader. I've tried looking into this for hours but haven't solved the problem. Hopefully someone might see what wrong I'm doing//////////////////////////////////////////////////////////////////////////////(Updated***) Solved temporary. Problem described below is the only one I need help with at the moment.Also while this is a smaller issue it still bugs me, as soon as I start to use frambuffer objects and textures for drawing on a quad my scene becomes extremely zoomed in. This happened last time as well when I did multipass rendering (which at least worked back then but the object was zoomed in alot)Here's all the code and all shaders I'm using:Code (updated***):#include <stdlib.h>#include <GL/glew.h>#include <GL/gl.h>#include <GL/glut.h>#include <stdio.h>#include <time.h>#include <sys/stat.h>#include <math.h>#include <iostream>GLuint windowWidth = 700;GLuint windowHeight = 700;GLuint texture[5];GLint programObj1;GLint programObj6;GLuint fbo;GLuint depthbuffer;GLfloat whiteSpecularLight[] = {1.0, 1.0, 1.0};GLfloat whiteSpecularMaterial[] = {1.0, 1.0, 1.0};GLfloat mShininess[] = {50};GLuint img0; //First offscreen renderGLuint img1; //Second offscreen renderfloat focalDistance = -7.0f;float focalRange = 6.0f;GLint loc;int mouse_old_x; //Position of the mouseint mouse_old_y; // Position of the mousebool rotate; static float xRot; static float yRot; //Function prototypesvoid light(void);void skybox(void);void teapots(void);void drawQuad(void);void init(void);//Read shader fileschar* readShaderFile(const char *filename) {  FILE *file;  struct stat st;    file = fopen(filename, "r");    if(file == NULL){    fprintf( stderr, "ERROR: Cannot open shader file!");    return 0;  }    stat(filename,&st);    int bytesinfile = st.st_size;  char *buffer = (char*)malloc(bytesinfile+sizeof(char));  int bytesread = fread( buffer, 1, bytesinfile, file);  buffer[bytesread] = 0; // Terminate the string with 0  fclose(file);    return buffer;}//Create shadersvoid createShaders() {  std::cout<< "Hej create shaaaaaaaaaaaaaaders" << std::endl;  GLint vertexShader1 = glCreateShader(GL_VERTEX_SHADER); //Create vertex shader  GLint vertexShader6  = glCreateShader(GL_VERTEX_SHADER);    const char *vertexAssembly1 = readShaderFile("first.vert"); //Read vertex shader file  const char *vertexAssembly6 = readShaderFile("fifth.vert");  glShaderSource( vertexShader1, 1, &vertexAssembly1, NULL );  glShaderSource( vertexShader6, 1, &vertexAssembly6, NULL );  glCompileShader( vertexShader1);  glCompileShader( vertexShader6);  free((void *)vertexAssembly1);  free((void *)vertexAssembly6);    GLint isCompiled;  glGetShaderiv( vertexShader1, GL_COMPILE_STATUS, &isCompiled );   if(isCompiled == GL_FALSE){    char str[256];    glGetShaderInfoLog(vertexShader1, 256, NULL, str);    fprintf( stderr, "Vertex shader compile error: %s\n", str);  }  glGetShaderiv( vertexShader6, GL_COMPILE_STATUS, &isCompiled );  if(isCompiled == GL_FALSE){    char str[256];    glGetShaderInfoLog(vertexShader6, 256, NULL, str);    fprintf( stderr, "Vertex shader compile error: %s\n", str);  } GLint fragmentShader1 = glCreateShader( GL_FRAGMENT_SHADER ); //Create fragmet shader  GLint fragmentShader6 = glCreateShader( GL_FRAGMENT_SHADER );    const char *fragmentAssembly1 = readShaderFile( "first.frag" ); //Read fragment shader file  const char *fragmentAssembly6 = readShaderFile( "renderblur.frag" );  glShaderSource( fragmentShader1, 1, &fragmentAssembly1, NULL );  glShaderSource( fragmentShader6, 1, &fragmentAssembly6, NULL );  glCompileShader( fragmentShader1 );  glCompileShader( fragmentShader6 );  free((void *)fragmentAssembly1);  free((void *)fragmentAssembly6);    glGetShaderiv( fragmentShader1, GL_COMPILE_STATUS, &isCompiled );    if(isCompiled == GL_FALSE){    char str[256];    glGetShaderInfoLog( fragmentShader1, 256, NULL, str );    fprintf( stderr, "Fragment shader compile error: %s\n", str );  }  glGetShaderiv( fragmentShader6, GL_COMPILE_STATUS, &isCompiled );  if(isCompiled == GL_FALSE){    char str[256];    glGetShaderInfoLog( fragmentShader6, 256, NULL, str );    fprintf( stderr, "Fragment shader compile error: %s\n", str );  }    programObj1 = glCreateProgram();  programObj6 = glCreateProgram();  glAttachShader( programObj1, vertexShader1 );  glAttachShader( programObj6, vertexShader6 );  glAttachShader( programObj1, fragmentShader1 );  glAttachShader( programObj6, fragmentShader6 );    glLinkProgram( programObj1 );  glLinkProgram( programObj6 );  GLint isLinked;  glGetProgramiv( programObj1, GL_LINK_STATUS, &isLinked );    if( isLinked == GL_FALSE ){    char str[256];    glGetProgramInfoLog( programObj1, 256, NULL, str );    fprintf( stderr, "Program object linking error: %s\n", str );  }  glGetProgramiv( programObj6, GL_LINK_STATUS, &isLinked );    if( isLinked == GL_FALSE ){    char str[256];    glGetProgramInfoLog( programObj6, 256, NULL, str );    fprintf( stderr, "Program object linking error: %s\n", str );  }}//Method for deleting texture once they've been usedvoid FreeTexture( GLuint texture ){  glDeleteTextures( 1, &texture );}//Loading the textures that will be used for the skyboxGLuint LoadTexture( const char * filename, int width, int height ){    GLuint texture;    unsigned char * data;    FILE * file;    //This code read the raw files.    file = fopen( filename, "rb" );    if ( file == NULL ) return 0;   data = (unsigned char *)malloc( width * height * 3 );    fread( data, width * height * 3, 1, file );    fclose( file );    glGenTextures( 1, &texture ); //Generate texture    glBindTexture( GL_TEXTURE_2D, texture ); //Bind texture to texture array declared above    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); //texture environment parameters    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);    free( data ); //free the texture    return texture; //return whether it was successfull}//Keyboard controlsvoid keyboard(unsigned char key, int x, int y){if(key==27) //27 is ASCI-code for ESC key{exit(0); //Exit the program}}void processMouse(int button, int state, int x, int y) {if ((state == GLUT_DOWN) && (button == GLUT_LEFT_BUTTON)){ rotate=true;}else   {    rotate=false;   }mouse_old_x =x;mouse_old_y =y;}void processMouseActiveMotion(int x, int y) {float weight =0.2;if(rotate) {   xRot += (x-mouse_old_x) * weight;   yRot += (y-mouse_old_y) * weight;   }mouse_old_x =x;mouse_old_y =y;}void initFbo(){//Create a framebuffer objectglGenFramebuffersEXT(1, &fbo); //Frame bufferglGenRenderbuffersEXT(1, &depthbuffer); //render bufferglGenTextures(1, &img0); //textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo);//initialize textureglBindTexture(GL_TEXTURE_2D, img0);glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,windowWidth,windowHeight,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);//texture parametersglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);  glGenerateMipmapEXT(GL_TEXTURE_2D);//attach texture to framebuffer color bufferglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, img0,0);//initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer);glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT24,windowWidth,windowHeight);//attach renderbuffer to framebuffer depth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,depthbuffer);}void firstPass(){init();glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glActiveTexture(GL_TEXTURE0);glUseProgram(programObj1);loc = glGetUniformLocation(programObj1, "focalDistance");if(loc == -1)fprintf(stderr, "Binding warning: Failed to locate uniform variable 'focalDistance'.\n"); glUniform1f(loc, focalDistance);loc = glGetUniformLocation(programObj1, "focalRange");if(loc == -1)fprintf(stderr, "Binding warning: Failed to locate uniform variable 'focalRange'.\n"); glUniform1f(loc, focalRange);light();skybox();teapots();}void blurTestPass(){glEnable(GL_TEXTURE_2D);glDisable(GL_LIGHTING);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);glDrawBuffer(GL_BACK);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glOrtho(0.0,1.0,0.0,1.0,0.0,1.0);glColor4f(1.0,1.0,1.0,0.0);glBindTexture(GL_TEXTURE_2D, img0);glUseProgram(programObj6);drawQuad();}void display(){glClearColor(0.0,0.0,0.0,1.0);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glClearDepth(1);glLoadIdentity();firstPass();blurTestPass();glutSwapBuffers(); //Swap between the two buffers}void reshape(int w, int h){glViewport(0,0,(GLsizei)w,(GLsizei)h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60.0,(GLfloat)w/(GLfloat)h,0.1,10000.0);glMatrixMode(GL_MODELVIEW); }int main(int argc, char **argv){glutInit(&argc, argv); //Initialize GLUTglutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA| GLUT_DEPTH); //Use a double buffer when displaying frames.glutInitWindowSize(windowWidth, windowHeight); glutInitWindowPosition(100, 100); glutCreateWindow("Test");init();glewInit();initFbo();glutDisplayFunc(display); glutIdleFunc (display);glutReshapeFunc(reshape); glutKeyboardFunc(keyboard);glutMouseFunc(processMouse);glutMotionFunc(processMouseActiveMotion);texture[0] = LoadTexture( "skylf.raw", 512, 512 );texture[1] = LoadTexture( "skyft.raw", 512, 512 );texture[2] = LoadTexture( "skyrt.raw", 512, 512 );texture[3] = LoadTexture( "skybk.raw", 512, 512 );texture[4] = LoadTexture( "skydn.raw", 512, 512 );texture[5] = LoadTexture( "skyup.raw", 512, 512 );   createShaders();glutMainLoop(); //Start the OpenGL loop-cyclefor(int i=0; i<6; i++){FreeTexture(texture);}return 0;}//////////////////////////////////////////////////////////////////////////Draw skybox, teapots and quad for texture. Lighting properties//////////////////////////////////////////////////////////////////////////void skybox(){  float quadSize = 1000.0; //Size of each quad   glPushMatrix();    glLoadIdentity(); //Loading identity matrix    gluLookAt(0.0,0.0,0.0,0.0,0.0,1.0,0.0,-1.0,0.0); //Setting up the camera for the scene. The cameras position is located in origo. This is because we want to be inside the skybox.    glPushAttrib(GL_ENABLE_BIT);    glEnable(GL_TEXTURE_2D);    glDisable(GL_LIGHTING);    glColor4f(1,1,1,1); //Set color for the quad    //Create and bind a texture for the front quad    glBindTexture(GL_TEXTURE_2D, texture[0]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f(  quadSize, -quadSize, -quadSize );   glTexCoord2f(1, 0); glVertex3f( -quadSize, -quadSize, -quadSize );   glTexCoord2f(1, 1); glVertex3f( -quadSize,  quadSize, -quadSize );   glTexCoord2f(0, 1); glVertex3f(  quadSize,  quadSize, -quadSize );    glEnd();    //Create and bind a texture for the left quad    glBindTexture(GL_TEXTURE_2D, texture[1]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f(  quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 0); glVertex3f(  quadSize, -quadSize, -quadSize );   glTexCoord2f(1, 1); glVertex3f(  quadSize,  quadSize, -quadSize );   glTexCoord2f(0, 1); glVertex3f(  quadSize,  quadSize,  quadSize );    glEnd();    //Create and bind a texture for the back quad    glBindTexture(GL_TEXTURE_2D, texture[2]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f( -quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 0); glVertex3f(  quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 1); glVertex3f(  quadSize,  quadSize,  quadSize );   glTexCoord2f(0, 1); glVertex3f( -quadSize,  quadSize,  quadSize );    glEnd();    //Create and bind a texture for the right quad    glBindTexture(GL_TEXTURE_2D, texture[3]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f( -quadSize, -quadSize, -quadSize );   glTexCoord2f(1, 0); glVertex3f( -quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 1); glVertex3f( -quadSize,  quadSize,  quadSize );   glTexCoord2f(0, 1); glVertex3f( -quadSize,  quadSize, -quadSize );    glEnd();    //Create and bind a texture for the top quad    glBindTexture(GL_TEXTURE_2D, texture[4]);    glBegin(GL_QUADS);   glTexCoord2f(0, 1); glVertex3f( -quadSize,  quadSize, -quadSize );   glTexCoord2f(0, 0); glVertex3f( -quadSize,  quadSize,  quadSize );   glTexCoord2f(1, 0); glVertex3f(  quadSize,  quadSize,  quadSize );   glTexCoord2f(1, 1); glVertex3f(  quadSize,  quadSize, -quadSize );    glEnd();    //Create and bind a texture for the bottom quad    glBindTexture(GL_TEXTURE_2D, texture[5]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f( -quadSize, -quadSize, -quadSize );   glTexCoord2f(0, 1); glVertex3f( -quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 1); glVertex3f(  quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 0); glVertex3f(  quadSize, -quadSize, -quadSize );    glEnd();    // Restore enable bits and matrix    glPopAttrib();    glPopMatrix();    //Return states    glDisable(GL_TEXTURE_2D);}//Enable lighting and color material of objectsvoid init(){    glEnable(GL_DEPTH_TEST);    glEnable(GL_LIGHTING);    glEnable(GL_LIGHT0);    glEnable(GL_COLOR_MATERIAL);}//Lighting propertiesvoid light(){glLightfv(GL_LIGHT0, GL_SPECULAR, whiteSpecularLight);glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);   glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);}//Render teapots with a rotational value depending on the movement of the mousevoid teapots(){//Blue teapotglPushMatrix();glColor4f(0.64,0.67,0.84,1.0);glTranslatef(3.0,0.0,-14.0);glRotatef(xRot,0.0,1.0,0.0);glRotatef(yRot,1.0,0.0,0.0);glutSolidTeapot(1);glPopMatrix();//Pink teapotglPushMatrix();glColor4f(0.79,0.63,0.72,1.0);glTranslatef(1.0,0.0,-11.0);glRotatef(xRot,0.0,1.0,0.0);glRotatef(yRot,1.0,0.0,0.0);glutSolidTeapot(1);glPopMatrix();//Green teapotglPushMatrix();glColor4f(0.64,0.67,0.49,1.0);glTranslatef(-1.0,0.0,-7.0);glRotatef(xRot,0.0,1.0,0.0);glRotatef(yRot,1.0,0.0,0.0);glutSolidTeapot(1);glPopMatrix();}void drawQuad(void){glBegin(GL_QUADS);glTexCoord2f(0.0f, 0.0f);glVertex2d(0, 0);glTexCoord2f(1.0f, 0.0f);glVertex2d(1, 0);glTexCoord2f( 1.0f, 1.0f);glVertex2d(1, 1);glTexCoord2f(0.0f, 1.0f);glVertex2d(0, 1);glEnd();}Vertex shader:uniform float focalDistance, focalRange;varying float Blur;void main(void){vec4 PosWV = gl_ModelViewMatrix * gl_Vertex;Blur = clamp(abs(-PosWV.z - focalDistance) / focalRange, 0.0, 1.0); gl_Position = ftransform();  gl_TexCoord[0] = gl_MultiTexCoord0; }Fragment shadervarying float Blur;uniform sampler2D Tex0;void main (void){gl_FragData[0] = vec4(texture2D(Tex0, gl_TexCoord[0].st).rgb, Blur);}[Edited by - Zaftwave on May 14, 2010 7:28:08 AM]