Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: trying to do texture mapping in GLSL 150

  1. #1
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    67

    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

    Code :
    #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


    Code :
    #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

    Code :
                        // 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

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: trying to do texture mapping in GLSL 150

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

  3. #3
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    67

    Re: trying to do texture mapping in GLSL 150

    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


    Code :
                        // 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

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    381

    Re: trying to do texture mapping in GLSL 150

    As Dark Photon said, you're setting an output from another output value, so maybe:
    Code :
    out vec2 texture_coordinate;
    should be:
    Code :
    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.

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: trying to do texture mapping in GLSL 150

    Quote Originally Posted by noobscratcher
    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);
    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

    Code :
      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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •