#include "glutils.h"
#include "topview.h"
#include "topfisheyeview.h"
+#include "glTexFont.h"
+
+extern texFont_t font;
+
/*
draw_selection_box(view);
drawBorders(view);
drawRotatingTools();
+ drawtestpoly();
/*DEBUG*/
/* if (view->mouse.mouse_mode == MM_PAN)
{
params:ViewInfo , global view variable defined in viewport.c
return value:none
*/
+void drawtestpoly()
+{
+ glEnable(GL_TEXTURE_2D);
+ glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE , GL_DECAL);
+ glBindTexture(GL_TEXTURE_2D,font.texId);
+ glColor3f(1,0,0);
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0.0,0.0);glVertex3f(0.0,0.0,0.0);
+ glTexCoord2f(0.0,1.0);glVertex3f(0.0,256.0,0.0);
+ glTexCoord2f(1.0,1.0);glVertex3f(256.0,256.0,0.0);
+ glTexCoord2f(1.0,0.0);glVertex3f(256.0,0.0,0.0);
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+
+}
+
void glexpose_grid(ViewInfo * view)
{
//drawing grids
void glexpose_grid(ViewInfo * v);
int glexpose_drawgraph(ViewInfo * view);
void drawRotatingTools();
+void drawtestpoly();
+
#endif
fontMakeMap ();
- return fontLoadTGA (name, font.texId);
+// return fontLoadTGA (name, font.texId);
+ return fontLoadPNG ("c:\\pango_test.png", font.texId);
+
}
/*
=============
Draws a character that is 'size' pixels in w and h.
=============
*/
-void fontDrawChar (char c, int x, int y, int size, int shadow)
+void fontDrawChar (char c, GLfloat x, GLfloat y, GLfloat size, int shadow)
{
if (!font.gradient && !shadow)
glColor4fv (font.fgColor);
glBegin (GL_QUADS);
glTexCoord2f (tPoints[(int)c][0], tPoints[(int)c][1]);
- glVertex3i (x, y,0);
+ glVertex3f (x, y,0);
glTexCoord2f (tPoints[(int)c][0] + font.tIncX, tPoints[(int)c][1]);
- glVertex3i (x + size, y,0);
+ glVertex3f (x + size, y,0);
if (!shadow)
glColor4fv (font.fgColor);
else glColor4fv (font.bgColor);
glTexCoord2f (tPoints[(int)c][0] + font.tIncX, tPoints[(int)c][1] + font.tIncY);
- glVertex3i (x + size + font.italic, y + size,0);
+ glVertex3f (x + size + font.italic, y + size,0);
glTexCoord2f (tPoints[(int)c][0], tPoints[(int)c][1] + font.tIncY);
- glVertex3i (x + font.italic, y + size,0);
+ glVertex3f (x + font.italic, y + size,0);
glEnd ();
}
/*
Sets the font size.
=============
*/
-void fontSize (int size)
+void fontSize (GLfloat size)
{
font.size = size;
}
-void fontzdepth(float zdepth)
+void fontzdepth(GLfloat zdepth)
{
font.zdepth=zdepth;
}
Bold is just a hack, nothing special
=============
*/
-void fontRenderChar (char c, int x, int y, int size)
+void fontRenderChar (char c, GLfloat x, GLfloat y, GLfloat size)
{
if (font.shadow)
{
if (!font.bold)
- fontDrawChar (c, x + 1, y + 1, size, 1);
- else fontDrawChar (c, x + 2, y + 1, size, 1);
+ fontDrawChar (c, x + 1.0, y + 1.0, size, 1);
+ else fontDrawChar (c, x + 2.0, y + 1.0, size, 1);
}
fontDrawChar (c, x, y, size, 0);
if (font.bold)
- fontDrawChar (c, x + 1, y, size, 0);
+ fontDrawChar (c, x + 1.0, y, size, 0);
}
/*
=============
After this funtion *buffptr ++ will be the next character to draw or parse.
=============
*/
-int fontSlashParser (char *buffPtr, int *x, int *y)
+int fontSlashParser (char *buffPtr, GLfloat *x, GLfloat *y)
{
int ret = 0;
Does the actual rendering of our string.
=============
*/
-void fontWalkString (char *buffPtr, int xpos, int ypos, int *vPort,float width)
+void fontWalkString (char *buffPtr, GLfloat xpos, GLfloat ypos, int *vPort,float width)
{
- int size = font.size;
- int x = xpos;
- int y = ypos;
- int carrage = 0;
- int tabs = 0;
+ GLfloat size = font.size;
+ GLfloat x = xpos;
+ GLfloat y = ypos;
+ GLfloat carrage = 0;
+ GLfloat tabs = 0;
int len = strlen (buffPtr);
int xMax;
int charCount;
int maxcharCount;
char* tempC;
- int charGap;
+ GLfloat charGap;
xMax = vPort[0] + vPort[2];
carrage = fontGetCharHits (buffPtr, '\n');
}
if (charCount > maxcharCount)
maxcharCount=charCount;
- charGap=(int)(width / (float)maxcharCount);
+ charGap=(width / (float)maxcharCount);
for ( ; *buffPtr; *buffPtr ++, x += charGap) //size*0.7 is the distance between2 characters
Renders a string at xpos, ypos.
=============
*/
-void fontDrawString (int xpos, int ypos, char *s,int width,...)
+void fontDrawString (GLfloat xpos, GLfloat ypos, char *s,GLfloat width,...)
{
va_list msg;
char buffer[FONT_MAX_LEN] = {'\0'};
#ifndef __GLTEXFONTH__
#define __GLTEXFONTH__
+typedef float GLfloat;
+
/* Error Codes */
#define FONT_FILE_NOT_FOUND -13 /* file was not found */
#define FONT_BAD_IMAGE_TYPE -14 /* color mapped image or image is not uncompressed */
float fgColor[4]; /* foreground color, default white */
float gdColor[4]; /* gradient color, default gray */
float bgColor[4]; /* background color, default gray */
- int size; /* size of text, default 12 */
+ float size; /* size of text, default 12 */
int shadow; /* shadow text? default 0 */
int gradient; /* gradient? default 0 */
int italic; /* italic amount, defaul 0 */
int bold; /* bold text? */
int region; /* do we have a text region */
- int regionX; /* lower left x */
- int regionY; /* lower left y */
- int regionW; /* text region w */
- int regionH; /* text region h */
+ float regionX; /* lower left x */
+ float regionY; /* lower left y */
+ float regionW; /* text region w */
+ float regionH; /* text region h */
float tIncX; /* used for texture coords, x axis amount to move */
float tIncY; /* used for texture coords, y axis amount to move */
int blockRow; /* characters per row */
Draws a string at (xpos, ypos) in the applications window.
=============
*/
-void fontDrawString (int xpos, int ypos, char *s,int width,...);
+void fontDrawString (GLfloat xpos, GLfloat ypos, char *s,GLfloat width,...);
/*
=============
fontRegion
Sets the font size.
=============
*/
-void fontSize (int size);
+void fontSize (GLfloat size);
void fontzdepth(float zdepth);
#include "glTexFont.h"
#include "glTexFontTGA.h"
#include "glTexFontInclude.h"
+#include <png.h>
+
GLenum texFormat;
return 1;
}
+unsigned char *load_png_font(char* file_name,int *imageWidth,int *imageHeight)
+{
+ unsigned char *imageData = NULL;
+ unsigned char header[8];
+ int rowbytes,i,ii,c;
+
+ png_structp png_ptr;
+ png_infop info_ptr;
+ png_infop end_info;
+ png_bytepp row_pointers; //actual image data
+ int is_png=0;
+ FILE *fp = fopen(file_name, "rb");
+ if (!fp)
+ {
+ return 0;
+ }
+ fread(header, 1, 8, fp);
+ is_png = !png_sig_cmp(header, 0, 8);
+ if (!is_png)
+ {
+ return 1;
+ }
+ else
+ printf("file is a valid ping file \n");
+
+ png_ptr = png_create_read_struct
+ (PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
+ if (!png_ptr)
+ return -1;
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr,
+ (png_infopp)NULL, (png_infopp)NULL);
+ return -1;
+ }
+
+ end_info = png_create_info_struct(png_ptr);
+ if (!end_info)
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return -1;
+ }
+
+
+ png_init_io(png_ptr, fp);
+
+//If you had previously opened the file and read any of the signature from the beginning in order to see if this was a PNG file, you need to let libpng know that there are some bytes missing from the start of the file.
+
+ png_set_sig_bytes(png_ptr, 8);
+ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
+
+ row_pointers = png_malloc(png_ptr,
+ info_ptr->height*sizeof(png_bytepp));
+ row_pointers = png_get_rows(png_ptr, info_ptr);
+ *imageWidth=info_ptr->width;
+ *imageHeight=info_ptr->height;
+ texFormat = GL_ALPHA;
+ rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+/* for (i=0; i < info_ptr->height; i++)
+ row_pointers[i]=png_malloc(png_ptr,
+ info_ptr->width*info_ptr->width/2);*/
+ // png_set_rows(png_ptr, info_ptr, &row_pointers);
+ imageData=malloc(info_ptr->height*info_ptr->width);
+ c=0;
+ for (i=0; i < info_ptr->height; i++)
+ {
+ printf ("ROW:%i\n",i);
+ for (ii=0;ii < 1024; ii=ii+4)
+ {
+/* if ((row_pointers[i][ii+1] == 0) || (row_pointers[i][ii+1] == 255))
+ imageData[c]=0;
+ else*/
+ imageData[c]=row_pointers[255-i][ii];
+ c++;
+// printf ("(%i %i)",row_pointers[i][ii],row_pointers[i][ii+1]);
+ }
+ printf ("\n---------------\n");
+ }
+
+
+ return imageData;
+
+
+
+
+}
+
+
+/*#define imageWidth 256
+#define imageHeight 256
+static GLubyte imageData[imageWidth][imageHeight][4];*/
+
+int fontLoadPNG (char *name, int id)
+{
+ GLubyte *imageData = NULL;
+ int imageWidth,imageHeight,idx,idx2,c;
+
+// imageData = fontGetData (s, size, imageBits);
+ imageData =load_png_font(name,&imageWidth,&imageHeight);
+
+ c=0;
+ idx2=0;
+/* for (idx=0;idx < imageWidth*imageHeight+30000;idx=idx+1)
+ {
+ if (c!=imageData[idx])
+ {
+ c=imageData[idx];
+ printf ("%i) %i \n ",idx2,imageData[idx]);
+ }
+
+ idx2++;
+ c=((((idx&0x8)==0)^((idx2&0x8))==0))*255;
+ imageData[idx][idx2][0] = c;
+ imageData[idx][idx2][1] = c;
+ imageData[idx][idx2][2] = c;
+ imageData[idx][idx2][3] = 255;
+
+ }*/
+
+
+ /* no image data */
+ if (imageData == NULL)
+ return FONT_BAD_DATA;
+
+ glBindTexture (GL_TEXTURE_2D, id);
+ glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ /* glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ /* glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE , GL_DECAL);
+
+ glTexImage2D (GL_TEXTURE_2D, 0, texFormat, imageWidth, imageHeight, 0, texFormat, GL_UNSIGNED_BYTE, imageData);
+// glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
+
+ /* release data, its been uploaded */
+
+ return 1;
+}
+void naber()
+{
+
+}
winY = (float) viewport[3] - (float) y;
gluUnProject(winX, winY, wwinZ, modelview, projection, viewport,
&posXX, &posYY, &posZZ);
- return ((float) (posXX - posX));
+ return ((float) (posXX - posX));
}
int GetFixedOGLPoslocal(int x, int y, float kts, GLfloat * X, GLfloat * Y,