Exemplo n.º 1
0
// ----------------------------------------------------------------------------
void
text_buffer_delete( text_buffer_t * self )
{
    vector_delete( self->lines );
    font_manager_delete( self->manager );
    vertex_buffer_delete( self->buffer );
    glDeleteProgram( self->shader );
    free( self );
}
Exemplo n.º 2
0
FontRenderer::~FontRenderer()
{
    if (m_pManager) {
        font_manager_delete(m_pManager);
    }
    
    if (m_pTextBuffer) {
        vertex_buffer_delete(m_pTextBuffer);
    }
}
Exemplo n.º 3
0
void CFont::Free()
{
	if (nullptr != font_manager)
	{
		glDeleteTextures(1, &font_manager->atlas->id);
		font_manager->atlas->id = 0;
		font_manager_delete(font_manager);
		font_manager = nullptr;
	}
	if (nullptr != buffer)
	{
		text_buffer_delete(buffer);
		buffer = nullptr;
	}
	if (text_shader > 0)
	{
		glDeleteProgram(text_shader);
		text_shader = 0;
	}
}
Exemplo n.º 4
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    GLFWwindow* window;
    char* screenshot_path = NULL;

    if (argc > 1)
    {
        if (argc == 3 && 0 == strcmp( "--screenshot", argv[1] ))
            screenshot_path = argv[2];
        else
        {
            fprintf( stderr, "Unknown or incomplete parameters given\n" );
            exit( EXIT_FAILURE );
        }
    }

    glfwSetErrorCallback( error_callback );

    if (!glfwInit( ))
    {
        exit( EXIT_FAILURE );
    }

    glfwWindowHint( GLFW_VISIBLE, GL_FALSE );
    glfwWindowHint( GLFW_RESIZABLE, GL_FALSE );

    window = glfwCreateWindow( 800, 600, argv[0], NULL, NULL );

    if (!window)
    {
        glfwTerminate( );
        exit( EXIT_FAILURE );
    }

    glfwMakeContextCurrent( window );
    glfwSwapInterval( 1 );

    TwInit( TW_OPENGL, NULL );

    glfwSetFramebufferSizeCallback( window, reshape );
    glfwSetWindowRefreshCallback( window, display );
    glfwSetCursorPosCallback( window, cursor_pos );
    glfwSetMouseButtonCallback( window, mouse_button );
    glfwSetKeyCallback( window, keyboard );

#ifndef __APPLE__
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
        exit( EXIT_FAILURE );
    }
    fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
#endif

    init( window );

    glfwShowWindow( window );
    reshape( window, 800, 600 );

    while(!glfwWindowShouldClose( window ))
    {
        display( window );
        glfwPollEvents( );

        if (screenshot_path)
        {
            screenshot( window, screenshot_path );
            glfwSetWindowShouldClose( window, 1 );
        }
    }

    TwTerminate();

    glDeleteProgram( text_shader );
    glDeleteTextures( 1, &font_manager_a->atlas->id );
    glDeleteTextures( 1, &font_manager_rgb->atlas->id );
    font_manager_a->atlas->id = 0;
    font_manager_rgb->atlas->id = 0;
    font_manager_delete( font_manager_rgb );
    font_manager_delete( font_manager_a );
    text_buffer_delete( text_buffer );

    glfwDestroyWindow( window );
    glfwTerminate( );

    return EXIT_SUCCESS;
}
Exemplo n.º 5
0
void CFont::TextAdd(float x, float y, float _size, float rectw, float recth, const char *text, const unsigned length)
{
	bool hasSizeChange = abs(_size - normal.size) > 0.01f;
	bool hasTextChange = (0 == lasttext.size() || 0 != strcmp(text, lasttext.c_str()));

	if (hasSizeChange || hasTextChange || nullptr == font_manager)
	{
		// DONE: rebuild a font texture and atlas

		if (nullptr != font_manager)
		{
			glDeleteTextures(1, &font_manager->atlas->id);
			font_manager->atlas->id = 0;
			font_manager_delete(font_manager);
			font_manager = nullptr;
		}

		normal.size = _size;

		font_manager = font_manager_new(ATLAS_SIZE, ATLAS_SIZE, LCD_FILTERING_ON);
		normal.font = font_manager_get_from_markup(font_manager, &normal);
		normal.font->kerning = 0;
		
		text_buffer_clear(buffer);

		vec2 pen = { { 0, 0 } };
		text_buffer_add_text(buffer, &pen, &normal, text, length);
		//text_buffer_align(buffer, &pen, ALIGN_CENTER);
		glGenTextures(1, &font_manager->atlas->id);
		glBindTexture(GL_TEXTURE_2D, font_manager->atlas->id);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, font_manager->atlas->width,
			font_manager->atlas->height, 0, GL_RGB, GL_UNSIGNED_BYTE,
			font_manager->atlas->data);

		vec4 bounds = text_buffer_get_bounds(buffer, &pen);

		mBounds[0] = bounds.x;
		mBounds[1] = bounds.y;
		mBounds[2] = bounds.z;
		mBounds[3] = bounds.w;

		lasttext = text;
	}

	//
	//vec2 pen = { { x, y } };
	//text_buffer_add_text(buffer, &pen, &normal, text, length);

	mat4_set_identity(&model);

	float stretch = 1.01f; // mBounds[2] / (0.8f * rectw);
	float xoffset = 0.25f * mBounds[2] / length;
	float yoffset = recth - 0.5f * (recth - mBounds[3]);

	mat4_set_scaling(&model, stretch, 1.0f, 1.0f);
	mat4_translate(&model, x + xoffset, y + yoffset, 0.0f);
	
}
Exemplo n.º 6
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    GLFWwindow* window;
    char* screenshot_path = NULL;

    if (argc > 1)
    {
        if (argc == 3 && 0 == strcmp( "--screenshot", argv[1] ))
            screenshot_path = argv[2];
        else
        {
            fprintf( stderr, "Unknown or incomplete parameters given\n" );
            exit( EXIT_FAILURE );
        }
    }

    glfwSetErrorCallback( error_callback );

    if (!glfwInit( ))
    {
        exit( EXIT_FAILURE );
    }

    glfwWindowHint( GLFW_VISIBLE, GL_FALSE );
    glfwWindowHint( GLFW_RESIZABLE, GL_FALSE );

    window = glfwCreateWindow( 1000, 500, argv[0], NULL, NULL );

    if (!window)
    {
        glfwTerminate( );
        exit( EXIT_FAILURE );
    }

    glfwMakeContextCurrent( window );
    glfwSwapInterval( 1 );

    glfwSetFramebufferSizeCallback( window, reshape );
    glfwSetWindowRefreshCallback( window, display );
    glfwSetKeyCallback( window, keyboard );

#ifndef __APPLE__
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
        exit( EXIT_FAILURE );
    }
    fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
#endif

    float start=(float)(glfwGetTime()*1000.0f);
    init();
    ////printf("init waste_time: %f\n", (float)(glfwGetTime()*1000.0f)-start);

    glfwShowWindow( window );
    reshape( window, 1000, 500 );

    while(!glfwWindowShouldClose( window ))
    {
        start=(float)(glfwGetTime()*1000.0f);
        display( window );
        glfwPollEvents( );
        ///printf("waste_time: %f\n", (float)(glfwGetTime()*1000.0f)-start);

        if (screenshot_path)
        {
            screenshot( window, (const char*)screenshot_path );
            glfwSetWindowShouldClose( window, 1 );
        }
    }

    glDeleteProgram( bounds_shader );
    glDeleteProgram( text_shader );
    glDeleteTextures( 1, &font_manager->atlas->id );
    font_manager->atlas->id = 0;
    text_buffer_delete( buffer );
    font_manager_delete( font_manager );

    glfwDestroyWindow( window );
    glfwTerminate( );

    return EXIT_SUCCESS;
}