Shaders took my textures!

So, I decided to implement shaders into my game engine, and it took away my textures! It just renders every shape in color with:

shader.fs


varying vec3 color;

void main() {
    gl_FragColor = vec4(color, 1);
}

shader.vs


varying vec3 color;

void main() {
    color = gl_Color.rgb;
    gl_Position = ftransform();
}

Why are my textures gone!?

Sorry if this is nooby, but I literally just found out about shaders. I literally only know how to load and use them in java. None of the glsl stuffs.

I’ve never used textures with shaders - in fact I’ve barely used shaders - but two minutes’ Googling leads me to the conclusion that you’re missing an assignment along the lines of gl_TexCoord[0] = gl_MultiTexCoord0; in the vertex shader and gl_FragColor = texture2D(sampler, gl_TexCoord[0].xy); in the fragment shader.

Take a look at these tutorials:


Take from the site:
vertex shader:

//combined projection and view matrix
uniform mat4 u_projView;

//"in" attributes from our SpriteBatch
attribute vec2 Position;
attribute vec2 TexCoord;
attribute vec4 Color;

//"out" varyings to our fragment shader
varying vec4 vColor;
varying vec2 vTexCoord;
 
void main() {
	vColor = Color;
	vTexCoord = TexCoord;
	gl_Position = u_projView * vec4(Position, 0.0, 1.0);
}

Fragment shader:

//SpriteBatch will use texture unit 0
uniform sampler2D u_texture;

//"in" varyings from our vertex shader
varying vec4 vColor;
varying vec2 vTexCoord;

void main() {
	//sample the texture
	vec4 texColor = texture2D(u_texture, vTexCoord);
	
	//invert the red, green and blue channels
	texColor.rgb = 1.0 - texColor.rgb;
	
	//final color
	gl_FragColor = vColor * texColor;
}

//In java

  1. Pass texture coordinates each vertrice
  2. Pass uniform texture

//In vertex shader
3. Pass texture coordinates to fragment shader

//In fragment shader
4. Sample texture in shader using Texture2D

Thats an odd class to put your main method in!

Hmm… No I guess not, you win :slight_smile: I just like keeping my main method in very generic classes like the Main class, even if its just a one class example project :stuck_out_tongue: I always have a seperate class just for the main method! Just one of my weird things I guess.