From 1d85158760bd53f5641912f5067ab941236ddf0a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 25 Oct 2009 16:05:43 +0000 Subject: [PATCH] Properly support arbitary sizes in History Pad the graph texture if NPOT textures are not supported Remove an extraneous pop_matrix call --- source/history.cpp | 27 +++++++++++++++++++-------- source/host.cpp | 2 -- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/source/history.cpp b/source/history.cpp index adcc3ec..b3e15f2 100644 --- a/source/history.cpp +++ b/source/history.cpp @@ -5,6 +5,7 @@ Copyright @ 2008 Mikko Rasa, Mikkosoft Productions Distributed unter the GPL */ +#include #include #include #include @@ -25,18 +26,28 @@ History::History(NetVis &n, unsigned w, unsigned h): scale(1024), mesh((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2)) { - texture.storage(GL::RGBA, height, width, 0); + unsigned texw = height; + unsigned texh = width; + if(!GL::is_supported("ARB_texture_non_power_of_two")) + { + for(texw=1; texw(height)/texw; + float hf = static_cast(width)/texh; GL::MeshBuilder bld(mesh); bld.color(1.0f, 1.0f, 1.0f); bld.begin(GL::QUADS); - bld.texcoord(0, 1); + bld.texcoord(0, hf); bld.vertex(0, 0); bld.texcoord(0, 0); bld.vertex(width, 0); - bld.texcoord(1, 0); + bld.texcoord(wf, 0); bld.vertex(width, height); - bld.texcoord(1, 1); + bld.texcoord(wf, hf); bld.vertex(0, height); bld.end(); } @@ -129,20 +140,20 @@ void History::create_texture() up_min = min(value+1, up_min); up_max = max(value, up_max); } - unsigned *row = &data[y*100]; - for(unsigned x=0; x<100; ++x) + unsigned *row = &data[y*height]; + for(unsigned x=0; x=up_min && x<=up_max) row[x] = 0xFF8000FF; else if(x<=down) row[x] = 0xFF80FF80; - else if(x%25==24 || y%60==0) + else if((x*4+4)%height==0 || y%60==0) row[x] = 0x40FFFFFF; else row[x] = 0x00000000; } } - texture.image(0, GL::RGBA, GL::UNSIGNED_BYTE, data.data()); + texture.sub_image(0, 0, 0, height, width, GL::RGBA, GL::UNSIGNED_BYTE, data.data()); } diff --git a/source/host.cpp b/source/host.cpp index 4314d75..1e92ed7 100644 --- a/source/host.cpp +++ b/source/host.cpp @@ -156,6 +156,4 @@ void Host::render() const imm.color(1.0f, 1.0f, 1.0f); font.draw_string(short_name, imm); GL::Texture::unbind(); - - GL::pop_matrix(); } -- 2.45.2