Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glsl arithmetic operator

Tags:

opengl

glsl

Why does this line:

float x = 1 - gl_Color.x;

give:

(26): error: Could not implicitly convert operands to arithmetic operator
like image 705
Charles Avatar asked Jan 18 '11 17:01

Charles


People also ask

What is vec2 in OpenGL?

GLM's vec2 is a utility class representing 2D vector, there are also vec3 , vec4 classes available for 3D and 4D respectively. GLM is also offering matrix classes following same naming conditions mat2 , mat3 , mat4 . You can multiply a matrix with a matrix or a matrix with a vector using overloaded * operator.

What is vec4 OpenGL?

vec4 is a floating point vector with four components. It can be initialized by: Providing a scalar value for each component. Providing one scalar value. This value is used for all components.

What is GLSL attribute?

Attributes are GLSL variables which are only available to the vertex shader (as variables) and the JavaScript code. Attributes are typically used to store color information, texture coordinates, and any other data calculated or retrieved that needs to be shared between the JavaScript code and the vertex shader.

What is gl_FragColor?

gl_FragColor is the principal variable that your fragment shader is designed to change. If your code does not assign a value to it then it is left undefined for the rest of the pipeline. gl_FragData is an array of data that can be used by the rest of the pipeline.


1 Answers

GLSL (prior to #version 120) does not allow implicit conversions between integer and floating point. 1 is an integer and gl_Color.x is a float, so you get an error. You need

float x = 1.0 - gl_Color.x;

instead

like image 123
Chris Dodd Avatar answered Oct 04 '22 20:10

Chris Dodd