Ejemplo n.º 1
0
/*
================
R_DrawChar
Draws one variable sized graphics character with 0 being transparent.
It can be clipped to the top of the screen to allow the console to be
smoothly scrolled off.
================
*/
void R_DrawChar (float x, float y, int32_t num, float scale, 
	 int32_t red, int32_t green, int32_t blue, int32_t alpha, qboolean italic, qboolean last)
{
	int32_t			row, col, i;
	float		frow, fcol, size, cscale, italicAdd;
	vec2_t		texCoord[4], verts[4];
	qboolean	addChar = true;

	num &= 255;

	if (alpha > 255)
		alpha = 255;
	else if (alpha < 1)
		alpha = 1;

	if ((num & 127) == 32)	// space
		addChar = false;
	if (y <= -(scale * DEFAULT_FONT_SIZE))	// totally off screen
		addChar = false;

	row = num >> 4;
	col = num&15;

	frow = row*0.0625;
	fcol = col*0.0625;
	size = 0.0625;
	cscale = scale * DEFAULT_FONT_SIZE;

	italicAdd = (italic) ? (cscale*0.25) : 0;

	if (addChar)
	{
		Vector2Set(texCoord[0], fcol, frow);
		Vector2Set(texCoord[1], fcol + size, frow);
		Vector2Set(texCoord[2], fcol + size, frow + size);
		Vector2Set(texCoord[3], fcol, frow + size);

		Vector2Set(verts[0], x+italicAdd, y);
		Vector2Set(verts[1], x+cscale+italicAdd, y);
		Vector2Set(verts[2], x+cscale-italicAdd, y+cscale);
		Vector2Set(verts[3], x-italicAdd, y+cscale);

		if (char_count == 0)
			rb_vertex = rb_index = 0;
		if (rb_vertex + 4 >= MAX_VERTICES || rb_index + 6 >= MAX_INDICES)
			R_FlushChars ();
		indexArray[rb_index++] = rb_vertex+0;
		indexArray[rb_index++] = rb_vertex+1;
		indexArray[rb_index++] = rb_vertex+2;
		indexArray[rb_index++] = rb_vertex+0;
		indexArray[rb_index++] = rb_vertex+2;
		indexArray[rb_index++] = rb_vertex+3;
		for (i=0; i<4; i++) {
			VA_SetElem2(texCoordArray[0][rb_vertex], texCoord[i][0], texCoord[i][1]);
			VA_SetElem3(vertexArray[rb_vertex], verts[i][0], verts[i][1], 0);
			VA_SetElem4(colorArray[rb_vertex], red*DIV255, green*DIV255, blue*DIV255, alpha*DIV255);
			rb_vertex++;
		}
		char_count++;
	}
	if (last)
		R_FlushChars ();
}
Ejemplo n.º 2
0
/*
================
R_DrawChar
Draws one variable sized graphics character with 0 being transparent.
It can be clipped to the top of the screen to allow the console to be
smoothly scrolled off.
================
*/
void R_DrawChar (float x, float y, int32_t num, float scale,
                 int32_t red, int32_t green, int32_t blue, int32_t alpha, qboolean italic, qboolean last)
{
    int32_t			row, col;
    float		frow, fcol, size, cscale, italicAdd;
    qboolean	addChar = true;

    const vec_t r = min(red, 255)*DIV255;
    const vec_t g = min(green, 255)*DIV255;
    const vec_t b = min(blue, 255)*DIV255;
    const vec_t a = max(min(alpha, 255), 1)*DIV255;


    const vec4_t color[4] = {
        {r,g,b,a},
        {r,g,b,a},
        {r,g,b,a},
        {r,g,b,a}
    };

    num &= 255;

    if ((num & 127) == 32)	// space
        addChar = false;
    if (y <= -(scale * DEFAULT_FONT_SIZE))	// totally off screen
        addChar = false;

    row = num >> 4;
    col = num&15;

    frow = row*0.0625;
    fcol = col*0.0625;
    size = 0.0625;
    cscale = scale * DEFAULT_FONT_SIZE;

    italicAdd = (italic) ? (cscale*0.25) : 0;

    if (addChar)
    {
        if (char_count == 0)
            rb_vertex = rb_index = 0;
        if (rb_vertex + 4 >= MAX_VERTICES || rb_index + 6 >= MAX_INDICES)
            R_FlushChars ();
        indexArray[rb_index] = rb_vertex+0;
        indexArray[rb_index+1] = rb_vertex+1;
        indexArray[rb_index+2] = rb_vertex+2;
        indexArray[rb_index+3] = rb_vertex+0;
        indexArray[rb_index+4] = rb_vertex+2;
        indexArray[rb_index+5] = rb_vertex+3;

        rb_index += 6;

        VA_SetElem2(texCoordArray[0][rb_vertex], fcol, frow);
        VA_SetElem2(texCoordArray[0][rb_vertex+1], fcol + size, frow);
        VA_SetElem2(texCoordArray[0][rb_vertex+2], fcol + size, frow + size);
        VA_SetElem2(texCoordArray[0][rb_vertex+3], fcol, frow + size);

        VA_SetElem3(vertexArray[rb_vertex], x+italicAdd, y, 0);
        VA_SetElem3(vertexArray[rb_vertex+1], x+cscale+italicAdd, y, 0);
        VA_SetElem3(vertexArray[rb_vertex+2], x+cscale-italicAdd, y+cscale, 0);
        VA_SetElem3(vertexArray[rb_vertex+3], x-italicAdd, y+cscale, 0);

        memcpy(colorArray[rb_vertex], color, sizeof(vec4_t) * 4);

        rb_vertex += 4;
        char_count++;
    }
    if (last)
        R_FlushChars ();
}