OpenGL Shading Language Tutorials

Tutorial 6 : Texturing


In this Tutorial we want to use the same texturing as the original OpenGL program, i.e. if you remove shaders it should look same way.

I load 2 textures and use glBindTexture(..) before drawing a teapot.

 

Vertex Shader Source

void main(void)
{
 gl_TexCoord[0] = gl_MultiTexCoord0;
 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 
}


gl_MultiTexCoord0: Our texture is in unit 0, we fill the predefined varying variable gl_TexCoord[0] with it. (In Tutorial 8 we will learn more about multitexturing).

Fragment Shader Source

uniform sampler2D myTexture;
void main (void)
{
  gl_FragColor  = texture2D(myTexture, vec2(gl_TexCoord[0]));         
}

 

Go to Tutorial 7


Author: Martin Christen, christen@clockworkcoders.com
(source code is included in Tutorial Version 0.2 and higher)

 

 

© 2003 by Martin Christen. All Rights Reserved.
christen@clockworkcoders.com