Commit 2f6c485a authored by Nicolas P. Rougier's avatar Nicolas P. Rougier

Merge pull request #4 from cforfang/master

Various fixes from cforfang
parents 20d7320c 48e7e0f6
......@@ -32,6 +32,7 @@
* ============================================================================
*/
#include <stdio.h>
#include <time.h>
#include "freetype-gl.h"
#include "shader.h"
#include "vertex-buffer.h"
......@@ -70,13 +71,15 @@ void display( void )
{
static float theta=0, phi=0;
static GLuint Color = 0;
float seconds_elapsed = (float)clock() / CLOCKS_PER_SEC;
if( !Color )
{
Color = glGetUniformLocation( shader, "Color" );
}
theta += .5; phi += .5;
theta = .5f * seconds_elapsed / 0.016f;
phi = .5f * seconds_elapsed / 0.016f;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
......@@ -144,7 +147,8 @@ int main( int argc, char **argv )
glutReshapeFunc( reshape );
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutTimerFunc( 1000/60, timer, 1000/60 );
//glutTimerFunc( 1000/60, timer, 1000/60 ); // not working on some systems (bug in GLUT)
glutIdleFunc(display);
GLenum err = glewInit();
if (GLEW_OK != err)
......
......@@ -42,10 +42,7 @@
#include <Glut/glut.h>
#elif defined(_WIN32) || defined(_WIN64)
#include <GLUT/glut.h>
// Round and INFINITY only defined in C99
double round(double r) {
return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}
// INFINITY only defined in C99
#define INFINITY 99999999999
#else
#include <GL/glut.h>
......
......@@ -38,10 +38,12 @@
#include <math.h>
double round (float v)
#if !defined(_MSC_VER) || _MSC_VER < 1800
double round (double v)
{
return floor(v+0.5f);
return (v > 0.0) ? floor(v + 0.5) : ceil(v - 0.5);
}
#endif // _MSC_VER < 1800
// strndup() is not available on Windows
char *strndup( const char *s1, size_t n)
......
......@@ -58,7 +58,9 @@ extern "C" {
#elif defined(_WIN32) || defined(_WIN64)
/* does not exist on windows */
char * strndup( const char *s1, size_t n);
double round (float v);
# if !defined(_MSC_VER) || _MSC_VER < 1800
double round(double v);
# endif // _MSC_VER
# pragma warning (disable: 4244) // suspend warnings
#endif // _WIN32 || _WIN64
......
......@@ -34,7 +34,7 @@ uniform sampler2D texture;
void main(void)
{
vec4 color = texture2D(texture, gl_TexCoord[0].st);
float dist = color.a;
float dist = color.r;
float width = fwidth(dist);
float alpha = smoothstep(0.5-width, 0.5+width, dist);
gl_FragColor = vec4(gl_Color.rgb, alpha*gl_Color.a);
......
......@@ -34,7 +34,7 @@ uniform sampler2D texture;
void main(void)
{
vec3 color = vec3(0.0,0.0,0.0);
float dist = texture2D(texture, gl_TexCoord[0].st).a;
float dist = texture2D(texture, gl_TexCoord[0].st).r;
float width = fwidth(dist);
float alpha = smoothstep(0.5-width, 0.5+width, dist);
gl_FragColor = vec4(color, alpha);
......
......@@ -40,7 +40,7 @@ const float glow_center = 1.25;
void main(void)
{
vec4 color = texture2D(texture, gl_TexCoord[0].st);
float dist = color.a;
float dist = color.r;
float width = fwidth(dist);
float alpha = smoothstep(glyph_center-width, glyph_center+width, dist);
......
......@@ -91,7 +91,7 @@ void main()
// LCD Off
if( pixel.z == 1.0)
{
float a = texture2D(texture, uv).a;
float a = texture2D(texture, uv).r;
gl_FragColor = gl_Color * pow( a, 1.0/vgamma );
return;
}
......
......@@ -33,6 +33,6 @@
uniform sampler2D texture;
void main()
{
float a = texture2D(texture, gl_TexCoord[0].xy).a;
float a = texture2D(texture, gl_TexCoord[0].xy).r;
gl_FragColor = vec4(gl_Color.rgb, gl_Color.a*a);
}
......@@ -338,8 +338,8 @@ texture_atlas_upload( texture_atlas_t * self )
}
else
{
glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, self->width, self->height,
0, GL_ALPHA, GL_UNSIGNED_BYTE, self->data );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RED, self->width, self->height,
0, GL_RED, GL_UNSIGNED_BYTE, self->data );
}
}
......@@ -370,9 +370,6 @@ texture_font_load_glyphs( texture_font_t * self,
for( i=0; i<wcslen(charcodes); ++i )
{
FT_Int32 flags = 0;
int ft_bitmap_width = 0;
int ft_bitmap_rows = 0;
int ft_bitmap_pitch = 0;
int ft_glyph_top = 0;
int ft_glyph_left = 0;
glyph_index = FT_Get_Char_Index( face, charcodes[i] );
......@@ -422,9 +419,6 @@ texture_font_load_glyphs( texture_font_t * self,
{
slot = face->glyph;
ft_bitmap = slot->bitmap;
ft_bitmap_width = slot->bitmap.width;
ft_bitmap_rows = slot->bitmap.rows;
ft_bitmap_pitch = slot->bitmap.pitch;
ft_glyph_top = slot->bitmap_top;
ft_glyph_left = slot->bitmap_left;
}
......@@ -508,9 +502,6 @@ texture_font_load_glyphs( texture_font_t * self,
}
ft_bitmap_glyph = (FT_BitmapGlyph) ft_glyph;
ft_bitmap = ft_bitmap_glyph->bitmap;
ft_bitmap_width = ft_bitmap.width;
ft_bitmap_rows = ft_bitmap.rows;
ft_bitmap_pitch = ft_bitmap.pitch;
ft_glyph_top = ft_bitmap_glyph->top;
ft_glyph_left = ft_bitmap_glyph->left;
FT_Stroker_Done(stroker);
......@@ -519,8 +510,8 @@ texture_font_load_glyphs( texture_font_t * self,
// We want each glyph to be separated by at least one black pixel
// (for example for shader used in demo-subpixel.c)
w = ft_bitmap_width/depth + 1;
h = ft_bitmap_rows + 1;
w = ft_bitmap.width/depth + 1;
h = ft_bitmap.rows + 1;
region = texture_atlas_get_region( self->atlas, w, h );
if ( region.x < 0 )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment