View Full Version : Polygon
I would like to know how can I draw any poligon at this way...
I chose all the points with mouse left button, and then when the right mouse is pressed all the points at the order that I clicked is linked... ??
I'm newbie I tried many way and no success
09-22-2005, 09:58 PM
I don't have any code that does this but this is the algorithm I would use:
Keep a list of vertices and a flag that when set to true draws the polygon with GL_POLYGON. Use a polygon mode of GL_FILL for a solid polygon or GL_LINE for the outline of a polygon.
In your init function:
set the flag to false
set the polygon mode to GL_LINE or GL_FILL
In your mouse function:
if the user clicks the left button:
add a vert to the list
if the user clicks the right button:
set the flag to true
In your display function:
if the flag is true:
draw the polygon with GL_POLYGON
To keep things simple you'll probably want to use a 2-D orthographic projection, and remember that for many operations OpenGL is happier if you pass it the verteces in counterclockwise order. Sorry I don't have code for you, but chapters 2 & 3 of the OpenGL Programming Guide (The Red Book) cover what you need to know.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.