Skip to content
Snippets Groups Projects
Select Git revision
  • c6a065dcd256c450949c5a03c81737d1978667c3
  • master default
  • cgnsUnstructured
  • partitioning
  • poppler
  • HighOrderBLCurving
  • gmsh_3_0_4
  • gmsh_3_0_3
  • gmsh_3_0_2
  • gmsh_3_0_1
  • gmsh_3_0_0
  • gmsh_2_16_0
  • gmsh_2_15_0
  • gmsh_2_14_1
  • gmsh_2_14_0
  • gmsh_2_13_2
  • gmsh_2_13_1
  • gmsh_2_12_0
  • gmsh_2_11_0
  • gmsh_2_10_1
  • gmsh_2_10_0
  • gmsh_2_9_3
  • gmsh_2_9_2
  • gmsh_2_9_1
  • gmsh_2_9_0
  • gmsh_2_8_6
26 results

Timer.cpp

Blame
  • Forked from gmsh / gmsh
    Source project has a limited visibility.
    drawString.cpp 2.11 KiB
    #if !defined(BUILD_ANDROID)
    #define BUILD_IOS 1
    #endif
    
    #if defined(BUILD_IOS)
    #include <OpenGLES/ES1/gl.h>
    #include <OpenGLES/ES1/glext.h>
    #endif
    
    #if defined(BUILD_ANDROID)
    #include <GLES/gl.h>
    #include <GLES/glext.h>
    #endif
    
    #include "drawString.h"
    
    drawString::drawString(std::string text, int size, float color[4])
    {
    	_size = size;
    	if(color == NULL)
    		this->setColor(0.0f, 0.0f, 0.0f, 1.0f);
    	else
    		this->setColor(color);
    	this->setText(text);
    }
    
    void drawString::setText(std::string text)
    {
    	this->_text = text;
    	getBitmapFromString(this->_text.c_str(), _size, &this->_map, &this->_height, &this->_width, &this->_realWidth);
    }
    
    void drawString::setColor(float color[4])
    {
    	_color[0] = color[0];
    	_color[1] = color[1];
    	_color[2] = color[2];
    	_color[3] = color[3];
    }
    
    void drawString::setColor(float r, float g, float b, float a)
    {
    	_color[0] = r;
    	_color[1] = g;
    	_color[2] = b;
    	_color[3] = a;
    }
    void drawString::draw(float x, float y, float z, float w, float h, bool center)
    {
    	GLuint textureId;
    	glGenTextures(1, &textureId);
    	glBindTexture(GL_TEXTURE_2D, textureId);
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, _width, _height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, _map);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glColor4f(_color[0], _color[1], _color[2], _color[3]);
    	if(center)
    		x-=(float)_realWidth/w/2;
    	GLfloat vertex[] = {
    		 x, y, z, // bottom left
    		 x, y+(float)_height/h, z, // top left
    		 x+(float)_width/w, y, z, // bottom right
    		 x+(float)_width/w, y+(float)_height/h, z, // top right
    	};
    	GLfloat texture[] = {
    		0.0f, 1.0f, // top left
    		0.0f, 0.0f, // bottom left
    		1.0f, 1.0f, // top right
    		1.0f, 0.0f, // bottom right
    	};
    	glEnable(GL_TEXTURE_2D);
    	glEnable(GL_BLEND);
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    	glTexCoordPointer(2, GL_FLOAT, 0, texture);
    	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    	glVertexPointer(3, GL_FLOAT, 0, vertex);
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    	glDisableClientState(GL_VERTEX_ARRAY);
    	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    	glDisable(GL_BLEND);
    	glDisable(GL_TEXTURE_2D);
    	glDeleteTextures(1, &textureId);
    }