Problem of colors when drawing lines

Hi,

I have written a drawLine method, but no matter what color I specify, my lines are always black.


void Game::drawLine(CGPoint origin, CGPoint dest, CGFloat width)
{
	glLineWidth(width);
	GLfloat	vertices[] = {origin.x, origin.y, dest.x, dest.y};
	GLfloat colors[] = {
		0.0f, 1.0f, 0.0f, 1.0f,
		0.0f, 1.0f, 0.0f, 1.0f
	};

	glVertexPointer(2, GL_FLOAT, 0, vertices);
	glColorPointer(4, GL_FLOAT, 0, colors);

	glEnableClientState(GL_COLOR_ARRAY);
	glShadeModel(GL_FLAT);

	glDrawArrays(GL_LINES, 0, 2);
	
	glDisableClientState(GL_COLOR_ARRAY);
}

What did I miss ?

Thanks !

some suggestions to try…

// not sure if this was already enabled
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

// specify the stride
glVertexPointer(2, GL_FLOAT, 2sizeof(float), vertices);
glColorPointer(4, GL_FLOAT, 4
sizeof(float), colors);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

Make sure that lighting and texturing is disabled when you draw the lines.

That’s it, texturing was not disabled.

Thanks a lot !

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.