问一下怎么在dev-c++上使用graphics.h

问一下怎么在dev-c++上使用graphics.h,第1张

下载地址:百度网盘链接

将ege ,ege.h ,graphics.h复制到Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include

将压缩包内

lib\mingw64\lib

目录下的

libgraphics64.a

复制,粘贴到

C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2

目录下

在上方菜单栏选择 工具->编译选项 填入 -lgraphics64 -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32

分享一下好代码:

#include "graphics.h"

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

#include "ege/fps.h"

int width = 640, height = 480

struct point //定义点,包含坐标,速度

{

    double x

    double y

    double dx

    double dy

}

struct poly //定义多边形,包含点的个数,和点数组

{

    int n_point

    point p[20]

}

struct polys //定义多边形队列组

{

    int n_poly                 //多边形队列长度

    int color                  //颜色

    int nextcolor, prevcolor   //上一次的颜色,目标颜色

    int chtime, nowtime        //过渡变化时间,当前时间

    int time                   //距离一下次改变颜色的时间

    poly p[100]                //多边形数组

}

double rand_float(double dv, double db) //返回一个db 到 db+dv之间的随机浮点数

{

    return randomf()*dv + db

}

void movepoint(struct point* b) //根据点的速度属性移动这个点,如果移出屏幕则进行反d计算

{

    double dv = 1.0, db = 0.5

    double tw = width / 640.0, th = height / 480.0

    if (b->x <0) b->dx = rand_float(dv, db) * tw

    if (b->y <0) b->dy = rand_float(dv, db) * th

    if (b->x >width) b->dx = -rand_float(dv, db) * tw

    if (b->y >height) b->dy = -rand_float(dv, db) * th

    b->x += b->dx

    b->y += b->dy

}

void movepoly(struct poly* p) //移动单个多边形,内部调用点的移动

{

    int i

    for (i=0i<p->n_point++i)

    {

        movepoint(&(p->p[i]))

    }

}

void movepolys(struct polys* p) //移动多边形队列,包含时间检测,颜色计算

{

    int i

    for (i=p->n_poly-1i>0--i)

    {

        p->p[i] = p->p[i-1]

    }

    movepoly(p->p)

    ++(p->nowtime)

    if (--(p->time) <= 0)

    {

        p->prevcolor = p->color

        p->nextcolor = HSVtoRGB((float)random(360), 1.0f, (float)rand_float(0.5, 0.5))

        p->time = random(1000)

        p->chtime = random(1000)+60

        p->nowtime = 0

    }

    if (p->nowtime >= p->chtime)

    {

        p->color = p->nextcolor

    }

    else

    {

        double dr = p->prevcolor&0xFF, dg = (p->prevcolor>>8)&0xFF, db = (p->prevcolor>>16)&0xFF

        double dt = 1 - p->nowtime / (double)(p->chtime)

        dr -= p->nextcolor&0xFF, dg -= (p->nextcolor>>8)&0xFF, db -= (p->nextcolor>>16)&0xFF

        dr *= dt, dg *= dt, db *= dt

        dr += p->nextcolor&0xFF, dg += (p->nextcolor>>8)&0xFF, db += (p->nextcolor>>16)&0xFF

        p->color = ((int)dr) | ((int)dg<<8) | ((int)db<<16)

    }

}

void initpolys(struct polys* p, int npoly, int npoint) //初始化多边形队列组

{

    int i,j

    p->n_poly = npoly

    p->color = 0

    p->time = 1000

    p->prevcolor = p->color

    p->nextcolor = HSVtoRGB((float)random(360), 1.0f, 0.5f)

    p->chtime = 1000

    p->nowtime = 0

    j = 0

    p->p[j].n_point = npoint

    for (i=0i<npoint++i)

    {

        p->p[j].p[i].x = random(width)

        p->p[j].p[i].y = random(height)

        p->p[j].p[i].dx = (randomf() * 2 + 1)

        p->p[j].p[i].dy = (randomf() * 2 + 1)

    }

    for (j=1j<npoly++j)

    {

        p->p[i] = p->p[i-1]

    }

}

void draw_poly(struct poly* p, int color) //绘制一个多边形

{

    int points[100]

    int i

    for (i=0i<p->n_point++i)

    {

        points[i*2  ] = (int)(p->p[i].x+.5f)

        points[i*2+1] = (int)(p->p[i].y+.5f)

    }

    points[i*2  ] = (int)(p->p[0].x+.5f)

    points[i*2+1] = (int)(p->p[0].y+.5f)

    setcolor(color)

    drawpoly(p->n_point+1, points)

}

void draw_polys(struct polys* p) //绘制多边形队列(只画第一个和最后一个,最后一个用于擦除)

{

    draw_poly(&(p->p[p->n_poly-1]),        0)

    draw_poly(&(p->p[          0]), p->color)

    //for (int i = 0i <4++i)

    //    draw_poly(&(p->p[i]), p->color)

}

int main()

{

    static struct polys p[10] = {{0}}

    int n_points[10] = {4,3,5,6,7}

    int n_poly[10] = {80,40,10,5,1}

    int n_polys = 2, i

    randomize()

    //图形初始化

    {

        setinitmode(1, 0, 0)

        initgraph(-1, -1)

        width  = getmaxx()

        height = getmaxy()

        setrendermode(RENDER_MANUAL)

    }

    //多边形对象初始化

    for (i=0i<n_polys++i)

    {

        initpolys(&p[i], n_poly[i], n_points[i])

    }

    setfont(12, 6, "宋体")

    fps ui_fps

    //主循环

    for ( is_run()delay_fps(60))

    {

        if (kbhit() >0) //有按键按下就退出

        {

            break

        }

        for (i=0i<n_polys++i)

        {

            movepolys(&(p[i]))

        }

        for (i=0i<n_polys++i)

        {

            draw_polys(&(p[i]))

        }

        //imagefilter_blurring(NULL, 0xff, 0x100)

    }

    closegraph()

    return 0

}

1.DEV-CPP中没有图形函数GRAPHICS,你可以去下载SDL,专门用于游戏开发和图形设计

具体这么做: 工具->检查更新->选择第2项检查一下->选择SDL进行更新...

2.给你看段代码参考下:(在dev-cpp4992上运行正常。)

#include

#include

#include

using namespace std

int main( void )

{

COORD pos = { 10, 15 }

SetConsoleCursorPosition( GetStdHandle(STD_INPUT_HANDLE), pos )

SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), pos )

SetConsoleCursorPosition( GetStdHandle(STD_ERROR_HANDLE), pos )

cout <<"这里就是第10行第15列。" <<endl

system( "pause" )

}

3。如果是4.9.6.0就好办得多.

先找到:菜单 Project->project Options ->"General "中的 "Linker Options/Optonal Libs or Obeject files ",在下面空白处,输入: "C:\Dev-Cpp_gcc321\Dev-Cpp\lib\conio.o "

C:\Dev-Cpp_gcc321\Dev-Cpp 是我的DEV_CPP的目录,你做适当修改即可,但注意要用引号 " "括起来.

再按 "ok ",

重新编译链接即可.

对于 DEV-c++ 4.9.6.0, conio.o文件在..\lib 目录下, 4.9.7.0中没有这个文件 .

DEV-C++中没有graphics.h这个头文件

4。在dev c++中添加graphics

Dev-C++ User F.A.Q.

看到下面的步骤就可以了

How do I use Borland Graphics Interface (graphics.h)?

For those of you migrating from Borland, you may be wondering where graphics.h is. Unfortunately, graphics.h is a Borland specific library and cannot be used with Dev-C++. Fortunately, a benevolent soul by the name of Michael Main has modified a BGI emulation library for Windows applications to be used under MinGW (and therefore Dev-C++) which he has aptly named WinBGIm.

The files we need are:

graphics.h (download to C:\Dev-Cpp\include)

libbgi.a (download to C:\Dev-Cpp\lib)

将上面这两个文件下载,放入Dev-Cpp的目录,(如上)

After you have downloaded the files to the correct locations, you can now use WinBGIm's graphic.h as you would Borland's graphics.h with a few caveats.

Using library files:

First, you have to tell Dev-C++ where to find the library functions that WinBGIm references--this is done in the "Project Options" dialog box.

Here are instructions on how to do this with a new project:

创建一个工程,选择工程属性-参数,添加以下的几个连接,如图

Follow step 2 and step 3 of "Using Dev-C++".

Go to "Project" menu and choose "Project Options" (or just press ALT+P).

Go to the "Parameters" tab

In the "Linker" field, enter the following text:

-lbgi

-lgdi32

-lcomdlg32

-luuid

-loleaut32

-lole32

Project Options ->Parameters:

Click "OK".

Follow step 4, step 5 and step 6 of "Using Dev-C++".

BGI and WinBGIm differences:

WinBGIm is a superset of BGI and as such may have functions and features with which you are unfamiliar. See Michael Main's BGI Documentation for more information.

Test code:

Just to make sure you've got everything set up correctly, try this test code in a new Dev-C++ WinBGIm project:

#include

int main()

{

initwindow(400,300)//open a 400x300 graphics window

moveto(0,0)

lineto(50,50)

while(!kbhit())//wait for user to press a key

closegraph() //close graphics window

return 0

}If you've done everything correctly, you should get a simple graphic that closes when the user presses a key.

最后这个是一个测试,看是否成功。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11685368.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存