From 86d9c85c7eead64eb56f81f85996e61be6bab55f Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 14 Sep 2017 21:13:02 -0500 Subject: [PATCH] in progress reverting to SDL1.2 for pi compatibility, adding sdl_gfx Former-commit-id: 496ef51b135330911afed2719564b90e6e039c89 Former-commit-id: 85a5e21f8bf4a7bdc0ade370a0872bc2fbc9b59b --- sdl1090/Makefile | 2 +- sdl1090/defs.h | 4 ++-- sdl1090/draw.c | 22 +++++++++++++--------- sdl1090/font.c | 26 +++++++++++++------------- sdl1090/init.c | 16 +++++++--------- sdl1090/interactive.c | 7 +++---- sdl1090/structs.h | 3 +-- sdl1090/view1090.REMOVED.git-id | 2 +- sdl1090/view1090.c | 15 +-------------- 9 files changed, 42 insertions(+), 55 deletions(-) diff --git a/sdl1090/Makefile b/sdl1090/Makefile index 4da4694..3560a07 100644 --- a/sdl1090/Makefile +++ b/sdl1090/Makefile @@ -11,7 +11,7 @@ EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\" endif CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr` -LIBS=`pkg-config --libs librtlsdr` -lpthread -lm `sdl2-config --libs` -lSDL2 -lSDL2_ttf +LIBS=`pkg-config --libs librtlsdr` -lpthread -lm `sdl-config --libs` -lSDL -lSDL_ttf -lSDL_gfx CC=gcc diff --git a/sdl1090/defs.h b/sdl1090/defs.h index 0bb1727..f9f1677 100644 --- a/sdl1090/defs.h +++ b/sdl1090/defs.h @@ -1,8 +1,8 @@ #include #include #include -#include "SDL2/SDL.h" -#include "SDL2/SDL_ttf.h" +#include "SDL/SDL.h" +#include "SDL/SDL_ttf.h" #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 diff --git a/sdl1090/draw.c b/sdl1090/draw.c index 26c6113..964d5df 100644 --- a/sdl1090/draw.c +++ b/sdl1090/draw.c @@ -1,6 +1,7 @@ #include "dump1090.h" #include "draw.h" #include "parula.h" +#include "SDL/SDL_gfxPrimitives.h" extern void drawString(char *, int, int, TTF_Font *, SDL_Color); @@ -11,18 +12,19 @@ void CROSSVP(double *v, double *u, double *w) v[2] = u[0]*w[1] - u[1]*(w)[0]; } - +/* SDL_Point screenCoords(double dx, double dy) { SDL_Point out; out.x = round(320.0 * (0.5 + (dx / 64.0))); out.y = round(240.0 * (0.5 + (dy / 48.0))); - return out; + return out; } +*/ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *flight) { - + /* SDL_Point center = screenCoords(dx,dy); if(center.x < 0 || center.x >= 320 || center.y < 0 || center.y >= 240 ) { @@ -87,11 +89,12 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl SDL_Color color = { 200, 200, 200 , 255}; drawString(flight, center.x + 10, center.y + 10, game.font, color); } + */ } void drawPlane(double dx, double dy, int signal) { - +/* SDL_Point center = screenCoords(dx,dy); if(center.x < 0 || center.x >= 320 || center.y < 0 || center.y >= 240 ) { @@ -112,9 +115,12 @@ void drawPlane(double dx, double dy, int signal) SDL_RenderDrawLine(game.renderer, center.x-length , center.y , center.x+length , center.y ); SDL_RenderDrawLine(game.renderer, center.x , center.y-length , center.x , center.y+length ); + */ } void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) { + + /* int currentIdx, prevIdx; SDL_Point current, prev; @@ -163,16 +169,14 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) { // SDL_Rect spot = {.x = current.x-1, .y = current.y-1, .w = 2, .h = 2}; // SDL_RenderFillRect(game.renderer, &spot); - } + }*/ } void drawGrid() { - SDL_SetRenderDrawColor(game.renderer, 40, 40, 40, SDL_ALPHA_OPAQUE); - - SDL_RenderDrawLine(game.renderer, 0, 120, 320, 120); - SDL_RenderDrawLine(game.renderer, 160, 0, 160, 240); + hlineRGBA (game.screen, 0, 320, 120, 40, 40, 40, SDL_ALPHA_OPAQUE); + vlineRGBA (game.screen, 160, 0, 240, 40, 40, 40, SDL_ALPHA_OPAQUE); } diff --git a/sdl1090/font.c b/sdl1090/font.c index 1fd551d..46625a7 100755 --- a/sdl1090/font.c +++ b/sdl1090/font.c @@ -29,27 +29,27 @@ void closeFont(TTF_Font *font) void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color) { SDL_Surface *surface; - - // surface = TTF_RenderUTF8_Shaded(font, text, foregroundColor, backgroundColor); - surface = TTF_RenderText_Solid(font, text, color); + SDL_Rect dest; + + surface = TTF_RenderUTF8_Solid(font, text, color); if (surface == NULL) { - printf("Couldn't create String: %s\n", SDL_GetError()); + printf("Couldn't create String %s: %s\n", text, SDL_GetError()); return; } + + /* Blit the entire surface to the screen */ - SDL_Texture* Message = SDL_CreateTextureFromSurface(game.renderer, surface); //now you can convert it into a texture - - SDL_Rect Message_rect; //create a rect - Message_rect.x = x; //controls the rect's x coordinate - Message_rect.y = y; // controls the rect's y coordinte - Message_rect.w = surface->w; // controls the width of the rect - Message_rect.h = surface->h; // controls the height of the rect - - SDL_RenderCopy(game.renderer, Message, NULL, &Message_rect); //you put the renderer's name first, the Message, the crop size(you can ignore this if you don't want to dabble with cropping), and the rect which is the size and coordinate of your texture + dest.x = x; + dest.y = y; + dest.w = surface->w; + dest.h = surface->h; + SDL_BlitSurface(surface, NULL, game.screen, &dest); + + /* Free the generated string image */ SDL_FreeSurface(surface); diff --git a/sdl1090/init.c b/sdl1090/init.c index 00884da..463b37f 100644 --- a/sdl1090/init.c +++ b/sdl1090/init.c @@ -7,7 +7,7 @@ void init(char *title) { /* Initialise SDL */ - if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_EVENTS) < 0) + if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Could not initialize SDL: %s\n", SDL_GetError()); @@ -24,16 +24,18 @@ void init(char *title) } - if (SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, 0, &(game.window), &(game.renderer)) < 0) - { - printf("Couldn't initialize Renderer: %s\n", SDL_GetError()); + game.screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_HWPALETTE|SDL_DOUBLEBUF); + + if (game.screen == NULL) + { + printf("Couldn't set screen mode to %d x %d: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError()); exit(1); } /* Set the screen title */ - SDL_SetWindowTitle(game.window,title); + SDL_WM_SetCaption(title, NULL); } void cleanup() @@ -46,10 +48,6 @@ void cleanup() TTF_Quit(); - - SDL_DestroyWindow(game.window); - - /* Shut down SDL */ SDL_Quit(); diff --git a/sdl1090/interactive.c b/sdl1090/interactive.c index 5c91358..ee2e430 100644 --- a/sdl1090/interactive.c +++ b/sdl1090/interactive.c @@ -472,8 +472,8 @@ void interactiveShowData(void) { } printf( "-------------------------------------------------------------------------------\n"); - SDL_SetRenderDrawColor(game.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); - SDL_RenderClear(game.renderer); + SDL_FillRect(game.screen, NULL, 0); + drawGrid(); while(a && (count < Modes.interactive_rows)) { @@ -573,8 +573,7 @@ void interactiveShowData(void) { a = a->next; } - SDL_RenderPresent(game.renderer); - + SDL_Flip(game.screen); } // //========================================================================= diff --git a/sdl1090/structs.h b/sdl1090/structs.h index b3624ad..f66fce9 100644 --- a/sdl1090/structs.h +++ b/sdl1090/structs.h @@ -2,7 +2,6 @@ typedef struct Game { - SDL_Window *window; - SDL_Renderer *renderer; + SDL_Surface *screen; TTF_Font *font; } Game; diff --git a/sdl1090/view1090.REMOVED.git-id b/sdl1090/view1090.REMOVED.git-id index 060d7c5..f866507 100644 --- a/sdl1090/view1090.REMOVED.git-id +++ b/sdl1090/view1090.REMOVED.git-id @@ -1 +1 @@ -a6a9a37e655d982e0f80b7465ae153997cf598a3 \ No newline at end of file +16533af5cceadbea2c10e6425e91d0560cabdbd8 \ No newline at end of file diff --git a/sdl1090/view1090.c b/sdl1090/view1090.c index 60e10d5..bceef72 100644 --- a/sdl1090/view1090.c +++ b/sdl1090/view1090.c @@ -238,15 +238,6 @@ void showCopyright(void) { // -int SDLCALL watch(void *userdata, SDL_Event* event) { - - if (event->type == SDL_APP_WILLENTERBACKGROUND) { - go = 0; - } - - return 1; -} - int main(int argc, char **argv) { @@ -345,7 +336,7 @@ int main(int argc, char **argv) { /* Start up SDL */ - init("Parallel Realities Tutorial 7"); + init("sdl1090"); /* Call the cleanup function when the program exits */ @@ -358,10 +349,6 @@ int main(int argc, char **argv) { game.font = loadFont("Arial.ttf", 10); - /* Loop indefinitely for messages */ - - - SDL_AddEventWatch(watch, NULL); while (go == 1)