Original Post
Hey Guys, I am having a problem where i create a texure based from 4 other textures, and i pass that into a shader Vertex: Fragment: Drawing After it uses the program i just get a memory error and it crashed, this is my first try of using sampler2D, i have no idea what is going on. Any suggestions of what coudl be wrong would be greatly appreciated.
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
uniform sampler2D colorMap;
#define textureWidth 1024.0
#define textureHeight 1024.0
#define texel_size_x 1.0 / textureWidth
#define texel_size_y 1.0 / textureHeight
vec4 texture2D_bilinear( sampler2D tex, vec2 uv )
{
vec2 f;
f.x = fract( uv.x * textureWidth );
f.y = fract( uv.y * textureHeight );
vec4 t00 = texture2D( tex, uv + vec2( 0.0, 0.0 ));
vec4 t10 = texture2D( tex, uv + vec2( texel_size_x, 0.0 ));
vec4 tA = mix( t00, t10, f.x);
vec4 t01 = texture2D( tex, uv + vec2( 0.0, texel_size_y ) );
vec4 t11 = texture2D( tex, uv + vec2( texel_size_x, texel_size_y ) );
vec4 tB = mix( t01, t11, f.x );
return mix( tA, tB, f.y );
}
void main (void)
{
gl_FragColor = texture2D_bilinear( colorMap, gl_TexCoord[0].st);
}
glUseProgram(coloursProg);
glUniform1i(texture2D, terrain->m_finalTextureInt);
glDisable(GL_CULL_FACE);
glPushMatrix();
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glVertex3f(50, 50, 50);
glVertex3f(100, 50, 50);
glVertex3f(100, 100, 50);
glVertex3f(50, 100, 50);
glEnd();
glPopMatrix();
glEnable(GL_CULL_FACE);
glUseProgram(0);