Esempio n. 1
0
void TTextField::Draw() const {
	const TColor& col = focus?colDYell:colWhite;
	FT.SetColor (col);
	DrawFrameX (mouseRect.left, mouseRect.top, mouseRect.width, mouseRect.height, 3, colMBackgr, col, 1.0);
	FT.AutoSizeN (5);
	FT.DrawString (mouseRect.left+20, mouseRect.top, text);

	if (cursor && focus) {
		int x = mouseRect.left + 20 + 1;
		//if (cursorPos != 0) {
			string temp = text.substr (0, text.length()/*cursorPos*/);
			x += FT.GetTextWidth (temp);
		//}
		int w = 3;
		int h = 26 * Winsys.scale;
		int scrheight = Winsys.resolution.height;

		glDisable (GL_TEXTURE_2D);
		glColor(colYellow);
		const GLshort vtx[] = {
			GLshort(x),     GLshort(scrheight - mouseRect.top - h - 9),
			GLshort(x + w), GLshort(scrheight - mouseRect.top - h - 9),
			GLshort(x + w), GLshort(scrheight - mouseRect.top - 9),
			GLshort(x),     GLshort(scrheight - mouseRect.top - 9)
		};
		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(2, GL_SHORT, 0, vtx);
		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
		glDisableClientState(GL_VERTEX_ARRAY);
		glEnable (GL_TEXTURE_2D);
	}
}
Esempio n. 2
0
static void init_elements(int n, int b)
{
    struct element
    {
        GLshort a;
        GLshort b;
        GLshort d;
        GLshort c;
    };
    
    const size_t s = n * n * sizeof (element);
    const int    d = n + 1;
    
    if (element *p = (element *) malloc(s))
    {
        element *e = p;
        
        // Compute the indices for each quad.
        
        for     (int r = 0; r < n; ++r)
            for (int c = 0; c < n; ++c, ++e)
            {
                e->a = GLshort(d * (r    ) + (c    ));
                e->b = GLshort(d * (r    ) + (c + 1));
                e->c = GLshort(d * (r + 1) + (c    ));
                e->d = GLshort(d * (r + 1) + (c + 1));
            }

        // Rewind the indices to reduce edge resolution as necessary.

        element *N = p;
        element *W = p + (n - 1);
        element *E = p;
        element *S = p + (n - 1) * n;

        for (int i = 0; i < n; ++i, N += 1, S += 1, E += n, W += n)
        {
            if (b & 1) { if (i & 1) N->a -= 1; else N->b -= 1; }
            if (b & 2) { if (i & 1) S->c += 1; else S->d += 1; }
            if (b & 4) { if (i & 1) E->a += d; else E->c += d; }
            if (b & 8) { if (i & 1) W->b -= d; else W->d -= d; }
        }
        
        // Upload the indices to the element buffer.
        
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, s, p, GL_STATIC_DRAW);
        free(p);
    }
}
Esempio n. 3
0
// Returns 0 for out-of-range sequence
GLshort Model3D::NumSeqFrames(GLshort SeqIndex)
{
  if (SeqFrmPointers.empty()) {
    return 0;
  }
  if ((SeqIndex < 0) || (SeqIndex >= GLshort(SeqFrmPointers.size()))) {
    return 0;
  }

  return (SeqFrmPointers[SeqIndex+1] - SeqFrmPointers[SeqIndex]);
}
Esempio n. 4
0
void TArrow::Draw() const {
	static const float textl[6] = { 0.5, 0.0, 0.5, 0.5, 0.0, 0.5 };
	static const float textr[6] = { 1.0, 0.5, 1.0, 1.0, 0.5, 1.0 };
	static const float texbl[6] = { 0.25, 0.25, 0.75, 0.00, 0.00, 0.50 };
	static const float texbr[6] = {0.50, 0.50, 1.00, 0.25, 0.25, 0.75};

	int type = 0;
	if (active)
		type = 1;
	if (focus)
		type++;
	if (down)
		type += 3;

	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable (GL_TEXTURE_2D);
	Tex.BindTex (LB_ARROWS);
	glColor4f (1.0, 1.0, 1.0, 1.0);

	const GLfloat tex[] = {
		textl[type], texbl[type],
		textr[type], texbl[type],
		textr[type], texbr[type],
		textl[type], texbr[type]
	};
	const GLshort vtx[] = {
		GLshort(position.x),      GLshort(Winsys.resolution.height - position.y - 48),
		GLshort(position.x + 48), GLshort(Winsys.resolution.height - position.y - 48),
		GLshort(position.x + 48), GLshort(Winsys.resolution.height - position.y),
		GLshort(position.x),      GLshort(Winsys.resolution.height - position.y)
	};
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glVertexPointer(2, GL_SHORT, 0, vtx);
	glTexCoordPointer(2, GL_FLOAT, 0, tex);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
}
Esempio n. 5
0
/*
*	\brief Constructor of the polyhedron class. Compute the vertex and indexes of the solid and prepare buffer data
*	\param[in] name a string containing the name of the polyhedron
*	\param[in] horizontal_divisions an unsigned containing the number of horizontal division of the polyhedron
*	\param[in] vertical_divisions an unsigned containing the number of vertical division of the polyhedron
*	\param[in] color a 3-vector containing the RGB values of the color of the polyhedron
*	\param[in] smooth_normal a boolean indicating if the normal should be smoothed of not
*	\return A well initialized polyhedron respecting the parameters
*/
Polyhedron::Polyhedron(std::string name, GLuint horizontal_divisions, GLuint vertical_divisions, glm::vec3 color, GLboolean smooth_normal) :
	Object()
{
	m_name = name;
	m_color = color;

	if (smooth_normal)
	{
		m_normal_computation_mode = SMOOTH;
	}
	else
	{
		m_normal_computation_mode = PER_TRIANGLE;
	}

	GLfloat horizontal_angle = 2.0f * PI / horizontal_divisions;
	GLfloat vertical_angle = PI / vertical_divisions;

	//Top triangles of the mesh
	for (GLuint i = 1; i < horizontal_divisions; i++)
	{
		m_indexes.push_back(0);
		m_indexes.push_back(i);
		m_indexes.push_back(i + 1);
	}
	m_indexes.push_back(0);
	m_indexes.push_back(horizontal_divisions);
	m_indexes.push_back(1);

	m_vertices.push_back(glm::vec3(0, 1.0f, 0));

	//All triangles except the first and last row (top and bottom)
	for (GLuint j = 1; j < vertical_divisions; j++)
	{
		for (GLuint i = 0; i < horizontal_divisions; i++)
		{
			m_vertices.push_back(glm::vec3(cos(i * horizontal_angle) * sin(j * vertical_angle),
				cos(j * vertical_angle), sin(i * horizontal_angle) * sin(j * vertical_angle)));

			if (j < vertical_divisions - 1)
			{
				m_indexes.push_back(1 + (horizontal_divisions + 1) * (j - 1) + i);
				m_indexes.push_back(1 + (horizontal_divisions + 1) * j + i);
				m_indexes.push_back(2 + (horizontal_divisions + 1) * (j - 1) + i);

				m_indexes.push_back(2 + (horizontal_divisions + 1) * (j - 1) + i);
				m_indexes.push_back(1 + (horizontal_divisions + 1) * j + i);
				m_indexes.push_back(2 + (horizontal_divisions + 1) * j + i);
			}
		}
		m_vertices.push_back(glm::vec3(sin(j * vertical_angle), cos(j * vertical_angle), 0));
	}

	//The last triangles at the bottom of the mesh
	m_vertices.push_back(glm::vec3(0, -1.0f, 0));
	for (GLuint i = 0; i < horizontal_divisions - 1; i++)
	{
		m_indexes.push_back(GLshort(m_vertices.size() - 1 - horizontal_divisions + i));
		m_indexes.push_back(GLshort(m_vertices.size() - 1));
		m_indexes.push_back(GLshort(m_vertices.size() - horizontal_divisions + i));
	}
	m_indexes.push_back(GLshort(m_vertices.size() - 2));
	m_indexes.push_back(GLshort(m_vertices.size() - 1));
	m_indexes.push_back(GLshort(m_vertices.size() - 1 - horizontal_divisions));

	glBindBuffer(GL_ARRAY_BUFFER, m_buffer_id[0]);
	glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * sizeof(glm::vec3), &m_vertices[0], GL_STATIC_DRAW);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer_id[5]);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indexes.size() * sizeof(GLushort), &m_indexes[0], GL_STATIC_DRAW);
}
Esempio n. 6
0
void DrawBonusExt (int y, size_t numraces, size_t num) {
	size_t maxtux = numraces * 3;
	if (num > maxtux) return;

	TVector2i bl, tr;

	//TColor col1 = {0.3, 0.5, 0.7, 1};
	TColor col2(0.45, 0.65, 0.85, 1);
	//TColor col3 = {0.6, 0.8, 1.0, 1};
	//TColor gold = {1, 1, 0, 1};

	int lleft[3];

	int framewidth = (int)numraces * 40 + 8;
	int totalwidth = framewidth * 3 + 8;
	int xleft = (Winsys.resolution.width - totalwidth) / 2;
	lleft[0] = xleft;
	lleft[1] = xleft + framewidth + 4;
	lleft[2] = xleft + framewidth + framewidth + 8;

	DrawFrameX (lleft[0], y, framewidth, 40, 1, col2, colBlack, 1);
	DrawFrameX (lleft[1], y, framewidth, 40, 1, col2, colBlack, 1);
	DrawFrameX (lleft[2], y, framewidth, 40, 1, col2, colBlack, 1);
	if (param.use_papercut_font > 0) FT.SetSize (20);
	else FT.SetSize (15);
	bl.y = Winsys.resolution.height - y - 32 -4;
	tr.y = Winsys.resolution.height - y - 0 -4;

	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable (GL_TEXTURE_2D);
	Tex.BindTex (TUXBONUS);
	glColor4f (1.0, 1.0, 1.0, 1.0);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	for (size_t i=0; i<maxtux; i++) {
		size_t majr = (i/numraces);
		size_t minr = i - majr * numraces;
		if (majr > 2) majr = 2;
		bl.x = lleft[majr] + (int)minr * 40 + 6;
		tr.x = bl.x + 32;

		// with tux outlines:
		// if (i<num) bott = 0.5; else bott = 0.0;
		// top = bott + 0.5;
		if (i<num) {
			float bott = 0.5;
			float top = 1.0;

			const GLfloat tex[] = {
				0, bott,
				1, bott,
				1, top,
				0, top
			};
			const GLshort vtx[] = {
				GLshort(bl.x), GLshort(bl.y),
				GLshort(tr.x), GLshort(bl.y),
				GLshort(tr.x), GLshort(tr.y),
				GLshort(bl.x), GLshort(tr.y)
			};
			glVertexPointer(2, GL_SHORT, 0, vtx);
			glTexCoordPointer(2, GL_FLOAT, 0, tex);
			glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
		}
	}
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
}
Esempio n. 7
0
void DrawFrameX (int x, int y, int w, int h, int line, const TColor& backcol, const TColor& framecol, ETR_DOUBLE transp) {
	float yy = Winsys.resolution.height - y - h;
	if (x < 0) x = (Winsys.resolution.width -w) / 2;

	glPushMatrix();
	glDisable(GL_TEXTURE_2D);
	glEnableClientState(GL_VERTEX_ARRAY);

	glColor(framecol, transp);
	glTranslatef(x, yy, 0);
	const GLshort frame [] = {
		0, 0,
		GLshort(w), 0,
		GLshort(w), GLshort(h),
		0, GLshort(h)
	};
	glVertexPointer(2, GL_SHORT, 0, frame);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

	glColor(backcol, transp);
	const GLshort back [] = {
		GLshort(0 + line), GLshort(0 + line),
		GLshort(w - line), GLshort(0 + line),
		GLshort(w - line), GLshort(h - line),
		GLshort(0 + line), GLshort(h - line)
	};
	glVertexPointer(2, GL_SHORT, 0, back);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

	glDisableClientState(GL_VERTEX_ARRAY);
	glEnable (GL_TEXTURE_2D);
	glPopMatrix();
}