wxDC on a wxglCanvas

78 views
Skip to first unread message

henrik....@stream-space.com

unread,
Jul 8, 2008, 5:25:22 PM7/8/08
to wx-u...@lists.wxwidgets.org

Hi,

When selecting objects, I'd like to draw a rectangle over the area
selected (startpoint+moving point). On windows I create a wxClientDC
for the canvas and draw using an XOR pen. On a mac, it doesn't work.

Is there a simple fix, should I create some transparent window over my
canvas or can I draw to an OpenGL layer?

Thanks,
Henrik

Vadim Zeitlin

unread,
Jul 8, 2008, 5:36:59 PM7/8/08
to wx-u...@lists.wxwidgets.org
On Tue, 8 Jul 2008 14:25:22 -0700 (PDT) henrik....@stream-space.com wrote:

> When selecting objects, I'd like to draw a rectangle over the area
> selected (startpoint+moving point). On windows I create a wxClientDC
> for the canvas and draw using an XOR pen. On a mac, it doesn't work.

On Mac using XOR pens doesn't work, whether you use them with wxGLCanvas
or not. See the new wxOverlay API in wx/overlay.h and example of its use in
the drawing sample for what does work.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

henrik....@streamspace.com

unread,
Jul 15, 2008, 7:13:29 AM7/15/08
to wx-u...@lists.wxwidgets.org

Thanks Vadim!

I'll take a look at wxOverlay!

Best Regards,
Henrik Vallgren

PS
I found a sample that allowed use of OpenGL to solve this:

void drawInvertRectX(const wxRect &rect)
{
glDesignCanvas *pWnd=getGLWindow();

if (pWnd)
{
wxRect rectClient=pWnd->GetClientRect();

glDisable(GL_DEPTH_TEST);
glDrawBuffer(GL_FRONT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,rectClient.GetWidth(),0,rectClient.GetHeight(),-1,1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glRecti(rect.GetLeft(), rectClient.GetHeight()-rect.GetBottom(),
rect.GetRight(), rectClient.GetHeight()-rect.GetTop());
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_COLOR_LOGIC_OP);
glFlush();

glDrawBuffer(GL_BACK);
glEnable(GL_DEPTH_TEST);
pWnd->reset_viewport(rectClient.GetWidth(),rectClient.GetHeight());

Reply all
Reply to author
Forward
0 new messages