Skip to main content
gamedev.net
🔒 Locked 🎯 Unreal

GLSL Texturing Problem.

Started by Deftoned 0 replies 550+ views
Original Post
Deftoned
Deftoned
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:
void main()
{	
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_Position = ftransform();		
}
Fragment:
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);
}
Drawing

	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);
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.
swiftcoder
swiftcoder
1) Have you printed out the glsl compilation and linking logs? They are invaluable in debugging shaders.
2) Your shader needs texture-coordinates, but you are only providing vertices.
3) Why are you manually filtering the texture? Bilinear filtering (GL_LINEAR) is supported on pretty much any shader-capable hardware.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.