Exemplo n.º 1
0
void prepare_shader(void)
{
	// build the shader program
	vert = shader_load(GL_VERTEX_SHADER, "data/render.vert");
	frag = shader_load(GL_FRAGMENT_SHADER, "data/render.frag");
	prog = glCreateProgram();
	glAttachShader(prog, vert);
	glAttachShader(prog, frag);
	glLinkProgram(prog);
	GLint param;
	glGetProgramiv(prog, GL_LINK_STATUS, &param);
	printf("*** Shader linking %s.\n",
		param == GL_FALSE ? "went as expected" : "worked");
	printProgramInfoLog(prog);

	// prepare uniforms etc for the shader	
	s_angle = glGetUniformLocation(prog, "angle");	
	s_pos = glGetUniformLocation(prog, "position");	
	s_pixelarc = glGetUniformLocation(prog, "pixel_arc");
	s_fovdepth = glGetUniformLocation(prog, "fovdepth");
	s_bPool = glGetUniformLocation(prog, "bPool");	
	s_nPool = glGetUniformLocation(prog, "nPool");	
//	s_now = glGetUniformLocation(prog, "now");	
//	glUniform1i(s_now, now);
	glUniformui64NV(s_nPool, nodepool_devptr);
//	glUniform1i(s_bPool, 0);

//	glMakeBufferNonResidentNV(GL_ARRAY_BUFFER_ARB);
}
Exemplo n.º 2
0
// ------------------------------------------------------------------- init ---
void init( void )
{
    atlas = texture_atlas_new( 512, 512, 1 );
    auto filename = "fonts/Vera.ttf";
    auto text = "A Quick Brown Fox Jumps Over The Lazy Dog 0123456789";
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
    vec2 pen = {0,0};
    auto black = vec4{1,1,1,1};
    auto font = texture_font_new_from_file( atlas, 48, filename );
    font->rendermode = RENDER_SIGNED_DISTANCE_FIELD;
    auto bbox = add_text( buffer, font, text, &black, &pen );
    size_t i;
    auto vertices = buffer->vertices;
    for( i=0; i< vector_size(vertices); ++i ) {
        auto vert = (vertex *) vector_get(vertices,i);
        vert->x -= (int)(bbox.x + bbox.width/2);
        vert->y -= (int)(bbox.y + bbox.height/2);
    }

    glGenTextures( 1, &atlas->id );
    glBindTexture( GL_TEXTURE_2D, 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_RED, atlas->width, atlas->height,
                  0, GL_RED, GL_UNSIGNED_BYTE, atlas->data );

    shader = shader_load( "shaders/distance-field-2v5.vert",
                          "shaders/distance-field-2v5.frag" );
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
}
// ------------------------------------------------------------------- init ---
void init( void )
{
    atlas = texture_atlas_new( 512, 512, 1 );
    font = texture_font_new_from_file( atlas, 32, "../media/fonts/Vera.ttf" );

    texture_glyph_t *glyph;

    // Generate the glyp at 512 points, compute distance field and scale it
    // back to 32 points
    // Just load another glyph if you want to see difference (draw render a '@')
    glyph = load_glyph( "../media/fonts/Vera.ttf", "@", 512, 64, 0.1);
    vector_push_back( font->glyphs, &glyph );

    texture_atlas_upload( atlas );

    glyph = texture_font_get_glyph( font, "@");

    GLuint indices[6] = {0,1,2, 0,2,3};
    vertex_t vertices[4] = { { -.5,-.5,0,  glyph->s0,glyph->t1,  0,0,0,1 },
                             { -.5, .5,0,  glyph->s0,glyph->t0,  0,0,0,1 },
                             {  .5, .5,0,  glyph->s1,glyph->t0,  0,0,0,1 },
                             {  .5,-.5,0,  glyph->s1,glyph->t1,  0,0,0,1 } };
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
    vertex_buffer_push_back( buffer, vertices, 4, indices, 6 );

    program = shader_load( "../media/shaders/distance-field.vert",
                           "../media/shaders/distance-field-2.frag" );
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
}
Exemplo n.º 4
0
// ------------------------------------------------------------------- init ---
void init( void )
{
    control_key_handled = 0;

    console = console_new();
    console_print( console,
                   "OpenGL Freetype console\n"
                   "Copyright 2011 Nicolas P. Rougier. All rights reserved.\n \n" );
    console_connect( console, "activate",     console_activate );
    console_connect( console, "complete",     console_complete );
    console_connect( console, "history-prev", console_history_prev );
    console_connect( console, "history-next", console_history_next );

    glClearColor( 1.00, 1.00, 1.00, 1.00 );
    glDisable( GL_DEPTH_TEST );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable( GL_TEXTURE_2D );
    glEnable( GL_BLEND );

    shader = shader_load("shaders/v3f-t2f-c4f.vert",
                         "shaders/v3f-t2f-c4f.frag");
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
}
Exemplo n.º 5
0
static void
greets_display_effect (sync_info *sync, void *params, int iparam)
{
  greets_data *gdata = (greets_data *) params;
  f32 indmtx[2][3] = { { 0.5, 0.0, 0.0 },
		       { 0.0, 0.5, 0.0 } };
  float scroll = (float) sync->time_offset / 900.0;
  int i, startpos;

  /*world_set_pos_lookat_up (gdata->world,
			   (guVector) spooky_ghost_data_0.scene.pos,
			   (guVector) spooky_ghost_data_0.scene.lookat,
			   (guVector) spooky_ghost_data_0.scene.up);*/

  GX_SetIndTexMatrix (GX_ITM_0, indmtx, 5);

  world_display (gdata->world);
  GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE);
  
  shader_load (gdata->tile_shader);

  startpos = (int) (scroll * 8.0) - 32;

  for (i = 0; i < 4; i++)
    put_text (gdata->tileidx, i, 0, message, sizeof (message) - 1,
	      startpos * 4 + i, 32);

  GX_SetTevColor (GX_TEVREG0, (GXColor) { 255, 255, 255, 255 });
  render_texture (gdata, 5.5, scroll);

  //screenspace_rect (gdata->tile_shader, GX_VTXFMT0, 0);
}
Exemplo n.º 6
0
// ------------------------------------------------------------------- main ---
int
main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
    glutInitWindowSize( 256, 256) ;
    glutCreateWindow( argv[0] );
    glutDisplayFunc( display );
    glutReshapeFunc( reshape );
    glutKeyboardFunc( keyboard );

    buffer = vertex_buffer_new( "v3f:c4f:t3f" ); 
    program = shader_load( "shaders/line-aa.vert",
                           "shaders/line-aa-round.frag" );
    size_t n = 20, i;
    vec4 color = {{0,0,0,1}};
    for (i = 0; i < n; ++i)
    {
        float x0 = 30;
        float y0 = 230 - i*10;
        float thickness = (i+1)/10.0;
        vec2 points[] = { {{ x0+  0, y0+10 }},  {{x0+ 40, y0-10 }}, {{ x0+ 80, y0+10 }},
                          {{ x0+120, y0-10 }}, {{ x0+160, y0+10 }}, {{ x0+200, y0-10 }} };
        vertex_buffer_add_polyline( buffer, points, 6, color, thickness, round_join, round_cap);
    }
    glutMainLoop();
    return 0;
}
// ------------------------------------------------------------------- init ---
void init( void )
{
    size_t i;
    vec2 pen = {{0,0}};
    vec4 color = {{0,0,0,1}};

    atlas  = texture_atlas_new( 512, 512, 1 );
    font = texture_font_new_from_file( atlas, 12, "../media/fonts/VeraMono.ttf" );
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );

    pen.y = -font->descender;
    for( i=0; i<line_count; ++i )
    {
        pen.x = 10.0;
        add_text( buffer, font, text, &color, &pen );
        pen.y += font->height - font->linegap;
    }

    glClearColor( 1.0, 1.0, 1.0, 1.0 );
    glDisable( GL_DEPTH_TEST );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable( GL_TEXTURE_2D );
    glEnable( GL_BLEND );

    shader = shader_load("../media/shaders/v3f-t2f-c4f.vert",
                         "../media/shaders/v3f-t2f-c4f.frag");
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
}
Exemplo n.º 8
0
// ------------------------------------------------------------------- main ---
int
main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize( 800, 600 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( "Signed Distance Field" );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );
#ifndef __APPLE__
    glewExperimental = GL_TRUE;
    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
    texture_font_t *font = 0;
    texture_atlas_t *atlas = texture_atlas_new( 512, 512, 1 );
    const char * filename = "fonts/Vera.ttf";
    wchar_t *text = L"A Quick Brown Fox Jumps Over The Lazy Dog 0123456789";
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
    vec2 pen = {{0,0}};
    vec4 black = {{1,1,1,1}};
    font = texture_font_new_from_file( atlas, 48, filename );
    vec4 bbox = add_text( buffer, font, text, &black, &pen );
    size_t i;
    vector_t * vertices = buffer->vertices;
    for( i=0; i< vector_size(vertices); ++i )
    {
        vertex_t * vertex = (vertex_t *) vector_get(vertices,i);
        vertex->x -= (int)(bbox.x + bbox.width/2);
        vertex->y -= (int)(bbox.y + bbox.height/2);
    }


    glBindTexture( GL_TEXTURE_2D, atlas->id );

    fprintf( stderr, "Generating distance map...\n" );
    unsigned char *map = make_distance_map(atlas->data, atlas->width, atlas->height);
    fprintf( stderr, "done !\n");

    memcpy( atlas->data, map, atlas->width*atlas->height*sizeof(unsigned char) );
    free(map);
    texture_atlas_upload( atlas );

    shader = shader_load( "shaders/distance-field-2.vert",
                          "shaders/distance-field-2.frag" );
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );

    glutMainLoop( );
    return 0;
}
Exemplo n.º 9
0
static int
lload(lua_State *L) {
	int prog = (int)luaL_checkinteger(L,1);
	const char *fs = luaL_checkstring(L, 2);
	const char *vs = luaL_checkstring(L, 3);
	shader_load(prog, fs, vs);
	return 0;
}
Exemplo n.º 10
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    size_t width = 800, height = 200;

    glutInit( &argc, argv );
    glutInitWindowSize( width, height );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( "Glyph Cartoon" );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );

    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) );

    atlas = texture_atlas_new( 1024, 1024, 1 );
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" ); 
    texture_font_t *font =
		texture_font_new_from_file( atlas, 128, "fonts/ObelixPro.ttf" );

    vec2 pen    = {{50, 50}};
    vec4 black  = {{0.0, 0.0, 0.0, 1.0}};
    vec4 yellow = {{1.0, 1.0, 0.0, 1.0}};
    vec4 orange1 = {{1.0, 0.9, 0.0, 1.0}};
    vec4 orange2 = {{1.0, 0.6, 0.0, 1.0}};


    font->outline_type = 2;
    font->outline_thickness = 7;
    add_text( buffer, font, L"Freetype GL", pen, black, black );

    font->outline_type = 2;
    font->outline_thickness = 5;
    add_text( buffer, font, L"Freetype GL", pen, yellow, yellow );

    font->outline_type = 1;
    font->outline_thickness = 3;
    add_text( buffer, font, L"Freetype GL", pen, black, black );

    font->outline_type = 0;
    font->outline_thickness = 0;
    add_text( buffer, font, L"Freetype GL", pen, orange1, orange2 );

    shader = shader_load("shaders/v3f-t2f-c4f.vert",
                         "shaders/v3f-t2f-c4f.frag");
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );

    glutMainLoop( );
    return 0;
}
Exemplo n.º 11
0
GLuint shader_loadVersion(const char *filenm, int GLver)
{
    if(GLver > 100)
        return -1;
    char ver[4] = {0,0,0,0};
    snprintf(ver, 4, "%d", GLver);
    char buf[32] = SHADER_DIR;
    strcat(buf, filenm);
    return shader_load(buf);
}
Exemplo n.º 12
0
bool CFont::Display()
{
	if (nullptr == font_manager || nullptr == buffer)
		return false;

	// TODO: check if we need to load a glsl shader
	if (0 == text_shader)
	{
		FBString appPath;

		appPath = FBSystem::TheOne().ApplicationPath;
		appPath = appPath + "\\plugins";

		FBString vert(appPath, SHADER_VERTEX);
		FBString frag(appPath, SHADER_FRAGMENT);

		text_shader = shader_load(vert, frag);
	}

	if (0 == text_shader)
		return false;

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glUseProgram(text_shader);
	{
		glUniformMatrix4fv(glGetUniformLocation(text_shader, "model"),
			1, 0, model.data);
		glUniformMatrix4fv(glGetUniformLocation(text_shader, "view"),
			1, 0, view.data);
		glUniformMatrix4fv(glGetUniformLocation(text_shader, "projection"),
			1, 0, projection.data);
		glUniform1i(glGetUniformLocation(text_shader, "tex"), 0);
		glUniform3f(glGetUniformLocation(text_shader, "pixel"),
			1.0f / font_manager->atlas->width,
			1.0f / font_manager->atlas->height,
			(float)font_manager->atlas->depth);

		glEnable(GL_BLEND);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, font_manager->atlas->id);

		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBlendColor(1, 1, 1, 1);

		vertex_buffer_render(buffer->buffer, GL_TRIANGLES);
		glBindTexture(GL_TEXTURE_2D, 0);
		glBlendColor(0, 0, 0, 0);
		glUseProgram(0);

		glDisable(GL_BLEND);
	}

	return true;
}
Exemplo n.º 13
0
text_buffer_t *
text_buffer_new( size_t depth,
                 const char * vert_filename,
                 const char * frag_filename )
{
    GLuint program = shader_load( vert_filename, frag_filename );

    text_buffer_t * p = text_buffer_new_with_program( depth, program );

    return p;
}
Exemplo n.º 14
0
void shader_init(shader_t *s, const char *program)
{
    s->program = shader_load(program);

    s->nattribs = 0; 
    s->noutputs = 0;
    s->ntexture_targets = 0;
    s->attrib_stride = 0;
    s->attribs = malloc(sizeof(struct shader_attrib_t) * 16);
    s->outputs = malloc(sizeof(struct shader_fragment_output_t) * 16);
    s->texture_targets = malloc(sizeof(struct shader_texture_target_t) * 16);
}
Exemplo n.º 15
0
// ------------------------------------------------------------------- main ---
int
main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize( 512, 512 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( "Freetype OpenGL width shaders" );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutMotionFunc( mouse_drag );
    glutPassiveMotionFunc( mouse_motion );
    glutKeyboardFunc( keyboard );

    glewExperimental = GL_TRUE;
    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) );


    unsigned char *map;
    texture_font_t * font;
    const char *filename = "fonts/Vera.ttf";
    const wchar_t *cache = L" !\"#$%&'()*+,-./0123456789:;<=>?"
                           L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
                           L"`abcdefghijklmnopqrstuvwxyz{|}~";

    atlas = texture_atlas_new( 512, 512, 1 );
    font = texture_font_new_from_file( atlas, 72, filename );
    texture_font_load_glyphs( font, cache );
    texture_font_delete( font );

    fprintf( stderr, "Generating distance map...\n" );
    map = make_distance_map(atlas->data, atlas->width, atlas->height);
    fprintf( stderr, "done !\n");

    memcpy( atlas->data, map, atlas->width*atlas->height*sizeof(unsigned char) );
    free(map);
    texture_atlas_upload( atlas );

    // Create the GLSL program
    program = shader_load( "shaders/distance-field.vert",
                           "shaders/distance-field.frag" );
    glUseProgram( program );

    glutMainLoop( );
    return 0;
}
Exemplo n.º 16
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    size_t i;
    vec4 color = {{0,0,0,1}};
    vec2 pen = {{0,0}};

    glutInit( &argc, argv );
    glutInitWindowSize( 800, 600 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( "Freetype OpenGL benchmark" );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );
    glutIdleFunc( idle );

    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) );

    atlas  = texture_atlas_new( 512, 512, 1 );
    font = texture_font_new( atlas, "fonts/VeraMono.ttf", 12 );
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" ); 

    pen.y = -font->descender;
    for( i=0; i<line_count; ++i )
    {
        pen.x = 10.0;
        add_text( buffer, font, text, &color, &pen );
        pen.y += font->height - font->linegap;
    }

    glClearColor( 1.0, 1.0, 1.0, 1.0 );
    glDisable( GL_DEPTH_TEST ); 
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable( GL_TEXTURE_2D );
    glEnable( GL_BLEND );

    shader = shader_load("shaders/v3f-t2f-c4f.vert",
                         "shaders/v3f-t2f-c4f.frag");
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );

    glutMainLoop( );

    return EXIT_SUCCESS;
}
Exemplo n.º 17
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize( 800, 400 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( "Freetype OpenGL / LCD filtering" );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );

    glewExperimental = GL_TRUE;
    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) );

    size_t i;
    texture_font_t *font = 0;
    atlas = texture_atlas_new( 512, 512, 3 );
    const char * filename = "fonts/Vera.ttf";
    wchar_t *text = L"A Quick Brown Fox Jumps Over The Lazy Dog 0123456789";
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f,ashift:1f,agamma:1f" ); 
    vec2 pen = {{0,0}};
    vec4 color = {{0,0,0,1}};

    for( i=7; i < 27; ++i)
    {
        font = texture_font_new_from_file( atlas, i, filename );
        pen.x = 0;
        pen.y -= font->height;
        texture_font_load_glyphs( font, text );
        add_text( buffer, font, text, &color, &pen );
        texture_font_delete( font );
    }
    glBindTexture( GL_TEXTURE_2D, atlas->id );

    shader = shader_load( "shaders/text.vert",
                          "shaders/text.frag" );
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );

    glutMainLoop( );

    return 0;
}
Exemplo n.º 18
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize( 400, 400 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( argv[0] );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );
    //glutTimerFunc( 1000/60, timer, 1000/60 ); // not working on some systems (bug in GLUT)
    glutIdleFunc(display);

    glewExperimental = GL_TRUE;
    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) );


    typedef struct { float x,y,z;} xyz;
    typedef struct { float r,g,b,a;} rgba;
    typedef struct { xyz position, normal; rgba color;} vertex;
    xyz v[] = { { 1, 1, 1},  {-1, 1, 1},  {-1,-1, 1}, { 1,-1, 1},
                { 1,-1,-1},  { 1, 1,-1},  {-1, 1,-1}, {-1,-1,-1} };
    xyz n[] = { { 0, 0, 1},  { 1, 0, 0},  { 0, 1, 0} ,
                {-1, 0, 1},  { 0,-1, 0},  { 0, 0,-1} };
    rgba c[] = { {1, 1, 1, 1},  {1, 1, 0, 1},  {1, 0, 1, 1},  {0, 1, 1, 1},
                 {1, 0, 0, 1},  {0, 0, 1, 1},  {0, 1, 0, 1},  {0, 0, 0, 1} };
    vertex vertices[24] =  {
      {v[0],n[0],c[0]}, {v[1],n[0],c[1]}, {v[2],n[0],c[2]}, {v[3],n[0],c[3]},
      {v[0],n[1],c[0]}, {v[3],n[1],c[3]}, {v[4],n[1],c[4]}, {v[5],n[1],c[5]},
      {v[0],n[2],c[0]}, {v[5],n[2],c[5]}, {v[6],n[2],c[6]}, {v[1],n[2],c[1]},
      {v[1],n[3],c[1]}, {v[6],n[3],c[6]}, {v[7],n[3],c[7]}, {v[2],n[3],c[2]},
      {v[7],n[4],c[7]}, {v[4],n[4],c[4]}, {v[3],n[4],c[3]}, {v[2],n[4],c[2]},
      {v[4],n[5],c[4]}, {v[7],n[5],c[7]}, {v[6],n[5],c[6]}, {v[5],n[5],c[5]} };
    GLuint indices[24] = { 0, 1, 2, 3,    4, 5, 6, 7,   8, 9,10,11,
                           12,13,14,15,  16,17,18,19,  20,21,22,23 };

    cube = vertex_buffer_new( "vertex:3f,normal:3f,color:4f" );
    vertex_buffer_push_back( cube, vertices, 24, indices, 24 );
    shader = shader_load("shaders/cube.vert","shaders/cube.frag");

    init( );
    glutMainLoop( );
    return EXIT_SUCCESS;
}
Exemplo n.º 19
0
// ----------------------------------------------------------------------------
text_buffer_t *
text_buffer_new( size_t depth )
{
    
    text_buffer_t *self = (text_buffer_t *) malloc (sizeof(text_buffer_t));
    self->buffer = vertex_buffer_new( "v3f:t2f:c4f:1g1f:2g1f" ); 
    self->manager = font_manager_new( 512, 512, depth );
        self->shader = shader_load("shaders/text.vert",
                                   "shaders/text.frag");
    self->shader_texture = glGetUniformLocation(self->shader, "texture");
    self->shader_pixel = glGetUniformLocation(self->shader, "pixel");
    self->line_start = 0;
    self->line_ascender = 0;
    self->line_descender = 0;
    return self;
}
Exemplo n.º 20
0
int
main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( argv[0] );
    glutReshapeFunc( on_reshape );
    glutDisplayFunc( on_display );
    glutKeyboardFunc( on_key_press );
    glutSpecialFunc( on_special_key_press );
    glutReshapeWindow( 600,400 );
#ifndef __APPLE__
    glewExperimental = GL_TRUE;
    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
    console = console_new();
    console_print( console,
                   L"OpenGL Freetype console\n"
                   L"Copyright 2011 Nicolas P. Rougier. All rights reserved.\n \n" );
    console_connect( console, "activate",     console_activate );
    console_connect( console, "complete",     console_complete );
    console_connect( console, "history-prev", console_history_prev );
    console_connect( console, "history-next", console_history_next );

    glClearColor( 1.00, 1.00, 1.00, 1.00 );
    glDisable( GL_DEPTH_TEST );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable( GL_TEXTURE_2D );
    glEnable( GL_BLEND );

    shader = shader_load("shaders/v3f-t2f-c4f.vert",
                         "shaders/v3f-t2f-c4f.frag");
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
    glutMainLoop();


    return 0;
}
Exemplo n.º 21
0
// ----------------------------------------------------------------------------
text_buffer_t *
text_buffer_new( size_t depth )
{
    
    text_buffer_t *self = (text_buffer_t *) malloc (sizeof(text_buffer_t));
    self->buffer = vertex_buffer_new(
        "vertex:3f,tex_coord:2f,color:4f,ashift:1f,agamma:1f" );
    self->manager = font_manager_new( 512, 512, depth );
    self->shader = shader_load("shaders/text.vert",
                               "shaders/text.frag");
    self->shader_texture = glGetUniformLocation(self->shader, "texture");
    self->shader_pixel = glGetUniformLocation(self->shader, "pixel");
    self->line_start = 0;
    self->line_ascender = 0;
    self->line_descender = 0;
    return self;
}
Exemplo n.º 22
0
Shader_t *shader_loadFromFiles(const char *aVertShaderPath, const char *aFragShaderPath)
{
    char *vertShaderSource = NULL, *fragShaderSource = NULL;
    size_t vertShaderLength, fragShaderLength;
    
    util_readFile(aVertShaderPath, &vertShaderLength, &vertShaderSource);
    dynamo_assert(vertShaderLength > 0 && vertShaderSource != NULL, "Could not read vertex shader source");

    util_readFile(aFragShaderPath, &fragShaderLength, &fragShaderSource);
    dynamo_assert(fragShaderLength > 0 && fragShaderSource != NULL, "Could not read fragment shader source");
    Shader_t *out = shader_load(vertShaderSource, fragShaderSource);

    free(vertShaderSource);
    free(fragShaderSource);

    return out;
}
Exemplo n.º 23
0
// ------------------------------------------------------------------- init ---
void init( void )
{
    atlas = texture_atlas_new( 1024, 1024, 1 );
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
    texture_font_t *font =
    texture_font_new_from_file( atlas, 128, "fonts/LuckiestGuy.ttf" );

    vec2 pen    = {{50, 50}};
    vec4 black  = {{0.0, 0.0, 0.0, 1.0}};
    vec4 yellow = {{1.0, 1.0, 0.0, 1.0}};
    vec4 orange1 = {{1.0, 0.9, 0.0, 1.0}};
    vec4 orange2 = {{1.0, 0.6, 0.0, 1.0}};

    font->rendermode = RENDER_OUTLINE_POSITIVE;
    font->outline_thickness = 7;
    add_text( buffer, font, "Freetype GL", pen, black, black );

    font->rendermode = RENDER_OUTLINE_POSITIVE;
    font->outline_thickness = 5;
    add_text( buffer, font, "Freetype GL", pen, yellow, yellow );

    font->rendermode = RENDER_OUTLINE_EDGE;
    font->outline_thickness = 3;
    add_text( buffer, font, "Freetype GL", pen, black, black );

    font->rendermode = RENDER_NORMAL;
    font->outline_thickness = 0;
    add_text( buffer, font, "Freetype GL", pen, orange1, orange2 );

    glGenTextures( 1, &atlas->id );
    glBindTexture( GL_TEXTURE_2D, 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_RED, atlas->width, atlas->height,
                  0, GL_RED, GL_UNSIGNED_BYTE, atlas->data );

    shader = shader_load("shaders/v3f-t2f-c4f.vert",
                         "shaders/v3f-t2f-c4f.frag");
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
}
Exemplo n.º 24
0
// ------------------------------------------------------------------- main ---
int
main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize( 512, 512 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( "Distance fields demo" );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );
    glutTimerFunc( 1000.0/60, timer, 60 );

    glewExperimental = GL_TRUE;
    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) );

    program = shader_load( "shaders/distance-field.vert",
                           "shaders/distance-field-3.frag" );
    glUseProgram( program );
    atlas = texture_atlas_new( 512, 512, 1 );
    font = texture_font_new_from_file( atlas, 32, "fonts/Vera.ttf" );

    texture_glyph_t *glyph;

    // Generate the glyp at 512 points, compute distance field and scale it
    // back to 32 points
    // Just load another glyph if you want to see difference (draw render a '@')
    glyph = load_glyph( "fonts/Vera.ttf", L'@', 512, 64, 0.1);
    vector_push_back( font->glyphs, &glyph );

    texture_atlas_upload( atlas );

    glutMainLoop( );
    return 0;
}
Exemplo n.º 25
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    size_t i;
    vec4 color = {{0,0,0,1}};
    vec2 pen = {{0,0}};

    glutInit( &argc, argv );
    glutInitWindowSize( 800, 600 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( "Freetype OpenGL benchmark" );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );
    glutIdleFunc( idle );

    atlas  = texture_atlas_new( 512, 512, 1 );
    font = texture_font_new( atlas, "fonts/VeraMono.ttf", 12 );
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" ); 

    pen.y = -font->descender;
    for( i=0; i<line_count; ++i )
    {
        pen.x = 10.0;
        add_text( buffer, font, text, &color, &pen );
        pen.y += font->height - font->linegap;
    }

    glClearColor( 1.0, 1.0, 1.0, 1.0 );
    glDisable( GL_DEPTH_TEST ); 
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable( GL_TEXTURE_2D );
    glEnable( GL_BLEND );

    shader = shader_load("shaders/v3f-t2f-c4f.vert",
                         "shaders/v3f-t2f-c4f.frag");
    glutMainLoop( );

    return EXIT_SUCCESS;
}
Exemplo n.º 26
0
void
skybox_render (skybox_info *skybox)
{
  const u32 vtxfmt = GX_VTXFMT0;
  int face;

  GX_ClearVtxDesc ();
  GX_SetVtxDesc (GX_VA_POS, GX_INDEX8);
  GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
  
  GX_SetArray (GX_VA_POS, vertices, 3 * sizeof (f32));
  
  GX_SetVtxAttrFmt (vtxfmt, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
  GX_SetVtxAttrFmt (vtxfmt, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
  
  GX_SetCullMode (GX_CULL_BACK);
  
  for (face = 0; face < 6; face++)
    {
      shader_load (skybox->face_shader[face]);

      GX_Begin (GX_TRIANGLESTRIP, vtxfmt, 4);

      GX_Position1x8 (faces[face][0]);
      GX_TexCoord2f32 (0, 1);

      GX_Position1x8 (faces[face][1]);
      GX_TexCoord2f32 (0, 0);

      GX_Position1x8 (faces[face][2]);
      GX_TexCoord2f32 (1, 1);

      GX_Position1x8 (faces[face][3]);
      GX_TexCoord2f32 (1, 0);

      GX_End ();
    }
}
Exemplo n.º 27
0
// ------------------------------------------------------------------- init ---
void init( void )
{
    texture_font_t *font = 0;
    texture_atlas_t *atlas = texture_atlas_new( 512, 512, 1 );
    const char * filename = "fonts/Vera.ttf";
    char *text = "A Quick Brown Fox Jumps Over The Lazy Dog 0123456789";
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
    vec2 pen = {{0,0}};
    vec4 black = {{1,1,1,1}};
    font = texture_font_new_from_file( atlas, 48, filename );
    vec4 bbox = add_text( buffer, font, text, &black, &pen );
    texture_atlas_upload( font->atlas );
    size_t i;
    vector_t * vertices = buffer->vertices;
    for( i=0; i< vector_size(vertices); ++i )
    {
        vertex_t * vertex = (vertex_t *) vector_get(vertices,i);
        vertex->x -= (int)(bbox.x + bbox.width/2);
        vertex->y -= (int)(bbox.y + bbox.height/2);
    }


    glBindTexture( GL_TEXTURE_2D, atlas->id );

    fprintf( stderr, "Generating distance map...\n" );
    unsigned char *map = make_distance_mapb(atlas->data, atlas->width, atlas->height);
    fprintf( stderr, "done !\n");

    memcpy( atlas->data, map, atlas->width*atlas->height*sizeof(unsigned char) );
    free(map);
    texture_atlas_upload( atlas );

    shader = shader_load( "shaders/distance-field.vert",
                          "shaders/distance-field-2.frag" );
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
}
Exemplo n.º 28
0
// ------------------------------------------------------------------- init ---
void init( void )
{
    typedef struct { float x,y,z;} xyz;
    typedef struct { float r,g,b,a;} rgba;
    typedef struct { xyz position, normal; rgba color;} vertex;
    xyz v[] = { { 1, 1, 1},  {-1, 1, 1},  {-1,-1, 1}, { 1,-1, 1},
                { 1,-1,-1},  { 1, 1,-1},  {-1, 1,-1}, {-1,-1,-1} };
    xyz n[] = { { 0, 0, 1},  { 1, 0, 0},  { 0, 1, 0} ,
                {-1, 0, 1},  { 0,-1, 0},  { 0, 0,-1} };
    rgba c[] = { {1, 1, 1, 1},  {1, 1, 0, 1},  {1, 0, 1, 1},  {0, 1, 1, 1},
                 {1, 0, 0, 1},  {0, 0, 1, 1},  {0, 1, 0, 1},  {0, 0, 0, 1} };
    vertex vertices[24] =  {
      {v[0],n[0],c[0]}, {v[1],n[0],c[1]}, {v[2],n[0],c[2]}, {v[3],n[0],c[3]},
      {v[0],n[1],c[0]}, {v[3],n[1],c[3]}, {v[4],n[1],c[4]}, {v[5],n[1],c[5]},
      {v[0],n[2],c[0]}, {v[5],n[2],c[5]}, {v[6],n[2],c[6]}, {v[1],n[2],c[1]},
      {v[1],n[3],c[1]}, {v[6],n[3],c[6]}, {v[7],n[3],c[7]}, {v[2],n[3],c[2]},
      {v[7],n[4],c[7]}, {v[4],n[4],c[4]}, {v[3],n[4],c[3]}, {v[2],n[4],c[2]},
      {v[4],n[5],c[4]}, {v[7],n[5],c[7]}, {v[6],n[5],c[6]}, {v[5],n[5],c[5]} };
    GLuint indices[24] = { 0, 1, 2, 3,    4, 5, 6, 7,   8, 9,10,11,
                           12,13,14,15,  16,17,18,19,  20,21,22,23 };

    cube = vertex_buffer_new( "vertex:3f,normal:3f,color:4f" );
    vertex_buffer_push_back( cube, vertices, 24, indices, 24 );
    shader = shader_load("../media/shaders/cube.vert","../media/shaders/cube.frag");

    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );

    glPolygonOffset( 1, 1 );
    glClearColor( 1.0, 1.0, 1.0, 1.0 );
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_COLOR_MATERIAL );
    glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable( GL_LINE_SMOOTH );
}
Exemplo n.º 29
0
// ------------------------------------------------------------------- init ---
void init( void )
{
    size_t i;
    texture_font_t *font = 0;
    atlas = texture_atlas_new( 512, 512, 3 );
    const char * filename = "fonts/Vera.ttf";
    char * text = "A Quick Brown Fox Jumps Over The Lazy Dog 0123456789";
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f,ashift:1f,agamma:1f" );
    vec2 pen = {{0,0}};
    vec4 color = {{0,0,0,1}};

    for( i=7; i < 27; ++i)
    {
        font = texture_font_new_from_file( atlas, i, filename );
        pen.x = 0;
        pen.y -= font->height;
        texture_font_load_glyphs( font, text );
        add_text( buffer, font, text, &color, &pen );
        texture_font_delete( font );
    }

    glGenTextures( 1, &atlas->id );
    glBindTexture( GL_TEXTURE_2D, 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, atlas->width, atlas->height,
                  0, GL_RGB, GL_UNSIGNED_BYTE, atlas->data );

    shader = shader_load( "shaders/text.vert",
                          "shaders/text.frag" );
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
}
Exemplo n.º 30
0
// ------------------------------------------------------------------- main ---
int main_texture( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize( 512, 512 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( argv[0] );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );

//    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) );

    texture_atlas_t * atlas = texture_atlas_new( 512, 512, 1 );
//    const char *filename = "/Users/jie/svn/v8/deps/freetype-gl-read-only/fonts/Vera.ttf";
    const char *filename = "/Users/jie/svn/v8/deps/freetype-gl-read-only/fonts/fat.ttf";
//    const wchar_t *cache = L" !\"#$%&'()*+,-./0123456789:;<=>?"
//                           L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
//                           L"`abcdefghijklmnopqrstuvwxyz{|}~";
    wchar_t unicode[6];
    unicode[0] = 22909;
    unicode[1] = 20320;
    unicode[2] = 25438;
    unicode[3] = 28156;
    unicode[4] = 48;
    unicode[5] = 0;
    wchar_t* cache = (wchar_t*)unicode;
    printf("%d %d\n", cache[0], wcslen(cache));
    size_t minsize = 20, maxsize = 40;
    size_t count = maxsize - minsize;
    size_t i, missed = 0;

    for( i=minsize; i < maxsize; ++i )
    {
        texture_font_t * font = texture_font_new( atlas, filename, i );
        missed += texture_font_load_glyphs( font, cache );
        texture_font_delete( font );
    }

    printf( "Matched font               : %s\n", filename );
    printf( "Number of fonts            : %ld\n", count );
    printf( "Number of glyphs per font  : %ld\n", wcslen(cache) );
    printf( "Number of missed glyphs    : %ld\n", missed );
    printf( "Total number of glyphs     : %ld/%ld\n", wcslen(cache)*count - missed, wcslen(cache)*count );
    printf( "Texture size               : %ldx%ld\n", atlas->width, atlas->height );
    printf( "Texture occupancy          : %.2f%%\n", 100.0*atlas->used/(float)(atlas->width*atlas->height) );

    glClearColor(1,1,1,1);
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, atlas->id );

    typedef struct { float x,y,z, u,v, r,g,b,a; } vertex_t;
    vertex_t vertices[4] =  {
        {  0,  0,  0, 0,1, 0,0,0,1},
        {  0,  512,0, 0,0, 0,0,0,1},
        {  512,512,0, 1,0, 0,0,0,1},
        {  512,  0,0, 1,1, 0,0,0,1}
    };

    GLuint indices[6] = { 0,1,2, 0,2,3 };
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
    vertex_buffer_push_back( buffer, vertices, 4, indices, 6 );

    shader = shader_load("/Users/jie/svn/v8/deps/freetype-gl-read-only/shaders/v3f-t2f-c4f.vert",
                         "/Users/jie/svn/v8/deps/freetype-gl-read-only/shaders/v3f-t2f-c4f.frag");
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );

    glutMainLoop( );

    return 0;
}