From: David Gow Date: Thu, 17 Apr 2014 06:00:16 +0000 (+0800) Subject: Bunch-a-bugfixes! X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=b1786b24148036a4d9402cc12ea97466072e988d;hp=67fb91aae1fc5315f462d6b5818806f154e9e687 Bunch-a-bugfixes! - Screenshots work properly. - Alpha works properly - New screen clear function, so we don't throw away things we need. --- diff --git a/bin/ipdf b/bin/ipdf index f242971..86a7077 100755 Binary files a/bin/ipdf and b/bin/ipdf differ diff --git a/src/main.h b/src/main.h index 6763042..9fcc26b 100644 --- a/src/main.h +++ b/src/main.h @@ -13,8 +13,8 @@ inline void OverlayBMP(Document & doc, const char * input, const char * output, { View view(doc, bounds, c); Screen scr; - //view.Render(); scr.RenderBMP(input); + view.Render(); scr.Present(); sleep(5); scr.ScreenShot(output); @@ -57,6 +57,7 @@ inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const while (scr.PumpEvents()) { + scr.Clear(); view.Render(); scr.Present(); } diff --git a/src/screen.cpp b/src/screen.cpp index 712bd26..59d4334 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -19,11 +19,11 @@ Screen::Screen() m_gl_context = SDL_GL_CreateContext(m_window); - glClearColor(1.f,1.f,1.f,1.f); - glClear(GL_COLOR_BUFFER_BIT); + ResizeViewport(800, 600); + + Clear(); Present(); - ResizeViewport(800, 600); } @@ -34,6 +34,12 @@ Screen::~Screen() SDL_Quit(); } +void Screen::Clear(float r, float g, float b, float a) +{ + glClearColor(r,g,b,a); + glClear(GL_COLOR_BUFFER_BIT); +} + void Screen::ResizeViewport(int width, int height) { glViewport(0, 0, width, height); @@ -133,9 +139,16 @@ void Screen::ScreenShot(const char * filename) const if (pixels == NULL) Fatal("Failed to allocate %d x %d x 4 = %d pixel array", w, h, w*h*4); - glReadPixels(0,0,w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + for (int y = 0; y < h; ++y) + { + glReadPixels(0,h-y-1,w, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[y*w*4]); + } - SDL_Surface * surf = SDL_CreateRGBSurfaceFrom(pixels, w, h, 8*4, w*4, 0,0,0,0); +#if SDL_BYTEORDER == SDL_LIL_ENDIAN + SDL_Surface * surf = SDL_CreateRGBSurfaceFrom(pixels, w, h, 8*4, w*4, 0x000000ff,0x0000ff00,0x00ff0000,0xff000000); +#else + SDL_Surface * surf = SDL_CreateRGBSurfaceFrom(pixels, w, h, 8*4, w*4, 0xff000000,0x00ff0000,0x0000ff00,0x000000ff); +#endif if (surf == NULL) Fatal("Failed to create SDL_Surface from pixel data - %s", SDL_GetError()); diff --git a/src/screen.h b/src/screen.h index e641826..44dd2c7 100644 --- a/src/screen.h +++ b/src/screen.h @@ -20,6 +20,9 @@ namespace IPDF // Returns 'false' if the program should quit. bool PumpEvents(); + // Clears the screen to a given colour. + void Clear(float r=1.0, float g=1.0, float b=1.0, float a=1.0); + // Finishes rendering a frame, and presents it on the screen. void Present(); diff --git a/src/view.cpp b/src/view.cpp index 3c6e2f5..6a3dbdf 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -69,8 +69,6 @@ void View::Render() debug_output_done = true; } - glClearColor(1.f,1.f,1.f,1.f); - glClear(GL_COLOR_BUFFER_BIT); //DrawGrid(); // Draw the gridlines @@ -80,6 +78,11 @@ void View::Render() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + if (m_colour.a < 1.0f) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } glColor4f(m_colour.r, m_colour.g, m_colour.b, m_colour.a); glBegin(GL_QUADS); for (unsigned id = 0; id < m_document.ObjectCount(); ++id) @@ -108,4 +111,9 @@ void View::Render() glEnd(); } + if (m_colour.a < 1.0f) + { + glDisable(GL_BLEND); + } + }