Trying to do texture mapping in GLSL 150

Hi all I’m trying to do texture mapping GLSL 150.

The problem is the texture shows but has this weird flicker I can show a video here

<object width=“425” height=“350”> <param name=“movie” value=“http://www.youtube.com/v/xbzw_LMxlHw”></param> <param name=“wmode” value=“transparent”></param> <embed src=“http://www.youtube.com/v/xbzw_LMxlHw” type=“application/x-shockwave-flash” wmode=“transparent” width=“425” height=“350”> </embed></object>

and I have everything setup best I can

have my texcords in my vertex array sent up to opengl

I have my fragment color set to the texture values and texel values I have my vertex sending the textures cords to texture cordinates to be used in the fragment shader I have my ins and outs setup and I still don’t know what I’m missing that could be causing that flicker.

here is my code

Fragment Shader

#version 150
//orginally 130
//orginally 110


//Texture Uniform Sampler 2D Container
uniform sampler2D texture;

in vec2 texture_coord;



varying vec3 texture_coordinate;

//Main Entry Point
void main(void){


     
  

   //To Tell GLSL The Texture and Texture Coords  texture cords is the position
   gl_FragColor = texture(texture, texture_coord);
   
   //vec4(1.0, 0.0, 0.0, 1.0); 
   //gl_FragColor = vec4(texture_coordinate.xy, 0.0, 1.0);
   
  
    
}

vertex shader

#version 150

//Always use a attribute vec4 for position variable
in vec4 position;


//Matrix 3 x 3 row
//mat4 projection;


//Texture Cordinates 2 element vector of varying type

//attribute vec2 texture_coordinate;
out vec2 texture_coordinate; 

out vec2 texture_coord;
//Translations 3 element vector uniform
uniform vec3 translations;


      //Projection Matrix
        //mat4 projection = mat4(
       // vec4(1.0, 0.0, 0.0, 0.0),
       // vec4(0.0, 1.0, 0.0, 0.0),
       // vec4(0.0, 0.0, 1.0, 0.0), 
       // vec4(0.0, 0.0, 0.0, 1.0)); 


//Main Entry Point
void main()
{


      //Passing The Texture Coordinate of Texture Unit 0 To The Fragment Shader
      texture_coord = (texture_coordinate);


  

  // To Put The Vertex in View? //ORGINALLY 8.0
 gl_Position = vec4(position.xyz + translations.xyz, 1.0);

 
  
}

Oh and here is my vertex array with texture cordinates

         
                    // X    //y   //z   //u   //v
GLfloat vVerts[] = {  0.5f, 0.5f, 0.0f, 0.0f, 1.0f , 
                      0.0f, 0.5f, 0.0f, 1.0f, 1.0f, 
                      0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 
                      0.5f, 0.0f, 0.0f, 1.0f, 0.0f};
                                       //tex x and y 
            

thank you for your help

Couple things come to mind:
[ol][]In the vtx shader, your setting the texcoord output with another output. Not what you want[]The order of the tex coord data in your data array doesn’t appear to be in the right order for the positions[*]All else fails, suspect a problem with how you’re setting an enabling the texcoord attribute in the C/C++ code.[/ol]

hmm Would having the first parameter of glVertexAttribPointer like so be a problem

glEnableVertexAttribArray(0);

glVertexAttribPointer(0, 3,GL_FLOAT,GL_FALSE, 5 * sizeof(float),0);

I’ve looked at everything else in my code and changed my tex coords

       
                    // X    //y   //z   //u   //v
GLfloat vVerts[] = {  0.5f, 0.5f, 0.0f, 1.0f, 1.0f , 
                      0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 
                      0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 
                      0.5f, 0.0f, 0.0f, 1.0f, 0.0f};
                                       //tex x and y 

As Dark Photon said, you’re setting an output from another output value, so maybe:


out vec2 texture_coordinate;

should be:


in vec2 texture_coordinate;

As to whether using 0 as the first parameter of glVertexAttribPointer would be a problem - not if you’re setting the location of “texture_coordinate” to 0 with glBindAttribLocation before linking the program, then using 0 would be okay, otherwise you should query the proper location with glGetAttribLocation.

Maybe “position” should be a vec3 instead of a vec4 in your vertex shader too.

Could be. 0 is a special case as it’s always positions (I think). For the rest, you need to ensure you bind the correct vertex attribute to the right name. One fairly trouble-free way to do this is with


  glBindAttribLocation( pgm, 0, "My_Vertex"         );
  glBindAttribLocation( pgm, 8, "My_TexCoord0"      );
  ...

You may have several issues, including the thing about assigning the texcoord in your shader.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.