Proper way to do texture mapping in modern OpenGL?

Posted by RubyKing on Game Development See other posts from Game Development or by RubyKing
Published on 2012-03-24T13:49:45Z Indexed on 2012/03/26 23:41 UTC
Read the original article Hit count: 191

Filed under:
|
|

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.

© Game Development or respective owner

Related posts about c++

Related posts about opengl