Use a REAL preprocessor definition.
Pass it from the Makefile in variable DEF
Can change using `make DEF=REAL=X`
Also allowed changing bounds with arguments in main.
Probably not that useful. Might remove later.
Tried to make a tester that overlays a series of BMPs but
the RenderBMP -> ScreenShot approach only works once; subsequent attempts lead to entirely filled images.
ARCH := $(shell uname -m)
CXX = g++ -std=gnu++0x -Wall -Werror -Wshadow -pedantic -g
MAIN = main.o
-OBJ = log.o document.o view.o screen.o vfpu.o
+OBJ = log.o real.o document.o view.o screen.o vfpu.o
LIB_x86_64 = ../contrib/lib/libSDL2-2.0.so.0 -lGL
LIB_i386 = ../contrib/lib32/libSDL2-2.0.so.0 -lGL
TESTRPATH := $(TESTRPATH_$(ARCH))
CFLAGS := $(CFLAGS_$(ARCH))
-
+DEF = -DREAL=1
LINKOBJ = $(OBJPATHS)
all : $(BIN)
+single : DEF = -DREAL=0
+single : $(BIN)
+
+double : DEF = -DREAL=1
+double : $(BIN)
+
+# The tests will compile with the default REAL definition
+# To change that you can run as `make DEFS="REAL=X" tests/<target>` where X is your chosen type
+# But remember to make clean first.
tests/% : tests/%.cpp ../obj/tests/%.o $(LINKOBJ)
../obj/%.o : %.cpp
@mkdir -p $(dir $@)
- $(CXX) $(CFLAGS) -c -MMD -o $@ $<
+ $(CXX) $(CFLAGS) $(DEF) -c -MMD -o $@ $<
-include $(DEPS)
#include "common.h"
#include "real.h"
+#define C_RED Colour(1,0,0,1)
+#define C_GREEN Colour(0,1,0,1)
+#define C_BLUE Colour(0,0,1,1)
+
namespace IPDF
{
#include <unistd.h> // Because we can.
int main(int argc, char ** argv)
{
+ Debug("Compiled with REAL = %d => \"%s\"", REAL, g_real_name[REAL]);
+
Document doc;
srand(time(NULL));
enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
- Rect bounds(0,0,1,1);
+
Colour c(0,0,0,1);
const char * input_bmp = NULL;
const char * output_bmp = NULL;
const char * input_filename = NULL;
+ float b[4] = {0,0,1,1};
int i = 0;
while (++i < argc)
i += 4;
break;
}
+ case 'b':
+ {
+ Debug("Reading view bounds");
+ for (int j = 1; j <= 4; ++j)
+ {
+ if (i+j >= argc)
+ Fatal("No %d bounds component following -b switch", j);
+ char * e;
+ b[j-1] = strtof(argv[i+j], &e);
+ if (*e != '\0')
+ Fatal("Bounds component %d not a valid float", j);
+ }
+ i += 4;
+ break;
+ }
}
}
}
else
{
- doc.Add(RECT_FILLED, Rect(0.2,0.2,0.6,0.6));
+ doc.Add(RECT_OUTLINE, Rect(0.5,0.5,1,1));
}
+ Rect bounds(b[0],b[1],b[2],b[3]);
if (mode == LOOP)
MainLoop(doc, bounds, c);
{
View view(doc, bounds, c);
Screen scr;
- scr.RenderBMP(input);
+ if (input != NULL)
+ scr.RenderBMP(input);
view.Render();
- sleep(1);
- scr.ScreenShot(output);
+ if (output != NULL)
+ scr.ScreenShot(output);
scr.Present();
-
- sleep(1);
}
inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f))
--- /dev/null
+#include "real.h"
+
+namespace IPDF
+{
+ // Maps the REAL to a string
+ const char * g_real_name[] = {
+ "single",
+ "double"
+ };
+
+}
#include "common.h"
-namespace IPDF
-{
+#define REAL_SINGLE 0
+#define REAL_DOUBLE 1
+
+#ifndef REAL
+ #error "REAL was not defined!"
+#endif
-#define REAL_SINGLE
-//#define REAL_DOUBLE
-//#define REAL_HALF
-#ifdef REAL_SINGLE
+namespace IPDF
+{
+ extern const char * g_real_name[];
+
+#if REAL == REAL_SINGLE
typedef float Real;
inline float Float(Real r) {return r;}
-#elif defined REAL_DOUBLE
+#elif REAL == REAL_DOUBLE
typedef double Real;
inline double Float(Real r) {return r;}
-#endif
+#else
+ #error "Type of Real unspecified."
+#endif //REAL
+
}
#endif //_REAL_H
#include "screen.h"
#include "SDL_opengl.h"
+#include <fcntl.h> // for access(2)
+#include <unistd.h> // for access(2)
using namespace IPDF;
using namespace std;
*/
void Screen::RenderBMP(const char * filename) const
{
+ if (access(filename, R_OK) == -1)
+ {
+ Error("No such file \"%s\" - Nothing to render - You might have done this deliberately?", filename);
+ return;
+ }
SDL_Surface * bmp = SDL_LoadBMP(filename);
if (bmp == NULL)
Fatal("Failed to load BMP from %s - %s", filename, SDL_GetError());
y *= m_bounds.h;
m_bounds.x += x;
m_bounds.y += y;
+ Debug("View Bounds => %s", m_bounds.Str().c_str());
}
void View::ScaleAroundPoint(Real x, Real y, Real scaleAmt)
{
+ // x and y are coordinates in the window
// Convert to local coords.
x *= m_bounds.w;
y *= m_bounds.h;
x += m_bounds.x;
y += m_bounds.y;
- Debug("Mouse wheel event %f %f %f\n", Float(x), Float(y), Float(scaleAmt));
+ //Debug("Mouse wheel event %f %f %f\n", Float(x), Float(y), Float(scaleAmt));
Real top = y - m_bounds.y;
Real left = x - m_bounds.x;
m_bounds.y = y - top;
m_bounds.w *= scaleAmt;
m_bounds.h *= scaleAmt;
+ Debug("View Bounds => %s", m_bounds.Str().c_str());
}
void View::DrawGrid()
{
public:
View(Document & document, const Rect & bounds = Rect(0,0,1,1), const Colour & colour = Colour(0.f,0.f,0.f,1.f))
- : m_document(document), m_bounds(bounds), m_colour(colour) {}
+ : m_document(document), m_bounds(bounds), m_colour(colour)
+ {
+ Debug("View Created - Bounds => {%s}", m_bounds.Str().c_str());
+ }
virtual ~View() {}
void Render();