Fragment shader failed to compile wi the following errors :


First of all I have to inform you that I’m a total beginner in OpenGL I don’t even know what a shader really is.

I’m currently following a tutorial and I get the following errors:

error<#202> No matching overloaded function found: texture
error<#160> Cannot convert from: “const float” to: “out highp 4-component vector of vec4”


with this code :

void	SceneOpenGL::principalLoop()
	float			vertices[] = { -2.0, -2.0, -2.0,  -2.0, 2.0, -2.0,  2.0, 2.0, -2.0,
									-2.0, -2.0, -2.0,  2.0, -2.0, -2.0,  2.0, 2.0, -2.0 };
	float			textureCoord[] = {0.0, 0.0,  0.0, 1.0,  1.0, 1.0,
									0.0, 0.0,  1.0, 0.0,  1.0, 1.0};
	unsigned int	frameRate(1000 / 50);
	Uint32			debutBoucle(0), finBoucle(0), tempsEcoule(0);

	// Matrices
	mat4	projection;
	mat4	modelview;

	projection = perspective(70.0, (double)m_width / m_height, 1.0, 100.0);
	modelview = mat4(1.0);

	// Textures

	Texture	texture("../../Textures/photorealistic_crate/crate21.jpg");
	// Shader

	Shader	shaderTexture("Shaders/texture.vert", "Shaders/texture.frag");

	// Boucle principale
	while (!m_input.terminer())
			debutBoucle = SDL_GetTicks();

			// Gestion des évènements
			// Nettoyage de l'écran

			modelview = lookAt(vec3(0, 0, 2), vec3(0, 0, 0), vec3(0, 1, 0));


			glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);

			glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, textureCoord);

			glUniformMatrix4fv(glGetUniformLocation(shaderTexture.getProgramID(), "projection"), 1, GL_FALSE, value_ptr(projection));
			glUniformMatrix4fv(glGetUniformLocation(shaderTexture.getProgramID(), "modelview"), 1, GL_FALSE, value_ptr(modelview));

			glBindTexture(GL_TEXTURE_2D, texture.getID());

			glDrawArrays(GL_TRIANGLES, 0, 6);

			glBindTexture(GL_TEXTURE_2D, 0);



			// Actualisation de la fenêtre
			finBoucle = SDL_GetTicks();
			tempsEcoule = finBoucle - debutBoucle;
			if (tempsEcoule < frameRate)
				SDL_Delay(frameRate - tempsEcoule);

Doing some “cout” debugging the problem seems to come from the line “shaderTexture.charger();” so it comes from the shaders files, however, I tried this code on another computer and it worked.

What should I do?

Probably the code worked on a computer with nVidia card while the errors you got on ATI card, right?
It seems like the shader does not declare the GLSL version it is written against, because the ‘texture’ function was not available in the first GLSL versions which is the default. Post the shader’s code here, let’s see.
Applying the telepathy skills, may I assume you need to place a line like:
#version 330
into fragment and vertex shaders.


first thanks a lot for your answer.

Yes indeed I have an ATI card.

this is the code from texture.frag :

// Version du GLSL

#version 150 core

// Entrée

in vec2 coordTexture;

// Uniform

uniform sampler2D texture;

// Sortie 

out vec4 out_Color;

// Fonction main

void main()
    // Couleur du pixel

    out_Color = texture(texture, coordTexture);

and texture.vert :

// Version du GLSL

#version 150 core

// Entrées

in vec3 in_Vertex;
in vec2 in_TexCoord0;

// Uniform

uniform mat4 projection;
uniform mat4 modelview;

// Sortie

out vec2 coordTexture;

// Fonction main

void main()
    // Position finale du vertex en 3D

    gl_Position = projection * modelview * vec4(in_Vertex, 1.0);

    // Envoi des coordonnées de texture au Fragment Shader

    coordTexture = in_TexCoord0;

I tried to change “#version 150 core” to “#version 330 core” but same result

Name collision probably. Give a different name to your texture handle ( uniform sampler2D my_texture; ). If it will not help, use the texture2D(…) function instead of texture(…).

BTW, just a small tip: for the transformation of this kind use parenthesis to avoid matrix-by-matrix multiplication:
gl_Position = projection * ( modelview * vec4(in_Vertex, 1.0) );

And another small tip about the input attributes. Even if you supply vertices as 3 component items (the way they are in your array buffer), in the shader you can declare them as vec4 and the forth component will be 1.0. In general, any non-existing component will be substituted by OpenGL with 0 except the forth one (it will be 1) for any input attribute. That makes life a bit easier. :slight_smile:

Thanks man. It worked changing the name of the texture.

PS : Do I have to mark the topic as resolved or somethin like that?