Visual Studio of C++ builds the EasyX Graphics Library graphics library environment, and uses EasyX (graphics.h) to draw the first graphics

Visual Studio of C++ builds the EasyX Graphics Library graphics library environment, and uses EasyX (graphics.h) to draw the first graphics

Table of contents

Visual Studio of C++ builds the EasyX Graphics Library graphics library environment, and uses EasyX (graphics.h) to draw the first graphics

1. Brief introduction

2. Download and install Visual Studio

3. Download and install EasyX Graphics Library into Visual Studio

4. Draw the first graphics with EasyX(graphics.h) and Visual Studio C++

5. Key code


1. Brief introduction

Organize some knowledge developed in C++, so that you can consult and use it in time when you encounter similar problems later.

This section introduces how to configure the EasyX Graphics Library graphics library environment in Visual Studio, and use this library and C++ to realize the simple arrangement of the process of drawing the first graphics. If there are deficiencies, welcome to point out, or if you have a better method, please leave a message.

What is EasyX?

Official Website: EasyX Graphics Library for C++

EasyX Graphics Library is a free graphics library for Visual C++, supports VC6.0 ~ VC2022, easy to use, very low learning cost, and has a wide range of applications. At present, many universities have applied EasyX in teaching.

Ultra-low learning cost

EasyX contains some simple function collections, almost no need to learn, you can use them directly by reading the reference manual. Online Reference Manual Address EasyX Documentation - Basic Instructions

Because EasyX is simple enough, you can focus on the course knowledge and not be too involved in the drawing part when conducting course experiments such as C/C++, graphics, iconography, and fractals. The following is a demo of EasyX:

A lot of application scenarios

EasyX has applications in various scenarios such as C/C++ learning, writing small games, graphics, iconography, fractals, particle systems, and physical simulation. Please refer to the EasyX library  code bus - share valuable C/C++ knowledge and source code  .

Ultra-light publishing process

EasyX adopts static compilation and does not depend on any dll. It is no different from the release method of traditional programs, and the program will not add any release burden due to the introduction of EasyX.

The statically linked EasyX will increase the volume of the compiled exe by about 70KB. For most applications, the added volume is negligible.

If the runtime library of Visual C++ is changed to the static link mode, the compiled exe can run as a single file. 

 

Operating environment:

  • window 10
  • Visual Studio 2019
  •  EasyX Graphics Library 20210730

2. Download and install Visual Studio

1. Download the version corresponding to your needs from the official website

Official website: Download Visual Studio Tools - Free installation for Windows, Mac, Linux

2. The installation is very simple. After the installation is complete, open the Installer to see if the C++ environment is installed. If not, just install it.

3. Download and install EasyX Graphics Library into Visual Studio

1. Download the EasyX installation package from the official website

Official Website: EasyX Graphics Library for C++

2. Download the installation package exe, double-click to run it, and then go to the next step here, select visual studio, and click install

EasyX documentation can also be installed if necessary for later reference

 3. Re-open Visual Studio, include graphics.h, and no error is reported, indicating that Visual Studio has successfully configured EasyX

4. Draw the first graphics with EasyX(graphics.h) and Visual Studio C++

1. Open Visual Studio and create a C++ project

2. Create a script in the project and import the Easy X graphics library graphics.h

3. Write code to draw two circles with Easy X

4. Click "Local Windows Debugger"

5. The effect is as shown in the figure

5. Key code

// easy X 图形库
#include<graphics.h>
#include<iostream>

// 使用 Bresenham 画圆法
void Circle_Bresenham(int x, int y, int r, int color)
{
	int tx = 0, ty = r, d = 3 - 2 * r;

	while (tx <= ty)
	{
		// 利用圆的八分对称性画点
		putpixel(x + tx, y + ty, color);
		putpixel(x + tx, y - ty, color);
		putpixel(x - tx, y + ty, color);
		putpixel(x - tx, y - ty, color);
		putpixel(x + ty, y + tx, color);
		putpixel(x + ty, y - tx, color);
		putpixel(x - ty, y + tx, color);
		putpixel(x - ty, y - tx, color);

		if (d < 0)		// 取上面的点
			d += 4 * tx + 6;
		else			// 取下面的点
			d += 4 * (tx - ty) + 10, ty--;

		tx++;
	}
}

// 主函数
int main()
{
	initgraph(640, 480);

	// 测试画圆
	Circle_Bresenham(320, 240, 200, RED);
	Circle_Bresenham(320, 240, 101, YELLOW);

	// 按任意键退出
	system("pause");
	closegraph();
	return 0;
}

Guess you like

Origin blog.csdn.net/u014361280/article/details/127773724