Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to do texture mapping using OpenGL 3.3 and GLSL 150.

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

My texcords are in a vertex array. I have my fragment color set to the texture values and texel values. I have my vertex shader sending the texture 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

uniform sampler2D texture;     
in vec2 texture_coord;

varying vec3 texture_coordinate;      
void main(void) {
    gl_FragColor = texture(texture, texture_coord);
}

Vertex shader

#version 150

in vec4 position;
out vec2 texture_coordinate; 
out vec2 texture_coord;
uniform vec3 translations;

void main() {    
    texture_coord = (texture_coordinate);
    gl_Position = vec4(position.xyz + translations.xyz, 1.0);  
}

Last bit

Here is my vertex array with texture coordinates:

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

If you need to see all the code, here is a link to every file.

Thank you for your help.

share|improve this question
2  
If you're using OpenGL v3.3, why aren't you using GLSL 3.30? Why use 1.50? –  Nicol Bolas Mar 26 '12 at 19:27
add comment

1 Answer

  1. In your vertex shader, texture_coordinate is declared as an out variable, but you use it as if it were an input. You might be collecting trash data here. You meant it to be an attribute (deprecated in GLSL 1.50, that's just in for your vertex shader.) It's surprising you didn't get at least a warning (which you probably have but didn't notice, are you checking the error log?)

  2. texture_coordinate and texture_coord are both vec2, but then in your fragment shader, texture_coordinate is a vec3, so types do not match.

  3. varying is deprecated in GLSL 1.50 so I encourage you not to use it. It's inferred from the in/out qualifiers in each shader and the different interpolation qualifiers (smooth, flat and noperspective.)

There are several problems in your shader which seem to be the consequence of heavy copy-pasting from tutorials involving different GLSL versions. You might want to check GLSL 1.50 reference thoroughly and the error log to avoid these.

share|improve this answer
    
Thank you for your help but my problem presists instead of the texture showing properly the quad looks like a single colour even tho its one colour of the actual image because if I tweak the ins and outs you can see a different shade of red. here are my shaders ideone.com/kMXNZ –  RubyKing Mar 24 '12 at 15:46
1  
@RubyKing of course. texture_coordinate and texture_coord are not the same. Your fragment shader is plain wrong. PLEASE check your error log before asking. –  kaoD Mar 24 '12 at 16:01
    
I wasn't going to post again till I seen the logs but my error logs doesn't even show I just see compilations text on cmd and shader errors on there but no actual logs in my exe directory so its rather difficult to read the log and could you explain what is wrong with my fragment shader or tell me how you learnt GLSL 150 ? because I'm having trouble finding information on very basic topics eg,(texture mapping) thank you in advance –  RubyKing Mar 24 '12 at 16:25
2  
@RubyKing those shader errors are the logs. Fix the shader errors and then your shader might work... How do you think your shader is going to work properly if there are errors? To learn GLSL read the reference that I linked in the answer. You are not going to learn anything by copy-pasting code from tutorials (which is obviously what you're doing.) –  kaoD Mar 24 '12 at 18:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.