Esempio n. 1
0
	hsl_colour hsl_colour::from_rgb(const colour& aColour)
	{
		double hue, saturation, lightness;
		double r = aColour.red() / 255.0, g = aColour.green() / 255.0, b = aColour.blue() / 255.0;
		double M = std::max(std::max(r, g), b);
		double m = std::min(std::min(r, g), b);
		double c = M - m;
		double h2;
		if (c == 0.0)
			h2 = undefined_hue();
		else if (M == r)
			h2 = std::fmod((g - b) / c, 6.0);
		else if (M == g)
			h2 = (b - r) / c + 2.0;
		else if (M == b)
			h2 = (r - g) / c + 4.0;
		else
			h2 = undefined_hue();
		if (h2 != undefined_hue())
		{
			hue = 60.0 * h2;
			if (hue < 0.0)
				hue += 360.0;
		}
		else
			hue = undefined_hue();
		lightness = 0.5f * (M + m);
		lightness = std::max(std::min(lightness, 1.0), 0.0);
		if (c == 0.0)
			saturation = 0.0;
		else
			saturation = c / (1.0 - std::abs(2.0 * lightness - 1.0));
		saturation = std::max(std::min(saturation, 1.0), 0.0);
		return hsl_colour(hue, saturation, lightness);
	}
Esempio n. 2
0
	hsv_colour hsv_colour::from_rgb(const colour& aColour)
	{
		double hue, saturation, value;
		double r = aColour.red() / 255.0, g = aColour.green() / 255.0, b = aColour.blue() / 255.0;
		double M = std::max(std::max(r, g), b);
		double m = std::min(std::min(r, g), b);
		double c = M - m;
		double h2;
		if (c == 0.0)
			h2 = undefined_hue();
		else if (M == r)
			h2 = std::fmod((g - b) / c, 6.0);
		else if (M == g)
			h2 = (b - r) / c + 2.0;
		else if (M == b)
			h2 = (r - g) / c + 4.0;
		else
			h2 = undefined_hue();
		if (h2 != undefined_hue())
		{
			hue = 60.0 * h2;
			if (hue < 0.0)
				hue += 360.0;
		}
		else
			hue = undefined_hue();
		value = M;
		value = std::max(std::min(value, 1.0), 0.0);
		if (c == 0.0)
			saturation = 0.0;
		else
			saturation = c / value;
		saturation = std::max(std::min(saturation, 1.0), 0.0);
		return hsv_colour(hue, saturation, value, aColour.alpha() / 255.0);
	}
Esempio n. 3
0
static void SetColour ( const colour& col )
{
	if (sizeof(col) == sizeof(float) * 4)
	{
		glColor4fv((const GLfloat*)&col);
	}
	else
	{
		glColor4f(col.red(), col.green(), col.blue(), col.alpha());
	}
}
Esempio n. 4
0
void DrawPoint ( vec2 coord, float width, colour col )
{
	SetShader("Primitive");
	DisableTexturing();
	if (col.alpha() < 1.0f)
	{
		EnableBlending();
	}
	else
	{
		DisableBlending();
	}
	SetColour(col);
	Matrices::SetViewMatrix(matrix2x3::Identity());
	Matrices::SetModelMatrix(matrix2x3::Identity());
	float quad[8] = { coord.X(), coord.Y(),
		coord.X(), coord.Y() - 2,
		coord.X() + 2, coord.Y() - 2,
		coord.X() + 2, coord.Y() };
	glVertexPointer ( 2, GL_FLOAT, 0, quad );
	glDrawArrays ( GL_QUADS, 0, 4 );
	/* ¡WARNING! IMMEDIATE MODE! ENTER AT YOUR OWN RISK */
//	glBegin(GL_POINTS);
//		glVertex2f(coord.X(), coord.Y());
//	glEnd();
}
Esempio n. 5
0
String PropertyHelper::colourToString(const colour& val)
{
	using namespace std;

	char buff[16];
	sprintf(buff, "%.8X", val.getARGB());

	return String(buff);
}
Esempio n. 6
0
void DrawLightning ( vec2 coordinate1, vec2 coordinate2, float width, float chaos, colour col, bool tailed )
{
	uint32_t newLastSeed = lightningRNG.GetState();
	RealDrawLightning(coordinate1, coordinate2, width, chaos, col, tailed, lightningRNG);
	RNG localRNG(lastSeed);
	lastSeed = newLastSeed;
	col.alpha() *= 0.5f;
	RealDrawLightning(coordinate1, coordinate2, width * 3.0f, chaos, col, tailed, localRNG);
}
Esempio n. 7
0
static void RealDrawLightning ( vec2 coordinate1, vec2 coordinate2, float width, float chaos, colour col, bool tailed, RNG& rng )
{
	if (col.alpha() < 0.2f)
		return;
	SetShader("Primitive");
	DisableTexturing();
	if (col.alpha() < 1.0f)
	{
		EnableBlending();
	}
	else
	{
		DisableBlending();
	}
	glLineWidth(width);
	Matrices::SetViewMatrix(matrix2x3::Identity());
	Matrices::SetModelMatrix(matrix2x3::Identity());
	SetColour(col);
	unsigned long segments = 12;
	float offsetting = chaos;
	float* vertices = (float*)alloca(sizeof(float) * 2 * segments);
	vec2 tangent = (coordinate2 - coordinate1).UnitVector();
	vec2 normal = vec2(-tangent.Y(), tangent.X());
	normal.X() = -normal.Y();
	for (unsigned long i = 0; i < segments; i++)
	{
		float delta = ((float)i / (float)(segments - 1));
		//This may be only a partial fix.	
		vec2 basePosition = ((coordinate1*(1.0f-delta)) + (coordinate2*delta));// / 2.0f;
		if (tailed)
		{
			delta *= 2.0f;
			if (delta > 1.0f) delta = 2.0f - delta;
		}
		float maxOffset = offsetting * delta;
		float actualOffset = RandomFloat(-maxOffset, maxOffset);
		basePosition += normal * actualOffset;
		vertices[(i*2)+0] = basePosition.X();
		vertices[(i*2)+1] = basePosition.Y();
	}
	glVertexPointer(2, GL_FLOAT, 0, vertices);
	glDrawArrays(GL_LINE_STRIP, 0, segments);
}
Esempio n. 8
0
/*************************************************************************
	convert colour value to whatever the OpenGL system is expecting.
*************************************************************************/
long OpenGLRenderer::colourToOGL(const colour& col) const
{
	ulong cval;
#ifdef __BIG_ENDIAN__
    cval =  (static_cast<ulong>(255 * col.getAlpha()));
    cval |= (static_cast<ulong>(255 * col.getBlue())) << 8;
    cval |= (static_cast<ulong>(255 * col.getGreen())) << 16;
    cval |= (static_cast<ulong>(255 * col.getRed())) << 24;
#else
	cval =	(static_cast<ulong>(255 * col.getAlpha())) << 24;
	cval |=	(static_cast<ulong>(255 * col.getBlue())) << 16;
	cval |=	(static_cast<ulong>(255 * col.getGreen())) << 8;
	cval |= (static_cast<ulong>(255 * col.getRed()));
#endif
	return cval;
}
Esempio n. 9
0
void DrawCircle ( vec2 centre, float radius, float width, colour col )
{
	SetShader("Primitive");
	DisableTexturing();
	if (col.alpha() < 1.0f)
	{
		EnableBlending();
	}
	else
	{
		DisableBlending();
	}
	glLineWidth(width);
	Matrices::SetViewMatrix(matrix2x3::Translate(centre));
	Matrices::SetModelMatrix(matrix2x3::Scale(radius));
	SetColour ( col );
	glVertexPointer(2, GL_FLOAT, 0, circlePoints);
	glDrawArrays(GL_LINE_LOOP, 0, sizeof(circlePoints) / (2 * sizeof(float)));
}
Esempio n. 10
0
void DrawTriangle ( const vec2 point1, const vec2 point2, const vec2 point3, colour col )
{
	SetShader("Primitive");
	DisableTexturing();
	if (col.alpha() < 1.0f)
	{
		EnableBlending();
	}
	else
	{
		DisableBlending();
	}
	SetColour(col);
	Matrices::SetViewMatrix(matrix2x3::Identity());
	Matrices::SetModelMatrix(matrix2x3::Identity());
	float real_triangle[6] = { point1.X(), point1.Y(),
								point2.X(), point2.Y(),
								point3.X(), point3.Y() };
	glVertexPointer(2, GL_FLOAT, 0, real_triangle);
	glDrawArrays(GL_POLYGON, 0, 3);
} 
Esempio n. 11
0
void DrawLine ( vec2 coordinate1, vec2 coordinate2, float width, colour col )
{
	SetShader("Primitive");
	DisableTexturing();
	if (col.alpha() < 1.0f)
	{
		EnableBlending();
	}
	else
	{
		DisableBlending();
	}
	glLineWidth(width);
	Matrices::SetViewMatrix(matrix2x3::Identity());
	Matrices::SetModelMatrix(matrix2x3::Identity());
	SetColour(col);
	float vertices[4] = { coordinate1.X(), coordinate1.Y(),
						coordinate2.X(), coordinate2.Y() };
	glVertexPointer ( 2, GL_FLOAT, 0, vertices );
	glDrawArrays ( GL_LINES, 0, 2 );
}
Esempio n. 12
0
void DrawDiamond ( float top, float left, float bottom, float right, colour col )
{
	SetShader("Primitive");
	DisableTexturing();
	if (col.alpha() < 1.0f)
	{
		EnableBlending();
	}
	else
	{
		DisableBlending();
	}
	SetColour(col);
	Matrices::SetViewMatrix(matrix2x3::Identity());
	Matrices::SetModelMatrix(matrix2x3::Identity());
	float diamond[8] = { (right + left) / 2, top,
						left, (top + bottom) / 2,
						(right + left) / 2, bottom,
						right, (top + bottom) / 2 };
	glVertexPointer(2, GL_FLOAT, 0, diamond);
	glDrawArrays(GL_QUADS, 0, 4);
} 
Esempio n. 13
0
void DrawBox ( float top, float left, float bottom, float right, float width, colour col )
{
	SetShader("Primitive");
	DisableTexturing();
	if (col.alpha() < 1.0f)
	{
		EnableBlending();
	}
	else
	{
		DisableBlending();
	}
	Matrices::SetViewMatrix(matrix2x3::Identity());
	Matrices::SetModelMatrix(matrix2x3::Identity());
	SetColour(col);
	float quad[8] = { left, top,
					left, bottom,
					right, bottom,
					right, top };
	glVertexPointer ( 2, GL_FLOAT, 0, quad );
	glDrawArrays ( GL_QUADS, 0, 4 );
	if (width != 0)
	{
		SetColour(col + colour(0.45, 0.45, 0.45, 0.0));
		glLineWidth(width);
		float vertices[16] = { left, top,
							right, top,
							left, top,
							left, bottom,
							right, top,
							right, bottom,
							left, bottom,
							right, bottom };
		glVertexPointer ( 2, GL_FLOAT, 0, vertices );
		glDrawArrays ( GL_LINES, 0, 8 );
	}
}