Simple drawing tool based on C++(MSVC) and OpenGL

simple-openl-graphic-tool

Source code can be downloaded from this project repository:
github
gitee

?Simple drawing tool based on C++ (MSVC) and OpenGL? Dynamically draw graphics through rubber band technology; Liang-Barsky algorithm batches clipping of straight lines and polylines; Bresenham algorithm draws ellipses at the midpoint of ellipses.

Contains executable files, environment configuration guide.

Personal website: www.bytesc.top

Personal blog: blog.bytesc.top

If you have any project-related questions, you are welcome to raise issue in this project. I will usually respond within 24 hours.

Source code

C++ source code file. If you run it in an OpenGL environment other than visual studio 2022, just use the following code file.

│ simple-openl-graphic-tool.cpp # Main source code file, project entry
│ lineClipping.cpp # Liang-Barsky algorithm
│ lineClipping.h
│ onMidPointEllispe.cpp # Bresenham algorithm
│ onMidPointEllispe.h

Page display

Liang-Barsky algorithm for clipping polylines

Please add a picture description
Right-click and select the Line menu to start drawing polylines.
Please add an image description

Press P on the keyboard to enter Paint mode. (Note that all keyboard operations must be switched to English input method, Chinese input method is invalid)

Then press and hold the left button to determine the starting point, press and hold the left button to drag the polyline, release the left button to determine a vertex, and press the left button again to continue.

Please add image description

Press E on the keyboard to enter cropping mode. (Note that all keyboard operations must be switched to English input method, Chinese input method is invalid)

Hold down the left button and drag the cropping frame, release to determine the size of the frame.

Please add a picture description

Press C on the keyboard, and the program will use the Liang-Barsky algorithm to crop the polyline according to the cropping box.

Please add a picture description

Bresenham algorithm for drawing ellipses

Please add an image description

Right-click and select the ellipse menu to start drawing.
Please add image description

Hold down the left button and drag to draw.
Please add an image description

Multiple pictures can be drawn continuously. Right-click and select the clear menu item to clear it.
Please add a picture description

When you hold down the left button and drag the mouse to draw, hold down shift at the same time to draw a perfect circle.
Please add image description
Please add a picture description

Operating environment

Operating environment

  • windows 11
  • Visual Studio 2022
  • OpenGL
    • glfw-3.3.8.bin.WIN64
    • glutdlls37beta

Do not configure the environment

If you only run the executable file without modification or debugging, there is no need to configure the environment.

The executable file can be found in x64/debug/simple-openl-graphic-tool.exe by double-clicking it in the project directory.

Environment configuration

For the configuration method, please refer to this Zhihu article I reprinted: OpenGL environment setup for VS2022 (complete article)

Visual Studio 2022 The related resources and guidelines required to configure OpenGL (reproduced not original) are in the conf folder.

The conf/Exported.vssettings file is the exported visual studio configuration

Project structure

Source code

C++ source code file. If you run it in an OpenGL environment other than visual studio 2022, just use the following code file.

│ simple-openl-graphic-tool.cpp # Main source code file, project entry
│ lineClipping.cpp # Liang-Barsky algorithm
│ lineClipping.h
│ onMidPointEllispe.cpp # Bresenham algorithm
│ onMidPointEllispe.h

vs project directory

visual studio 2022 project directory

│ .gitignore
│ LICENSE
│ lineClipping.cpp
│ lineClipping.h
│ onMidPointEllispe.cpp
│ onMidPointEllispe.h
│ packages.config
│ README.md
│ simple-openl-graphic-tool.cpp # Main source code file, project entry
│ simple-openl-graphic-tool.sln
│ simple-openl-graphic-tool.vcxproj
│ simple-openl-graphic-tool.vcxproj.filters
│ simple-openl-graphic-tool.vcxproj.user
│
├─conf
│ conf.pdf # Configuration Guide
│ Exported.vssettings # Exported visual-studio configuration
│ glad.zip
│ glfw-3.3.8.bin.WIN64.zip
│ glutdlls37beta.zip
│
├─packages
├─readme_img
│
└─x64
    ├─Debug
    │ │ freeglut.dll
    │ │ glew32.dll
    │ │ glewinfo.exe
    │ │ glfw3.dll
    │ │ simple-openl-graphic-tool.exe # Executable file entry
    │ │ simple-openl-graphic-tool.exe.recipe
    │ │ simple-openl-graphic-tool.ilk
    │ │ simple-openl-graphic-tool.log
    │ │ simple-openl-graphic-tool.obj
    │ │ simple-openl-graphic-tool.pdb
    │ │ simple-openl-graphic-tool.vcxproj.FileListAbsolute.txt
    │
    └─Release
        │freeglut.dll
        │ glew32.dll
        │ glewinfo.exe
        │ glfw3.dll
        │ lineClipping.obj
        │ onMidPointEllispe.obj
        │ simple-openl-graphic-tool.exe # Executable file entry
        │ simple-openl-graphic-tool.exe.recipe
        │ simple-openl-graphic-tool.iobj
        │ simple-openl-graphic-tool.ipdb
        │ simple-openl-graphic-tool.log
        │ simple-openl-graphic-tool.obj
        │ simple-openl-graphic-tool.pdb
        │ simple-openl-graphic-tool.vcxproj.FileListAbsolute.txt
       

Run method

Run

There is no need to configure the environment to run the executable file. Double-click to open x64/debug/simple-openl-graphic-tool.exe

Debugging

First configure the environment as above, then use Visual Studio 2022 to open simple-openl-graphic-tool.sln, the source code file is simple-openl-graphic-tool .cpp

Before debugging, you need to exclude the following files from generation, as shown below:

│ lineClipping.cpp
│ lineClipping.h
│ onMidPointEllispe.cpp
│ onMidPointEllispe.h

Please add a picture description
Please add a picture description
Visual-studio configuration can also be imported from conf/Exported.vssettings
Please add a picture description
Please add a picture description
Click Browse to find and select conf/Exported.vssettings
Please add an image description
Please add an image description

Open Source License

This translated version is for reference only, the English version in the LICENSE file shall prevail

MIT Open Source License:

Copyright ? 2023 bytesc

The right to use, copy, modify, merge, publish, distribute, sublicense and/or sell the Software is hereby granted, free of charge, to any person obtaining a copy of this software and related documentation files (the “Software”), subject to the following condition:

The above copyright notice and this permission notice shall be included in all copies or substantial portions thereof.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. In no event shall the author or copyright holder be liable for any claim, damages or other liability, whether in contract, tort or otherwise, arising out of the use of this software.