cnping

Minimal Graphical Ping Tool
git clone https://git.sinitax.com/cnlohr/cnping
Log | Files | Refs | Submodules | README | LICENSE | sfeed.txt

commit d67c304b3245f535b09214282e004f77cee125d6
parent 56639b4cc4c9f10e880624ff6d8ed124672d1113
Author: cnlohr <lohr85@gmail.com>
Date:   Tue,  4 Apr 2017 20:26:01 -0400

Update to newer CNPING

Diffstat:
MCNFGFunctions.c | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MCNFGFunctions.h | 7++++++-
MCNFGWinDriver.c | 71++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
MCNFGXDriver.c | 74+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Mcnping-mousey.c | 2+-
Dcnping.exe | 0
6 files changed, 222 insertions(+), 14 deletions(-)

diff --git a/CNFGFunctions.c b/CNFGFunctions.c @@ -270,3 +270,85 @@ void CNFGDrawTextbox( int x, int y, const char * text, int textsize ) CNFGPenY = y + textsize; CNFGDrawText( text, textsize ); } + + +#ifdef CNFGOGL + +#include <GL/gl.h> + +uint32_t CNFGColor( uint32_t RGB ) +{ + unsigned char red = RGB & 0xFF; + unsigned char grn = ( RGB >> 8 ) & 0xFF; + unsigned char blu = ( RGB >> 16 ) & 0xFF; + glColor3ub( red, grn, blu ); +} + +void CNFGClearFrame() +{ + short w, h; + unsigned char red = CNFGBGColor & 0xFF; + unsigned char grn = ( CNFGBGColor >> 8 ) & 0xFF; + unsigned char blu = ( CNFGBGColor >> 16 ) & 0xFF; + glClearColor( red/255.0, grn/255.0, blu/255.0, 1.0 ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + CNFGGetDimensions( &w, &h ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glViewport( 0, 0, w, h ); + glOrtho( 0, w, h, 0, 1, -1 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); +} + + +void CNFGTackSegment( short x1, short y1, short x2, short y2 ) +{ + if( x1 == x2 && y1 == y2 ) + { + glBegin( GL_POINTS ); + glVertex2f( x1+.5, y1+.5 ); + glEnd(); + } + else + { + glBegin( GL_LINES ); + glVertex2f( x1+.5, y1+.5 ); + glVertex2f( x2+.5, y2+.5 ); + glEnd(); + } +} + +void CNFGTackPixel( short x1, short y1 ) +{ + glBegin( GL_POINTS ); + glVertex2f( x1, y1 ); + glEnd(); +} + +void CNFGTackRectangle( short x1, short y1, short x2, short y2 ) +{ + glBegin( GL_QUADS ); + glVertex2f( x1, y1 ); + glVertex2f( x2, y1 ); + glVertex2f( x2, y2 ); + glVertex2f( x1, y2 ); + glEnd(); +} + +void CNFGTackPoly( RDPoint * points, int verts ) +{ + int i; + glBegin( GL_TRIANGLE_FAN ); + glVertex2f( points[0].x, points[0].y ); + for( i = 1; i < verts; i++ ) + { + glVertex2f( points[i].x, points[i].y ); + } + glEnd(); +} + +void CNFGInternalResize( short x, short y ) { } + + +#endif diff --git a/CNFGFunctions.h b/CNFGFunctions.h @@ -1,4 +1,4 @@ -//Copyright (c) 2011 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose. +//Copyright (c) 2011, 2017 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose. #ifndef _DRAWFUCNTIONS_H #define _DRAWFUCNTIONS_H @@ -49,6 +49,11 @@ void HandleDestroy(); //Internal function for resizing rasterizer for rasterizer-mode. void CNFGInternalResize( short x, short y ); //don't call this. +//Not available on all systems. Use The OGL portion with care. +#ifdef CNFGOGL +void CNFGSetVSync( int vson ); +void * CNFGGetExtension( const char * extname ); +#endif #ifdef __cplusplus }; diff --git a/CNFGWinDriver.c b/CNFGWinDriver.c @@ -13,7 +13,6 @@ static HWND lsHWND; static HDC lsWindowHDC; static HDC lsHDC; - #ifdef RASTERIZER #include "CNFGRasterizer.h" @@ -32,14 +31,34 @@ static void InternalHandleResize(); #endif +#ifdef CNFGOGL +#include <GL/gl.h> +static HGLRC hRC=NULL; +static void InternalHandleResize() { } +void CNFGSwapBuffers() +{ + SwapBuffers(lsWindowHDC); +} +#endif + void CNFGGetDimensions( short * x, short * y ) { + static int lastx, lasty; + RECT window; + GetClientRect( lsHWND, &window ); + bufferx = ( window.right - window.left); + buffery = ( window.bottom - window.top); + if( bufferx != lastx || buffery != lasty ) + { + lastx = bufferx; + lasty = buffery; + InternalHandleResize(); + } *x = bufferx; *y = buffery; } - void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h ) { RECT r; @@ -126,9 +145,49 @@ void CNFGSetup( const char * name_of_window, int width, int height ) hInstance, NULL); //no parameters to pass - lsWindowHDC = GetDC( lsHWND ); +#ifdef CNFGOGL + //From NeHe + static PIXELFORMATDESCRIPTOR pfd = + { + sizeof(PIXELFORMATDESCRIPTOR), + 1, + PFD_DRAW_TO_WINDOW | + PFD_SUPPORT_OPENGL | + PFD_DOUBLEBUFFER, + PFD_TYPE_RGBA, + 32, + 0, 0, 0, 0, 0, 0, + 0, + 0, + 0, + 0, 0, 0, 0, + 16, + 0, + 0, + PFD_MAIN_PLANE, + 0, + 0, 0, 0 + }; + GLuint PixelFormat = ChoosePixelFormat( lsWindowHDC, &pfd ); + if( !SetPixelFormat( lsWindowHDC, PixelFormat, &pfd ) ) + { + MessageBox( 0, "Could not create PFD for OpenGL Context\n", 0, 0 ); + exit( -1 ); + } + if (!(hRC=wglCreateContext(lsWindowHDC))) // Are We Able To Get A Rendering Context? + { + MessageBox( 0, "Could not create OpenGL Context\n", 0, 0 ); + exit( -1 ); + } + if(!wglMakeCurrent(lsWindowHDC,hRC)) // Try To Activate The Rendering Context + { + MessageBox( 0, "Could not current OpenGL Context\n", 0, 0 ); + exit( -1 ); + } +#endif + lsHDC = CreateCompatibleDC( lsWindowHDC ); lsBitmap = CreateCompatibleBitmap( lsWindowHDC, bufferx, buffery ); SelectObject( lsHDC, lsBitmap ); @@ -182,6 +241,7 @@ void CNFGHandleInput() } } +#ifndef CNFGOGL #ifndef RASTERIZER @@ -237,8 +297,7 @@ void CNFGClearFrame() DeleteObject( lsClearBrush ); lsClearBrush = CreateSolidBrush( CNFGBGColor ); SelectObject( lsHDC, lsClearBrush ); - - FillRect( lsHDC, &r, lsClearBrush ); + FillRect( lsHDC, &r, lsClearBrush); } void CNFGTackPoly( RDPoint * points, int verts ) @@ -287,3 +346,5 @@ void CNFGSwapBuffers() void CNFGInternalResize( short bufferx, short buffery ) { } #endif +#endif + diff --git a/CNFGXDriver.c b/CNFGXDriver.c @@ -1,4 +1,4 @@ -//Copyright (c) 2011 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose. +//Copyright (c) 2011, 2017 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose. //portions from //http://www.xmission.com/~georgeps/documentation/tutorials/Xlib_Beginner.html @@ -25,6 +25,17 @@ Window CNFGWindow; Pixmap CNFGPixmap; GC CNFGGC; GC CNFGWindowGC; +Visual * CNFGVisual; + + +#ifdef CNFGOGL +#include <GL/glx.h> +#include <GL/glxext.h> + +GLXContext CNFGCtx; +void * CNFGGetExtension( const char * extname ) { return glXGetProcAddressARB((const GLubyte *) extname); } +#endif + int FullScreen = 0; void CNFGGetDimensions( short * x, short * y ) @@ -86,7 +97,7 @@ void CNFGSetupFullscreen( const char * WindowName, int screen_no ) exit( 1 ); } - Visual * visual = DefaultVisual(CNFGDisplay, screen); + CNFGVisual = DefaultVisual(CNFGDisplay, screen); CNFGWinAtt.depth = DefaultDepth(CNFGDisplay, screen); if (XineramaQueryExtension(CNFGDisplay, &a, &b ) && @@ -117,7 +128,9 @@ void CNFGSetupFullscreen( const char * WindowName, int screen_no ) CNFGWindow = XCreateWindow(CNFGDisplay, XRootWindow(CNFGDisplay, screen), xpos, ypos, CNFGWinAtt.width, CNFGWinAtt.height, - 0, CNFGWinAtt.depth, InputOutput, visual, CWBorderPixel | CWEventMask | CWOverrideRedirect | CWSaveUnder, &setwinattr); + 0, CNFGWinAtt.depth, InputOutput, CNFGVisual, + CWBorderPixel | CWEventMask | CWOverrideRedirect | CWSaveUnder, + &setwinattr); XMapWindow(CNFGDisplay, CNFGWindow); XSetInputFocus( CNFGDisplay, CNFGWindow, RevertToParent, CurrentTime ); @@ -155,7 +168,31 @@ void CNFGSetup( const char * WindowName, int w, int h ) XGetWindowAttributes( CNFGDisplay, RootWindow(CNFGDisplay, 0), &CNFGWinAtt ); int depth = CNFGWinAtt.depth; - CNFGWindow = XCreateWindow(CNFGDisplay, RootWindow(CNFGDisplay, 0), 1, 1, w, h, 0, depth, InputOutput, CopyFromParent, 0, 0 ); + int screen = DefaultScreen(CNFGDisplay); + CNFGVisual = DefaultVisual(CNFGDisplay, screen); + +#ifdef CNFGOGL + int attribs[] = { GLX_RGBA, + GLX_DOUBLEBUFFER, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 1, + None }; + XVisualInfo * vis = glXChooseVisual(CNFGDisplay, screen, attribs); + CNFGVisual = vis->visual; + depth = vis->depth; + CNFGCtx = glXCreateContext( CNFGDisplay, vis, NULL, True ); +#endif + + XSetWindowAttributes attr; + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( CNFGDisplay, RootWindow(CNFGDisplay, 0), CNFGVisual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + int mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + CNFGWindow = XCreateWindow(CNFGDisplay, RootWindow(CNFGDisplay, 0), 1, 1, w, h, 0, depth, InputOutput, CNFGVisual, mask, &attr ); XMapWindow(CNFGDisplay, CNFGWindow); XFlush(CNFGDisplay); @@ -163,7 +200,12 @@ void CNFGSetup( const char * WindowName, int w, int h ) Atom WM_DELETE_WINDOW = XInternAtom( CNFGDisplay, "WM_DELETE_WINDOW", False ); XSetWMProtocols( CNFGDisplay, CNFGWindow, &WM_DELETE_WINDOW, 1 ); + XSelectInput( CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask ); + +#ifdef CNFGOGL + glXMakeCurrent( CNFGDisplay, CNFGWindow, CNFGCtx ); +#endif } void CNFGHandleInput() @@ -226,7 +268,6 @@ void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h ) if( !xi ) { int screen = DefaultScreen(CNFGDisplay); - Visual * visual = DefaultVisual(CNFGDisplay, screen); depth = DefaultDepth(CNFGDisplay, screen)/8; // xi = XCreateImage(CNFGDisplay, DefaultVisual( CNFGDisplay, DefaultScreen(CNFGDisplay) ), depth*8, ZPixmap, 0, (char*)data, w, h, 32, w*4 ); // lw = w; @@ -236,7 +277,7 @@ void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h ) if( lw != w || lh != h ) { if( xi ) free( xi ); - xi = XCreateImage(CNFGDisplay, DefaultVisual( CNFGDisplay, DefaultScreen(CNFGDisplay) ), depth*8, ZPixmap, 0, (char*)data, w, h, 32, w*4 ); + xi = XCreateImage(CNFGDisplay, CNFGVisual, depth*8, ZPixmap, 0, (char*)data, w, h, 32, w*4 ); lw = w; lh = h; } @@ -247,7 +288,25 @@ void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h ) } -#ifndef RASTERIZER +#ifdef CNFGOGL + +void CNFGSetVSync( int vson ) +{ + void (*glfn)( int ); + glfn = (void (*)( int ))CNFGGetExtension( "glXSwapIntervalMESA" ); if( glfn ) glfn( vson ); + glfn = (void (*)( int ))CNFGGetExtension( "glXSwapIntervalSGI" ); if( glfn ) glfn( vson ); + glfn = (void (*)( int ))CNFGGetExtension( "glXSwapIntervalEXT" ); if( glfn ) glfn( vson ); +} + +void CNFGSwapBuffers() +{ + glFlush(); + glFinish(); + glXSwapBuffers( CNFGDisplay, CNFGWindow ); +} +#endif + +#if !defined( RASTERIZER ) && !defined( CNFGOGL) uint32_t CNFGColor( uint32_t RGB ) @@ -302,3 +361,4 @@ void CNFGInternalResize( short x, short y ) { } #include "CNFGRasterizer.h" #endif + diff --git a/cnping-mousey.c b/cnping-mousey.c @@ -15,7 +15,7 @@ #include <sys/select.h> #include <netdb.h> #endif -#include "DrawFunctions.h" +#include "CNFGFunctions.h" #include "os_generic.h" #include "ping.h" diff --git a/cnping.exe b/cnping.exe Binary files differ.