Analyses, Musings

Just another WordPress.com weblog

Archive for the ‘Uncategorized’ Category

Drawing Filled, Concave Polygons Using the Stencil Buffer

with 3 comments

Chapter 14

Here is a GLUT implementation. I use GL_INCR instead of GL_INVERT but it keeps the basic idea.

#include "glut.h"

float p[][2]={{0,0}
,{.1,0}
,{.4,.3}
,{0,.5}
,{.7,1}
,{.3,.5}
,{1,0}
,{.6,.1}};

void d(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1,1);
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);

glColorMask(0,0,0,0);

glColor3f(1,1,1);
glBegin(GL_TRIANGLES);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[2][0],p[2][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[7][0],p[7][1]);
glEnd();

glColorMask(1,1,1,1);

glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);

glStencilFunc(GL_EQUAL,1,255);
glColor3f(0,.5,0);
glBegin(GL_TRIANGLES);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[2][0],p[2][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[7][0],p[7][1]);
glEnd();

glStencilFunc(GL_EQUAL,3,255);
glColor3f(0,1,0);
glBegin(GL_TRIANGLES);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[2][0],p[2][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[7][0],p[7][1]);
glEnd();

glStencilFunc(GL_EQUAL,2,255);
glColor3f(0,0,.5);
glBegin(GL_TRIANGLES);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[2][0],p[2][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[7][0],p[7][1]);
glEnd();

glStencilFunc(GL_EQUAL,4,255);
glColor3f(0,0,1);
glBegin(GL_TRIANGLES);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[2][0],p[2][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[3][0],p[3][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[4][0],p[4][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[5][0],p[5][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[1][0],p[1][1]);
glVertex2f(p[6][0],p[6][1]);
glVertex2f(p[7][0],p[7][1]);
glEnd();

glFlush();
}

void init(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,1,0,1,0,1);
}

int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_STENCIL);
glutCreateWindow("");
init();
glutDisplayFunc(d);
glutMainLoop();
return 0;
}

Advertisements

Written by 001041a

July 13, 2012 at 6:45 am

Posted in Uncategorized

A working stencil test OpenGL sample

leave a comment »

Written by 001041a

July 11, 2012 at 9:33 pm

Posted in Uncategorized

Notes on SendMessageRemote()

leave a comment »

(03feb10)

(SendMessageRemote() is a useful function for doing GetWindowText() on dialog
items in another process.  Due to implementation details GetWindowText() often
fails if you try using it for that)

(running windows vista 32-bit)

the last parameter of david ching's SendMessageRemote() is the exact maximal
number of bytes that his code will write to your buffer whose address you pass
in the LPVOID fifth parameter

e.g.since WM_GETTEXT writes wchar_t's you will get  (assuming the window whose
text is being read has a title that big)  8 and 1/2 wide-chars written to your
memory

and it will NOT write the terminating null

note that WM_GETTEXT wParam msdn says is the maximal number of characters to
transfer

so dont you think that would limit SendMessageRemote()  (indirectly)  to only
transfer 6.5 wide-chars to your buffer?  (if you specify wParam==13)

no.

because WM_GETTEXT is 'smart' enough to know that wchar_t's are two bytes thus
it thinks you told it 'my buffer is 26 bytes big'

but microsoft has a bug!  they say it returns the number of wide-chars written
not counting terminating null.  therefore you would expect in our example since
in the remote process it thinks it had a 26 byte buffer it would write 12 wide
chars and then a terminating null it should return 12

it actually returns 25 in my testing!*

anyway the upshot is that you can just put 999 in the wParam to WM_GETTEXT and
the 'real' restriction is what you tell SendMessageRemote() in the sixth size_t
parameter

you will be safe as long as you set that size_t to size of your buffer minus
one  (and do the terminating null yourself)

[to test:  what if the title of the window is 'Short' i.e. there are only ten
bytes worth of wide char to send over?  will david ching's code mindlessly
write 10 bytes then perhaps 7 bytes of memory rubbish from the other injected
process?]

[it seems SendMessage() microsoft code processing WM_GETTEXT does some 'safe
buffering' stuff where it takes the actual strlen() of the stuff in say an edit
box and allocates separate string that has that text and null terminated]

[then it gives THAT safe buffer to david ching's remote thread and that remote
thread presumably hits terminating null and even though you request 17 bytes of
raw memory transfer the remote thread is smart and only writes 12 bytes to your
LPVOID the wchar_t's (S)(h)(o)(r)(t)(0)]

[actually it will not write any terminating null perhaps it 'knows about' the
strlen() being 5, scribbled down somewhere by WM_GETTEXT processing code]

[point is if WM_GETTEXT sees wParam too short for the buffer it doesnt write
terminating null to its own buffer, and somehow david ching remote thread is
aware of this and also does not write a terminating null]

[therefore again in that case when strlen() exactly equals wParam you will have
to null terminate your LPVOID]

[final note seems to be bug in ReadProcessMemory() used by david ching it says
it wrote 17 bytes but i plainly see in my buffer it only wrote the (S)(h)(o)(r)
(t) and left buffer slots after that untouched, didnt even copy garbage.  this
is with wParam set to 5 for WM_GETTEXT]

*as you can see if you read on it actually DOES only write 26 bytes worth of
wide chars.  though it will write 13 wide chars and let you worry about
terminating null.  the real funny part is that i dont know if in the remote
process since it scribbles somewhere '25' to return to you if it was dumb
enough to write 25 wide chars to a buffer the user said 'size is 13' for

Addendum:

Boy things get really odd.  If you set wParam==5 but have _six_ characters in
the edit box 'Longer' and david ching size_t_L_param is 17 you only get 'Longe'
back!  And the remote thread SendMessage() returns 6!  Whatever..

Written by 001041a

February 4, 2010 at 4:30 am

Posted in Uncategorized

Compile Audacity 1.2.6 Source on Windows Vista 32-bit

with one comment

Compile Audacity 1.2.6 Source on Windows Vista 32-bit
29 December 2009
(sources: win/compile.txt, Audacity wiki, google searches on compilation errs.)

Main thing was needed to compile wxWidgets as Debug not Debug DLL.

Tested process from start to end, but having uninstalled and reinstalled and
recompiled so many times on this machine, no guarantees.

At the time of writing, the recommended versions were Audacity 1.3.9 or 1.3.10
beta, and wxWidgets 2.8.9 or 2.8.10, but Debug builds crashed a lot and the
Release build took too long to recompile even a small change, so I went with
Audacity 1.2.6.

Download:
audacity-src-1.2.6.tar.gz (md5=5477ddca23592ae06cc3295f91961ec0)
wxMSW-2.4.2.zip (md5=2b1594182175c3afe33c2c2f443d6000)

-Extract wxWindows-2.4.2 folder to C:
-Extract audacity source (C:\audacity-src-1.2.6)
-Copy contents of C:\audacity-src-1.2.6\win\wxWidgets_additions_VC7 to
 C:\wxWindows-2.4.2\src
-Open wxWindows.sln in Visual C++ 2008 Express (convert it)
-Build menu, Configuration Manager, Active solution change from "Debug DLL" to
 "Debug" (should change wxWindows subproject from "Debug DLL" to "Debug")
-Control Panel, Classic View, System, Advanced system settings, Env.variables,
 System variables, add WXWIN with value C:\wxWindows-2.4.2
-Tools menu, Options, Projects and Solutions, VC++ Directories, Include files
 add entry:
 $(WXWIN)\include
-Library files add entry:
 $(WXWIN)\lib
-Close and reopen VC2008express
-Solution Explorer, highlight wxWindows subproject, right-click Properties,
 Configuration prop., C/C++, Code Generation assert Runtime Library is:
 Multi-threaded Debug (/MTd)
-Also in C/C++, General assert Additional Include Directories has "../lib/mswd"
-Librarian, Output File should be "..\lib\wxmswd.lib"
-Build menu, Build solution
-Don't worry about localtime, sscanf, etc may be unsafe warnings
-If you get regerror.c errors, move the type specifiers into the regerror()
 function declaration (i.e. convert it from old C function signature style)
-It should complete the build now giving you wxmswd.lib in
 C:\wxWindows-2.4.2\lib and wx/setup.h in C:\wxWindows-2.4.2\lib\mswd
-Exit VC2008express

At this point, instructions say to if you have certain modules like "libmad" or
"OGG/Vorbis support" you need to enable them with Audacity's configwin.h.  I
didn't have any of these installed.

-Open C:\audacity-src-1.2.6\win\audacity.sln (and convert)
-Due to not having modules like libmad, OGG Vorbis, installed(?), I got errors
 in the conversion log, and several subprojects in Solution Explorer say
 unavailable.  (libsndfile is available though)  It's not a show stopper though
-Build menu, Configuration manager, assert all Configurations say Debug
-Assert in Audacity subproject's properties, Config., C/C++, Addt'l Incl. Dirs.
 has $(WXWIN)\lib\mswd as first entry
 (should prevent platform.h can't find wx/setup.h errors)
-Also C/C++, Code Generation is using Multi-threaded Debug (/MTd)
-Also Linker, Input, Addt'l Dependencies already has wxmswd.lib in the list
-Try Build solution
-If you get can't find FLAC/all.h error, remove HAVE_FLAC_ALL_H from libsndfile
 subproject properties (Config., C/C++, Preprocessor, Prepr.Defn's)
-If you get cannot open libFLACd.lib, remove that file from Audacity properties
 Config., Linker, Input, Addt'l Dep.
-If you get ambiguous pow() call error, you can change "resultDivFactor" to
 "(double)resultDivFactor"
-Compile should succeed now and F5 should successfully bring up newly compiled
 Audacity

Written by 001041a

January 4, 2010 at 4:04 am

Posted in Uncategorized

Tagged with , , ,