//
//  glFont.h
//  CGL
//
//  Created by kat on Sat Jun 15 2002.
//  Copyright (c) 2001 Katherine Tattersall. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>

#import <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>

#define max_chars 96

// for outline fonts, you can specify the maximum number of vertices here
// each vertex will produce 1 quad  if extrude:0
// each vertex will produce 6 quads otherwise
#define max_vertices		1000
#define vertex_array_size	(max_vertices*4)

// for outline fonts, you can specify the level of detail
// outlinehelp MUST be an integer
// it is recommended that if you wish to have less detail you instead use a smaller font size
// and simply increase the scale
#define outlinehelp 1

// for precision, this should be a multiple of 2
// xdiff and ydiff should probably be the same number
// smaller and larger x and y diffs will affect the size of the resulting letters
// but not the number of polygons in each
#define xdiff 0.015625
#define ydiff 0.015625

/*
    Apple does not provide for a bitmap font except with respect to glutBitmapFont
    glutBitmapFont does not provide many different fonts
    To compete with windows programs, we may want to use bitmap fonts, but with the above, we are limited
    Therefore, we create glBitmapFont
    glBitmapFont handles writing text to the open gl context
    glBitmapFont will create a Bitmap font with any font you can name as a font 
        as long as it can be used in both NSFont and CGContext
 */
@interface NSGLFont : NSObject {

    GLuint	base;
    
    NSFont	*font;
    
    unsigned char *	data      [max_chars];
    size_t		width     [max_chars];
    size_t		height    [max_chars];
    
    size_t		max_height;
    size_t		max_width;
    unsigned int        x_offset  [max_chars];
    
    unsigned int 	nVertices;
    float		vertex[vertex_array_size];
    
    bool		outline, textured, pixelFont;
}

// bitmapFont creates a font using bitmaps
// bitmapFonts are easy to work with, but the don't use antialiasing
-(id) 	bitmapFont: (NSString *)fontname 
        atSize:(int)size;
// pixmapFont creates a font like the bitmap font but uses glDrawPixels instead of glBitmap
// pixmapFonts are nicer the bitmapFonts because they include antialiasing, and you can use things like glPixelZoom
// however, pixmapFonts are harder to change colors
-(id)	pixmapFont: (NSString *)fontname
        atSize:(int)size;
// outlineFont is an extruded font
// outlineFonts can use a nearly infinite amount of polygons to create the outline font
// but this means they take longer to render and create than cheapOutlineFonts and non-extruded fonts
-(id) 	outlineFont: (NSString *)fontname 
        atSize:(int)size
        extrude:(float)z
        stepsize:(int)s;
// cheapOutlineFont is an extruded font
// cheapOutlineFonts often use fewer polygons than outlineFonts, but may not be very exact
-(id) 	cheapOutlineFont: (NSString *)fontname 
        atSize:(int)size 
        extrude:(float)z;
        
-(void) writeString: (NSString *)s;
-(void) drawLetter:(char) ch 
        context: (CGContextRef)cg_context 
        atx:(int)xpos 
        withFont:(const char *)fontname 
        atSize:(int)size;

-(void) convertBitmap: (int) number;
-(void) getVertices: (int) number;

-(bool) outline;
-(bool) textured;

-(void) setTextured: (bool) t;
-(int)  getHeight: (int) number atX: (int) x atY: (int) y;

@end

void glPrint( NSGLFont *f, float x, float y, const char *fmt, ... );
void glPrint3( NSGLFont *f, float x, float y, float z, const char *fmt, ... );


