Jump to content
  • Advertisement
Sign in to follow this  
Zay Zay Zaw

OpenGL MouseEvent Drawing 2D Primitive Objects

This topic is 2739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Guys,

I need some help in developing with OpenGL for using with mouse to draw 2D primitives object. Honestly speaking, yes, it is for my School Project and this is my first time using to OpenGL software but i got some background knowledge of C++ . The purpose is that I'll be able to draw those primitives, rotate them and translate them, including different mode, which are selection mode and drawing mode. And the program should be able to delete for the selected object.

The problem i am having is to track the mouse coordinate to draw either the line, square, or circle with the mouse event. Can say so that i am lack in coming out with those formula and another thing is to assign with Keyboard. I have attached my Program for your reference and those area in program with "missing" mean i don't know what to do. All in all, if i were to summarize to make it clear;

Drawing 2D Primitive Objects
The choice of primitive to be drawn is done using the keyboard (letter ‘l’=line, ‘c’=circle, ‘r’=rectangle) or via a menu.

Mouse left button control
[Draw Mode]
The program should draw the selected primitive type when the user press the left mouse button.
The object’s size changes according to the mouse position while the left mouse button remains pressed.
When the left-button is released, the object is confirmed and finalized.

[Selection Mode]
When the user presses the left button down, you should find the closest primitive to the mouse position (You must decide how to find the closest primitives -- this will most likely be based on the distance from the mouse to some part of the drawn primitives. You may set a maximum distance for selection – for example if no primitive within 10 pixels then don’t select any.)
While the mouse is down, your primitive should move along with the movement of the mouse. (translation only, not scaling).
The current object that is selected should be highlighted. For example, the object could have a different shade of color around it’s outer circumference

Simple Edits (in either mode)
The user should be able to delete the last drawn object.
The user should be able to delete all the objects on the screen.

Application Control
Implement the following keyboard shortcuts to control the program states:
Keys ‘l’=line, ‘r’=rectangle, ‘c’=circle
Key ‘u’ = erase last
Key ‘e’ = erase all
Key ‘s’ = selection mode
Key ‘d’ = draw mode [default mode is draw mode]
‘Escape’ key to exit the application

I truly appreciate your help and consideration. I would be delighted if you could help me out with the coding. I look forward to hearing from you guys and thanks a million in advance. Thank you.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!