DEV-C++ ege.h库 绘图教程(三)

一、上期回顾

上次我们讲了高级绘图函数的上半部分,那么今天我们将继续介绍更多的高级绘图函数。

DEV-C++ ege.h库 绘图教程(一)

DEV-C++ ege.h库 绘图教程(二)

二、高级绘图函数

1.ege_setpattern_texture和ege_gentexture

设置高级函数颜色填充模式为纹理填充模式,通俗地说,就是用一个图案来填充。

ege_gentexture则用来生成“纹理”,也就是这个图案。

void ege_setapttern_texture(
    PIMAGE texture,
    float x,
    float y,
    float w,
    float h,
    PIMAGE pimg= NULL
);

其中,x,y,w,h是生成纹理的范围,至于PIMAGE是什么类型,不懂的点这里

texture就是我们要的图案。

关于ege_gentexture的定义是这样的:

void ege_gentexture(
    bool gen,
    PIMAGE pimg = NULL
);

其中,gen表示是否开启纹理填充。

pimg就是图案。

让我们来看一个例子:

其中,这是我的icon.png

 2.ege_puttexture

绘制纹理,就是把图案画出来。

#include<bits/stdc++.h>
#include<graphics.h>
using namespace std;
using namespace ege;
int main(){
	initgraph(640,480);
	PIMAGE img=newimage();
	getimage(img,"icon.png");
	ege_gentexture(1,img);
	ege_setalpha(0xFF,img);
	ege_setpattern_texture(img,0,0,144,144);
	ege_puttexture(img,0,0,240,480);
	getch();
	closegraph();
	return 0;
}

3.ege_transform_rotate

就是把整个窗口旋转一下。

void EGEAPI ege_transform_rotate(float angle,PIMAGE pimg = NULL);

可以看到窗口被旋转了n°。 

但是这里有个问题就是这个angle我不知道是角度制还是弧度制,所以不建议大家用这个。

(我测来测去都不知道这个角度的单位,上网没有相关信息)

4.ege_transform_translate

把整个窗口的(0,0)坐标(也就是左上角)移到(x,y)的位置。

void EGEAPI ege_transform_translate(float x,float y,PIMAGE pimg = NULL);
#include<bits/stdc++.h>
#include<graphics.h>
using namespace std;
using namespace ege;
int main() {
	initgraph(640, 480);
	cleardevice();
	ege_transform_translate(200,100);
	PIMAGE img = newimage();
	getimage(img, "icon.png");
	ege_gentexture(1, img);
	ege_setalpha(0xFF, img);
	ege_setpattern_texture(img, 0, 0, 144, 144);
	ege_puttexture(img, 0, 0, 144, 144);
	delimage(img);
	getch();
	closegraph();
	return 0;
}

 

5.ege_transform_scale

把窗口按一定比例放大。

void EGEAPI ege_transform_scale(float scale_x, float scale_y,PIMAGE pimg = NULL);

 其中scale_x代表x轴的放大(缩小)比例,scale_y也一样。

#include<bits/stdc++.h>
#include<graphics.h>
using namespace std;
using namespace ege;
int main() {
	initgraph(640, 480);
	ege_transform_scale(1.5,2.0);
	PIMAGE img = newimage();
	getimage(img, "icon.png");
	ege_gentexture(1, img);
	ege_setalpha(0xFF, img);
	ege_setpattern_texture(img, 0, 0, 144, 144);
	ege_puttexture(img, 0, 0, 144, 144);
	delimage(img);
	getch();
	closegraph();
	return 0;
}

6.ege_transform_reset

重置窗口变换。 

7.The end of drawing

至此,所有有关画图的函数我差不多都讲完了。有一些没有讲,是因为不常用,或者根本没什么用处。我在这里全部放出来,大家感兴趣的可以去查一下。

// 基本绘图函数

color_t     EGEAPI getpixel  (int x, int y, PCIMAGE pimg = NULL);               // 获取点的颜色
void        EGEAPI putpixel  (int x, int y, color_t color, PIMAGE pimg = NULL); // 画点
color_t     EGEAPI getpixel_f(int x, int y, PCIMAGE pimg = NULL);               // 获取点的颜色
void        EGEAPI putpixel_f(int x, int y, color_t color, PIMAGE pimg = NULL); // 绝对坐标画点
void        EGEAPI putpixels  (int nPoint, int* pPoints, PIMAGE pimg = NULL);   // 批量画点
void        EGEAPI putpixels_f(int nPoint, int* pPoints, PIMAGE pimg = NULL);   // 批量画点

void        EGEAPI putpixel_withalpha  (int x, int y, color_t color, PIMAGE pimg = NULL); // 带透明度画点
void        EGEAPI putpixel_withalpha_f(int x, int y, color_t color, PIMAGE pimg = NULL); // 带透明度绝对坐标画点
void        EGEAPI putpixel_savealpha  (int x, int y, color_t color, PIMAGE pimg = NULL); // 设置像素点的颜色(同时保留原有alpha值)
void        EGEAPI putpixel_savealpha_f(int x, int y, color_t color, PIMAGE pimg = NULL); // 设置像素点的颜色(同时保留原有alpha值,使用绝对坐标)

void EGEAPI moveto(int x, int y, PIMAGE pimg = NULL);                      // 移动当前点(绝对坐标)
void EGEAPI moverel(int dx, int dy, PIMAGE pimg = NULL);                   // 移动当前点(相对坐标)

void EGEAPI line(int x1, int y1, int x2, int y2, PIMAGE pimg = NULL);      // 画线
void EGEAPI linerel(int dx, int dy, PIMAGE pimg = NULL);                   // 画线(至相对坐标)
void EGEAPI lineto(int x, int y, PIMAGE pimg = NULL);                      // 画线(至绝对坐标)
void EGEAPI line_f(float x1, float y1, float x2, float y2, PIMAGE pimg = NULL);  // 画线
void EGEAPI linerel_f(float dx, float dy, PIMAGE pimg = NULL);                   // 画线(至相对坐标)
void EGEAPI lineto_f(float x, float y, PIMAGE pimg = NULL);                      // 画线(至绝对坐标)


void EGEAPI rectangle(int left, int top, int right, int bottom, PIMAGE pimg = NULL);   // 画矩形

//void EGEAPI getarccoords(int *px, int *py, int *pxstart, int *pystart, int *pxend, int *pyend, PIMAGE pimg = NULL);    // 获取圆弧坐标信息 ###
void EGEAPI arc(int x, int y, int stangle, int endangle, int radius, PIMAGE pimg = NULL);                  // 画圆弧
void EGEAPI circle(int x, int y, int radius, PIMAGE pimg = NULL);                                          // 画圆
void EGEAPI pieslice(int x, int y, int stangle, int endangle, int radius, PIMAGE pimg = NULL);             // 画填充圆扇形
void EGEAPI ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius, PIMAGE pimg = NULL);// 画椭圆弧线
void EGEAPI fillellipse(int x, int y, int xradius, int yradius, PIMAGE pimg = NULL);                       // 画填充椭圆
void EGEAPI sector(int x, int y, int stangle, int endangle, int xradius, int yradius, PIMAGE pimg = NULL); // 画填充椭圆扇形
void EGEAPI roundrect(int left, int top, int right, int bottom, int xradius, int yradius, PIMAGE pimg = NULL); //画圆角矩形 

void EGEAPI arcf(float x, float y, float stangle, float endangle, float radius, PIMAGE pimg = NULL);                    // 画圆弧
void EGEAPI circlef(float x, float y, float radius, PIMAGE pimg = NULL);                                                // 画圆
void EGEAPI pieslicef(float x, float y, float stangle, float endangle, float radius, PIMAGE pimg = NULL);               // 画填充圆扇形
void EGEAPI ellipsef(float x, float y, float stangle, float endangle, float xradius, float yradius, PIMAGE pimg = NULL);// 画椭圆弧线
void EGEAPI fillellipsef(float x, float y, float xradius, float yradius, PIMAGE pimg = NULL);                           // 画填充椭圆
void EGEAPI sectorf(float x, float y, float stangle, float endangle, float xradius, float yradius, PIMAGE pimg = NULL); // 画填充椭圆扇形

void EGEAPI bar(int left, int top, int right, int bottom, PIMAGE pimg = NULL);                             // 画无边框填充矩形
void EGEAPI bar3d(int left, int top, int right, int bottom, int depth, int topflag, PIMAGE pimg = NULL);   // 画有边框三维填充矩形

void EGEAPI fillrect(int left, int top, int right, int bottom, PIMAGE pimg = NULL);                      //画填充矩形 
void EGEAPI fillroundrect(int left, int top, int right, int bottom, int xradius, int yradius, PIMAGE pimg = NULL); //画填充圆角矩形 

void EGEAPI drawpoly(int numpoints, const int *polypoints, PIMAGE pimg = NULL);     // 画多边形
void EGEAPI drawlines(int numlines, const int *polypoints, PIMAGE pimg = NULL);     // 画多条不连续线(扩展函数)
void EGEAPI drawbezier(int numpoints, const int *polypoints, PIMAGE pimg = NULL);   // 画bezier曲线(扩展函数)
void EGEAPI fillpoly(int numpoints, const int *polypoints, PIMAGE pimg = NULL);     // 画填充的多边形
void EGEAPI fillpoly_gradient(int numpoints, const ege_colpoint* polypoints, PIMAGE pimg = NULL); // 画渐变填充的多边形
void EGEAPI floodfill(int x, int y, int border, PIMAGE pimg = NULL);                // 按边界颜色填充区域
void EGEAPI floodfillsurface(int x, int y, color_t areacolor, PIMAGE pimg = NULL);  // 按起始点颜色填充区域

#ifdef EGE_GDIPLUS
// 高级绘图函数(带AA)
// ege new_api
void EGEAPI ege_enable_aa(bool enable, PIMAGE pimg = NULL);

void EGEAPI ege_line(float x1, float y1, float x2, float y2, PIMAGE pimg = NULL);
void EGEAPI ege_drawpoly(int numpoints, ege_point* polypoints, PIMAGE pimg = NULL);
void EGEAPI ege_drawcurve(int numpoints, ege_point* polypoints, PIMAGE pimg = NULL);
void EGEAPI ege_rectangle(float x, float y, float w, float h, PIMAGE pimg = NULL);
void EGEAPI ege_ellipse(float x, float y, float w, float h, PIMAGE pimg = NULL);
void EGEAPI ege_pie(float x, float y, float w, float h, float stangle, float sweepAngle, PIMAGE pimg = NULL);

void EGEAPI ege_arc(float x, float y, float w, float h, float stangle, float sweepAngle, PIMAGE pimg = NULL);
void EGEAPI ege_bezier(int numpoints, ege_point* polypoints, PIMAGE pimg = NULL);

void EGEAPI ege_fillpoly(int numpoints, ege_point* polypoints, PIMAGE pimg = NULL);
void EGEAPI ege_fillrect(float x, float y, float w, float h, PIMAGE pimg = NULL);
void EGEAPI ege_fillellipse(float x, float y, float w, float h, PIMAGE pimg = NULL);
void EGEAPI ege_fillpie(float x, float y, float w, float h, float stangle, float sweepAngle, PIMAGE pimg = NULL);

void EGEAPI ege_setpattern_none(PIMAGE pimg = NULL);
void EGEAPI ege_setpattern_lineargradient(float x1, float y1, color_t c1, float x2, float y2, color_t c2, PIMAGE pimg = NULL);
void EGEAPI ege_setpattern_pathgradient(ege_point center, color_t centercolor,
	int count, ege_point* points, int colcount, color_t* pointscolor, PIMAGE pimg = NULL);
void EGEAPI ege_setpattern_ellipsegradient(ege_point center, color_t centercolor,
	float x, float y, float w, float h, color_t color, PIMAGE pimg = NULL);
void EGEAPI ege_setpattern_texture(PIMAGE srcimg, float x, float y, float w, float h, PIMAGE pimg = NULL);

void EGEAPI ege_drawtext(LPCSTR  textstring, float x, float y, PIMAGE pimg = NULL);
void EGEAPI ege_drawtext(LPCWSTR textstring, float x, float y, PIMAGE pimg = NULL);

void EGEAPI ege_setalpha(int alpha, PIMAGE pimg = NULL);
void EGEAPI ege_gentexture(bool gen, PIMAGE pimg = NULL);
void EGEAPI ege_puttexture(PCIMAGE srcimg, float x, float y, float w, float h, PIMAGE pimg = NULL);
void EGEAPI ege_puttexture(PCIMAGE srcimg, ege_rect dest, PIMAGE pimg = NULL);
void EGEAPI ege_puttexture(PCIMAGE srcimg, ege_rect dest, ege_rect src, PIMAGE pimg = NULL);

//draw image
void EGEAPI ege_drawimage(PCIMAGE srcimg,int dstX, int dstY,PIMAGE pimg = NULL);
void EGEAPI ege_drawimage(PCIMAGE srcimg,int dstX, int dstY, int dstWidth, int dstHeight, int srcX, int srcY, int srcWidth, int srcHeight,PIMAGE pimg = NULL);

// matrix for transformation
typedef struct ege_transform_matrix{
	float m11;
	float m12;
	float m21;
	float m22;
	float m31;
	float m32;	
}ege_transform_matrix;

//transforms
void EGEAPI ege_transform_rotate(float angle,PIMAGE pimg = NULL);
void EGEAPI ege_transform_translate(float x,float y,PIMAGE pimg = NULL);
void EGEAPI ege_transform_scale(float scale_x, float scale_y,PIMAGE pimg = NULL);
void EGEAPI ege_transform_reset(PIMAGE pimg = NULL);
void EGEAPI ege_get_transform(ege_transform_matrix* pmatrix, PIMAGE pimg = NULL);
void EGEAPI ege_set_transform(ege_transform_matrix* const pmatrix, PIMAGE pimg = NULL);
ege_point EGEAPI ege_transform_calc(ege_point p, PIMAGE pimg = NULL); // Calculate transformed coordination of p; 
ege_point EGEAPI ege_transform_calc(float x, float y, PIMAGE pimg = NULL); // Calculate transformed coordination of point(x,y);

//
#endif

三、时间函数

1.api_sleep

功能:
单纯延迟指定时间(精确程度由系统API决定),其它事情什么都不干。
可以多线程下使用,非图形(worker)线程的sleep使用这个。

声明:
VOID api_sleep(long dwMilliseconds);

参数: dwMilliseconds 要延迟的时间,以毫秒为单位,如果为0则不产生延时的作用(相当于无意义调用)。不附带刷新窗口的作用。

因为接下来的内容相对来说比较简单,就不放示例程序了。

2. ege_sleep

功能:
至少延迟以毫秒为单位的时间。

声明:
void ege_sleep(long Milliseconds);

参数: Milliseconds  dwMilliseconds 要延迟的时间,以毫秒为单位。

3.delay

功能:
至少延迟以毫秒为单位的时间,不具有刷新窗口的功能。

声明:
void delay(long Milliseconds);

参数: Milliseconds 要延迟的时间,以毫秒为单位 

4.delay_ms

功能:
平均延迟以毫秒为单位的时间, 具有刷新窗口的功能。
可以使用delay_ms(0)只刷新不延迟,并且会判断是否有刷新的需要

声明:
void delay_ms(long Milliseconds);

参数: Milliseconds 要延迟的时间,以毫秒为单位
 

5.delay_fps

功能:
延迟以FPS为准的时间,以实现稳定帧率,具有刷新窗口的功能。

声明:
void delay_fps(long fps); 
void delay_fps(double fps);

参数: fps 要得到的帧率,平均延迟1000/fps毫秒,并更新FPS计数值。这个函数一秒最多能调用fps次。 

6.delay_jfps

功能:
延迟以FPS为准的时间,以实现稳定帧率(带跳帧)。

声明:

void delay_jfps(long fps); 
void delay_fps(double fps); 

参数: fps 要得到的帧率,平均延迟1000/fps毫秒,并更新FPS计数值。这个函数一秒最多能调用fps次。注意的是,即使这帧跳过了,仍然会更新FPS计数值。 

7.fclock


功能:
获取当前程序从初始化起经过的时间,以秒为单位

声明:
double fclock();

参数: (无)

返回值: 返回一个以秒为单位的浮点数,精度比API的GetTickCount稍高。程序中使用一般用于求时间差,一般不要直接使用这个值。 

四、总结

结束了绘图函数和时间函数后,下一期我们将会讲一讲颜色表示及相关函数。

我们下次继续! 

上一期:DEV-C++ ege.h库 绘图教程(二)

下一期:未出

  • 23
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值