Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL Shaders Attributes as ints

Tags:

opengl

glsl

I'm just learning OpenGL and I'm running into some issues. I'm using OpenGL 3.0 and GLSL 1.2.

I have an array of matrices which I would like to selectively apply to different vertices. Instead of copying a matrix each time I want to indicate an index, I would instead like to pass in an integer as an index and use that integer to select the matrix I want. However, when I try to compile my shader I get the following error:

ERROR: 0:5: 'attribute' : cannot be bool or int

I'd appreciate it if anybody could point me in the right direction.

like image 479
LandonSchropp Avatar asked Sep 23 '10 07:09

LandonSchropp


People also ask

Is gl_FragColor deprecated?

Yes, gl_FragColor is deprecated. You should use the following syntax: layout(location = 0) out vec4 diffuseColor; It is included in the GLSL 4.60 spec under the section 7.1.

How does GLSL shaders work?

GLSL is executed directly by the graphics pipeline. There are several kinds of shaders, but two are commonly used to create graphics on the web: Vertex Shaders and Fragment (Pixel) Shaders. Vertex Shaders transform shape positions into 3D drawing coordinates.

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 vec3 in GLSL?

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


1 Answers

Attributes can be ints, but you need to enable a newer version of GLSL to use it. Try adding this to the top of your shader:

#version 130

Version 130 corresponds to OpenGL 3.0

like image 113
Dr. Snoopy Avatar answered Sep 24 '22 16:09

Dr. Snoopy