Getting a gray window when using shaders

I’ve been coding a shaders program thats supposed to display a magenta window, but instead, it is gray.
There’s is no compile, linker or any type of error, everything works just “fine” but even thought i set rgb to it’s correspondent values, i can’t seem to make it work.
Here is the main code:


void Sprite::init(...) {
if (_vboID == 0) {
		glGenBuffers(1, &_vboID);
	Vertex vertexData[6];

	vertexData[0].position.x = _x;
	... //set the vertex positions

	for (int i = 0; i << 6; i++) {
		vertexData[i].color.r = 255;
		vertexData[i].color.g = 0;
		vertexData[i].color.b = 255;
		vertexData[i].color.a = 255;
	} //set the vertex color

	glBindBuffer(GL_ARRAY_BUFFER, _vboID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, 0);

void Sprite::draw() {
	glBindBuffer(GL_ARRAY_BUFFER, _vboID);


	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
	glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex, color)); //assign vertex attributes

	glDrawArrays(GL_TRIANGLES, 0, 6); //draw the triangles (2, to fill the entire window)


	glBindBuffer(GL_ARRAY_BUFFER, 0);


void linkShaders() {
... //link shaders, i'm pretty sure there are no errors here as the code worked perfectly before using shaders

void compileShaders() {
... //compile shaders, i'm pretty sure there are no errors here as the code worked perfectly before using shaders

void GLSL_Program::use() {
	for (unsigned int i = 0; i < _numAttributes; i++) {

void GLSL_Program::unuse() {
	for (unsigned int i = 0; i < _numAttributes; i++) {

void GLSL_Program::addAttribute(const std::string& attributeName) {
	glBindAttribLocation(_programID, _numAttributes++, attributeName.c_str()); //add attribute


void MainGame::initShaders() {
	_colorProgram.compileShaders("Shaders/colorShading.vert", "Shaders/colorShading.frag");

void MainGame::drawGame() {




	SDL_GL_SwapWindow(_window); //swap windows

Finally, these are my shader files:

#version 130

in vec4 fragmentColor;

out vec4 color;

void main() {
	color = fragmentColor;


#version 130

in vec2 vertexPosition;
in vec4 vertexColor;

out vec4 fragmentColor;

void main() {
	gl_Position.xy = vertexPosition;
	gl_Position.z = 0.0;
	gl_Position.w = 1.0;
	fragmentColor = vertexColor;

In case any more code is needed just tell me, i tryied to summarize the important parts the most i could, sorry if it is too long, it’s just that i’m not sure where’s the code error.

The only thing which stands out from the fragments you’ve posted is:

If GLSL_Program::use() is being called before rendering and it works correctly, then the glEnableVertexAttribArray() call in Sprite::draw() is redundant. If GLSL_Program::use() isn’t being called or it doesn’t work correctly, then you’re only enabling the attribute array for the positions and not that for the colours.

But GLSL_Program::use ITS being called before rendering, and even if i remove glEnableVertexAttribArray() the error is still happening

In which case, the problem lies elsewhere.

I also just noticed this:

I’m assuming that the “<<” is a typo; I’d expect the program to crash if that’s the actual code.

Ye just a typo, but already find the solution, so don’t worry about it anymore