PDA

View Full Version : Rubber rectangle



hellrage
03-28-2002, 06:44 PM
Hi,
Does anyone has an idea how to draw a rubber rectangle using openGL ? Thanx's

nexusone
03-28-2002, 07:03 PM
If I put a rubberband around my opengl book it makes ruber rectangle!!!! http://www.opengl.org/discussion_boards/ubb/smile.gif

But do you mean like a rectangle, like a windows selection function or maybe a drawing function?



Originally posted by hellrage:
Hi,
Does anyone has an idea how to draw a rubber rectangle using openGL ? Thanx's

hellrage
03-29-2002, 01:46 AM
Hi,
Sorry if my question is unclear. What i mean by rubber rectangle is that when the rectangle can be resize it when we're drawing them. It's like the selection tool in Photoshop, if you've used this program before. Does anyone have idea how to do this? Thanx's

Bob
03-29-2002, 02:41 AM
Get the position of the first mouse click, and save it. As long as the mouse button is pressed, then for each mouse movement, draw a rectange from the saved position to the current mouse position. And last, when you release the mouse button, save the current mouse position, and you have the two corners needed to draw the rectangle.

Getting the mouse position, on the other hand, is nothing you do with OpenGL, so that's another problem.

nexusone
03-29-2002, 05:58 AM
Using GLUT you can get the mouse position and mouse click events, if you need more let me know.


example code:

glutMouseFunc(mouse_event);
glutPassiveMotionFunc(mouse_passive);


mouse_event(int button, int x, int y)

if button GLUT_LEFT and BUTTON_DOWN
save first left top conner of box.
set a flag to state start of box

if button GLUT_LEFT and BUTTON_UP
save second conner bottom right of box.
set flag to state end of box
}


mouse_passive(int x, int y)
{
If box flag set, give the bottom right of box the current x, y position.
}

}


Originally posted by hellrage:
Hi,
Sorry if my question is unclear. What i mean by rubber rectangle is that when the rectangle can be resize it when we're drawing them. It's like the selection tool in Photoshop, if you've used this program before. Does anyone have idea how to do this? Thanx's

hellrage
03-29-2002, 12:37 PM
Hi,
Thanx's for posting the code but i'm having difficulties understanding it. Do you have the actual code to make them working? So i can have a look how it actually works on openGL ? And also is GLutpassivemotion is a built-in function in openGL ? Or is it something that we have to make ? I know that openGL has glutmotionFunc though. Thanx's

pleopard
03-29-2002, 01:37 PM
Sorry, no time to explain but ... here is mine ...




// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
// Render the rubberband

void DGNView5Exec::renderRubberBand()
{
double wxm, wxx, wym, wyx;
double vxm, vym;
double mx, my, bx, by;


// Drawing Window Dimensions
wxm = -16.0;
wxx = 16.0;
wym = -12.0;
wyx = 12.0;
// Viewport Window Dimensions (screen, mouse)
vxm = 0.0;
vym = 0.0;

mx = (wxx-wxm)/(z_Engine->windowViewPort().width()-vxm);
my = -(wyx-wym)/(z_Engine->windowViewPort().height()-vym);
bx = wxm;
by = wyx;

double x0 = mx *((double)m_RubberBandStartCoords[0]) + bx;
double y0 = my *((double)m_RubberBandStartCoords[1]) + by;

double x1 = mx *((double)m_RubberBandEndCoords[0]) + bx;
double y1 = my *((double)m_RubberBandEndCoords[1]) + by;

z_Engine->stateManager().enable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
z_Engine->stateManager().enable(GL_LINE_STIPPLE);
z_Engine->stateManager().disable(GL_LIGHTING);
z_Engine->stateManager().disable(GL_TEXTURE_2D);

glLineWidth(2);
glColor3d(0,1,1);
glLineStipple(2,64250);
/*
glLineWidth(2);
glColor3d(1,1,0);
glLineStipple(1,0xF0F0);
*/

/*
glLineWidth(2);
glColor3d(1,1,0);
glLineStipple(1,0xF00F);
*/

/*
glColor3d(1,0,0);
glLineWidth(1);
glLineStipple(1,0x8888);
*/

/*
glLineWidth(1);
glColor3d(1,1,0);
glLineStipple(2,0x1c47);// dash/dot/dash
*/

z_Engine->stateManager().setActiveMatrix(GL_PROJECTION);
glPushMatrix();

glLoadIdentity();
gluOrtho2D(
wxm,
wxx,
wym,
wyx
);
z_Engine->stateManager().setActiveMatrix(GL_MODELVIEW);

glPushMatrix();

glLoadIdentity();

glBegin(GL_LINE_LOOP);
// Top left
glVertex3d( x0, y0, 0.0);
// top right
glVertex3d( x1, y0, 0.0);
// Bottom right
glVertex3d( x1, y1, 0.0);
// bottom left
glVertex3d( x0, y1, 0.0);
glEnd();

glPopMatrix();

z_Engine->stateManager().setActiveMatrix(GL_PROJECTION);
glPopMatrix();
z_Engine->stateManager().setActiveMatrix(GL_MODELVIEW);

z_Engine->stateManager().disable(GL_COLOR_LOGIC_OP);
z_Engine->stateManager().disable(GL_LINE_STIPPLE);
glLineWidth(1);
}

nexusone
03-29-2002, 01:48 PM
This are functions found in the GLUT library for use with OpenGL, I think you need to learn to use the openGL online books to help you learn the openGL commands.
The openGL red book can be found here: http://ask.ii.uib.no/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/

Here is a link for the GLUT (GL Utility Toolkit)on-line ref: http://www.opengl.org/developers/documentation/Specs/glutspec3/node1.html

Any command you see that start say glut is part of the GLUT library, glutpassivemotion is a good example.

glColor = gl + Color OpenGL base (gl.h)

gluCylinder = glu + Cylinder GLU library (glu.h).

I do not have the code handy and did not have time to write something.
I also think you need to learn a bit more about how to program in general, learning more about C would help, since a lot of programing the graphics has nothing to do with openGL at all.

If I get a chance try to whip up some code.
http://www.opengl.org/discussion_boards/ubb/smile.gif



Originally posted by hellrage:
Hi,
Thanx's for posting the code but i'm having difficulties understanding it. Do you have the actual code to make them working? So i can have a look how it actually works on openGL ? And also is GLutpassivemotion is a built-in function in openGL ? Or is it something that we have to make ? I know that openGL has glutmotionFunc though. Thanx's

hellrage
03-29-2002, 04:42 PM
Hi,
Thanx's for the posting, i'll try to study the code now. Byeee