From: arif Date: Tue, 28 Oct 2008 01:02:36 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: LAST_LIBGRAPH~32^2~2947 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54565e335c744b88100da54a1bba61d9e0568ec9;p=graphviz *** empty log message *** --- diff --git a/cmd/smyrna/glexpose.c b/cmd/smyrna/glexpose.c index 04539f889..a1cab0998 100644 --- a/cmd/smyrna/glexpose.c +++ b/cmd/smyrna/glexpose.c @@ -19,6 +19,10 @@ #include "glutils.h" #include "topview.h" #include "topfisheyeview.h" +#include "glTexFont.h" + +extern texFont_t font; + /* @@ -89,6 +93,7 @@ int glexpose_main(ViewInfo * view) draw_selection_box(view); drawBorders(view); drawRotatingTools(); + drawtestpoly(); /*DEBUG*/ /* if (view->mouse.mouse_mode == MM_PAN) { @@ -114,6 +119,23 @@ int glexpose_main(ViewInfo * view) 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 diff --git a/cmd/smyrna/glexpose.h b/cmd/smyrna/glexpose.h index f946285a0..ff7790e04 100644 --- a/cmd/smyrna/glexpose.h +++ b/cmd/smyrna/glexpose.h @@ -22,5 +22,7 @@ int glexpose_main(ViewInfo * v); void glexpose_grid(ViewInfo * v); int glexpose_drawgraph(ViewInfo * view); void drawRotatingTools(); +void drawtestpoly(); + #endif diff --git a/lib/glcomp/glTexFont.c b/lib/glcomp/glTexFont.c index 0f205f780..ff9206b65 100755 --- a/lib/glcomp/glTexFont.c +++ b/lib/glcomp/glTexFont.c @@ -65,7 +65,9 @@ int fontLoad (char *name) fontMakeMap (); - return fontLoadTGA (name, font.texId); +// return fontLoadTGA (name, font.texId); + return fontLoadPNG ("c:\\pango_test.png", font.texId); + } /* ============= @@ -97,7 +99,7 @@ fontDrawChar 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); @@ -108,20 +110,20 @@ void fontDrawChar (char c, int x, int y, int size, int shadow) 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 (); } /* @@ -238,11 +240,11 @@ fontSize 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; } @@ -276,13 +278,13 @@ Draws a character to the screen 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); } @@ -290,7 +292,7 @@ void fontRenderChar (char c, int x, int y, int size) fontDrawChar (c, x, y, size, 0); if (font.bold) - fontDrawChar (c, x + 1, y, size, 0); + fontDrawChar (c, x + 1.0, y, size, 0); } /* ============= @@ -300,7 +302,7 @@ Handles all the fun that comes with a \\, returns amount to advance string. 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; @@ -338,19 +340,19 @@ fontWalkString 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'); @@ -400,7 +402,7 @@ void fontWalkString (char *buffPtr, int xpos, int ypos, int *vPort,float width) } 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 @@ -458,7 +460,7 @@ fontDrawString 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'}; diff --git a/lib/glcomp/glTexFont.h b/lib/glcomp/glTexFont.h index b2cb0cf3a..c8a54aec4 100755 --- a/lib/glcomp/glTexFont.h +++ b/lib/glcomp/glTexFont.h @@ -15,6 +15,8 @@ #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 */ @@ -32,16 +34,16 @@ typedef struct 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 */ @@ -79,7 +81,7 @@ fontDrawString 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 @@ -96,7 +98,7 @@ fontSize Sets the font size. ============= */ -void fontSize (int size); +void fontSize (GLfloat size); void fontzdepth(float zdepth); diff --git a/lib/glcomp/glTexFontTGA.c b/lib/glcomp/glTexFontTGA.c index e014e40a4..d628b1c9b 100755 --- a/lib/glcomp/glTexFontTGA.c +++ b/lib/glcomp/glTexFontTGA.c @@ -20,6 +20,8 @@ #include "glTexFont.h" #include "glTexFontTGA.h" #include "glTexFontInclude.h" +#include + GLenum texFormat; @@ -233,4 +235,153 @@ fprintf(stderr,"font: %s\n", name); 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() +{ + +} diff --git a/lib/glcomp/glutils.c b/lib/glcomp/glutils.c index 48055e47d..749bf8210 100644 --- a/lib/glcomp/glutils.c +++ b/lib/glcomp/glutils.c @@ -135,7 +135,7 @@ float GetOGLDistance(int l) 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,