in progress reverting to SDL1.2 for pi compatibility, adding sdl_gfx

Former-commit-id: 40831fe91c60533d31957aaaaeec18bde028228a
Former-commit-id: 646e410a0d38835d5d43dba6039e9797a0584cb8
This commit is contained in:
Nathan 2017-09-14 21:13:02 -05:00
parent 5d11256a6a
commit 8fb50efe7b
9 changed files with 42 additions and 55 deletions

View file

@ -11,7 +11,7 @@ EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\"
endif endif
CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr` 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 CC=gcc

View file

@ -1,8 +1,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "SDL2/SDL.h" #include "SDL/SDL.h"
#include "SDL2/SDL_ttf.h" #include "SDL/SDL_ttf.h"
#define SCREEN_WIDTH 320 #define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240 #define SCREEN_HEIGHT 240

View file

@ -1,6 +1,7 @@
#include "dump1090.h" #include "dump1090.h"
#include "draw.h" #include "draw.h"
#include "parula.h" #include "parula.h"
#include "SDL/SDL_gfxPrimitives.h"
extern void drawString(char *, int, int, TTF_Font *, SDL_Color); 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]; v[2] = u[0]*w[1] - u[1]*(w)[0];
} }
/*
SDL_Point screenCoords(double dx, double dy) { SDL_Point screenCoords(double dx, double dy) {
SDL_Point out; SDL_Point out;
out.x = round(320.0 * (0.5 + (dx / 64.0))); out.x = round(320.0 * (0.5 + (dx / 64.0)));
out.y = round(240.0 * (0.5 + (dy / 48.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) void drawPlaneHeading(double dx, double dy, double heading, int signal, char *flight)
{ {
/*
SDL_Point center = screenCoords(dx,dy); SDL_Point center = screenCoords(dx,dy);
if(center.x < 0 || center.x >= 320 || center.y < 0 || center.y >= 240 ) { 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}; SDL_Color color = { 200, 200, 200 , 255};
drawString(flight, center.x + 10, center.y + 10, game.font, color); drawString(flight, center.x + 10, center.y + 10, game.font, color);
} }
*/
} }
void drawPlane(double dx, double dy, int signal) void drawPlane(double dx, double dy, int signal)
{ {
/*
SDL_Point center = screenCoords(dx,dy); SDL_Point center = screenCoords(dx,dy);
if(center.x < 0 || center.x >= 320 || center.y < 0 || center.y >= 240 ) { 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-length , center.y , center.x+length , center.y );
SDL_RenderDrawLine(game.renderer, center.x , center.y-length , center.x , center.y+length ); 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) { void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
/*
int currentIdx, prevIdx; int currentIdx, prevIdx;
SDL_Point current, prev; 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_Rect spot = {.x = current.x-1, .y = current.y-1, .w = 2, .h = 2};
// SDL_RenderFillRect(game.renderer, &spot); // SDL_RenderFillRect(game.renderer, &spot);
} }*/
} }
void drawGrid() void drawGrid()
{ {
SDL_SetRenderDrawColor(game.renderer, 40, 40, 40, SDL_ALPHA_OPAQUE); hlineRGBA (game.screen, 0, 320, 120, 40, 40, 40, SDL_ALPHA_OPAQUE);
vlineRGBA (game.screen, 160, 0, 240, 40, 40, 40, SDL_ALPHA_OPAQUE);
SDL_RenderDrawLine(game.renderer, 0, 120, 320, 120);
SDL_RenderDrawLine(game.renderer, 160, 0, 160, 240);
} }

View file

@ -29,27 +29,27 @@ void closeFont(TTF_Font *font)
void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color) void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color)
{ {
SDL_Surface *surface; SDL_Surface *surface;
SDL_Rect dest;
// surface = TTF_RenderUTF8_Shaded(font, text, foregroundColor, backgroundColor);
surface = TTF_RenderText_Solid(font, text, color); surface = TTF_RenderUTF8_Solid(font, text, color);
if (surface == NULL) if (surface == NULL)
{ {
printf("Couldn't create String: %s\n", SDL_GetError()); printf("Couldn't create String %s: %s\n", text, SDL_GetError());
return; return;
} }
/* Blit the entire surface to the screen */
SDL_Texture* Message = SDL_CreateTextureFromSurface(game.renderer, surface); //now you can convert it into a texture dest.x = x;
dest.y = y;
SDL_Rect Message_rect; //create a rect dest.w = surface->w;
Message_rect.x = x; //controls the rect's x coordinate dest.h = surface->h;
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
SDL_BlitSurface(surface, NULL, game.screen, &dest);
/* Free the generated string image */
SDL_FreeSurface(surface); SDL_FreeSurface(surface);

View file

@ -7,7 +7,7 @@ void init(char *title)
{ {
/* Initialise SDL */ /* 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()); 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) game.screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_HWPALETTE|SDL_DOUBLEBUF);
{
printf("Couldn't initialize Renderer: %s\n", SDL_GetError()); if (game.screen == NULL)
{
printf("Couldn't set screen mode to %d x %d: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError());
exit(1); exit(1);
} }
/* Set the screen title */ /* Set the screen title */
SDL_SetWindowTitle(game.window,title); SDL_WM_SetCaption(title, NULL);
} }
void cleanup() void cleanup()
@ -46,10 +48,6 @@ void cleanup()
TTF_Quit(); TTF_Quit();
SDL_DestroyWindow(game.window);
/* Shut down SDL */ /* Shut down SDL */
SDL_Quit(); SDL_Quit();

View file

@ -472,8 +472,8 @@ void interactiveShowData(void) {
} }
printf( printf(
"-------------------------------------------------------------------------------\n"); "-------------------------------------------------------------------------------\n");
SDL_SetRenderDrawColor(game.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); SDL_FillRect(game.screen, NULL, 0);
SDL_RenderClear(game.renderer);
drawGrid(); drawGrid();
while(a && (count < Modes.interactive_rows)) { while(a && (count < Modes.interactive_rows)) {
@ -573,8 +573,7 @@ void interactiveShowData(void) {
a = a->next; a = a->next;
} }
SDL_RenderPresent(game.renderer); SDL_Flip(game.screen);
} }
// //
//========================================================================= //=========================================================================

View file

@ -2,7 +2,6 @@
typedef struct Game typedef struct Game
{ {
SDL_Window *window; SDL_Surface *screen;
SDL_Renderer *renderer;
TTF_Font *font; TTF_Font *font;
} Game; } Game;

View file

@ -1 +1 @@
a6a9a37e655d982e0f80b7465ae153997cf598a3 16533af5cceadbea2c10e6425e91d0560cabdbd8

View file

@ -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) { int main(int argc, char **argv) {
@ -345,7 +336,7 @@ int main(int argc, char **argv) {
/* Start up SDL */ /* Start up SDL */
init("Parallel Realities Tutorial 7"); init("sdl1090");
/* Call the cleanup function when the program exits */ /* Call the cleanup function when the program exits */
@ -358,10 +349,6 @@ int main(int argc, char **argv) {
game.font = loadFont("Arial.ttf", 10); game.font = loadFont("Arial.ttf", 10);
/* Loop indefinitely for messages */
SDL_AddEventWatch(watch, NULL);
while (go == 1) while (go == 1)