Some Useful Functions

社区服务
高级搜索
猴岛论坛CSGO反恐精英CS作弊器交流讨论Some Useful Functions
发帖 回复
倒序阅读 最近浏览的帖子最近浏览的版块
0个回复

Some Useful Functions

楼层直达
作弊辅导员_h

ZxID:1019634

等级: 元老
定做作弊器
举报 只看楼主 使用道具 楼主   发表于: 2007-07-25 0
Don't you hate having to make of vertex's every time you want to make a box?
What about making the border around the box?

If you said yes then this tutorial is for you. I have put together some prefab functions that could save a lot of time and effort when drawing boxes and the border around them.

These may seem simple but they help a lot when you are drawing menus and many other things.

To draw a Box I use this Function:

void DrawBox(int x, int y, int wi, int he)
{ //x, y, width, height
    glBegin(GL_QUADS);
    glVertex2i(x, y);
    glVertex2i(x + wi, y);
    glVertex2i(x + wi, y + he);
    glVertex2i(x, y + he);
    glEnd();
}

Basically this puts all the boxes you draw into one little code segment.

Instead of this:

glBegin(GL_QUADS);
    glVertex2i(x, y);
    glVertex2i(x + wi, y);
    glVertex2i(x + wi, y + he);
    glVertex2i(x, y + he);
glEnd();
glBegin(GL_QUADS);
    glVertex2i(x, y);
    glVertex2i(x + wi, y);
    glVertex2i(x + wi, y + he);
    glVertex2i(x, y + he);
glEnd();
glBegin(GL_QUADS);
    glVertex2i(x, y);
    glVertex2i(x + wi, y);
    glVertex2i(x + wi, y + he);
    glVertex2i(x, y + he);
glEnd();
You get this:
DrawBox(x, y, wi, he);
DrawBox(x, y, wi, he);
DrawBox(x, y, wi, he);

Oh But now you want a box with a border around it...

OK here's the old code:

glBegin(GL_QUADS);
    glVertex2i(x, y);
    glVertex2i(x + wi, y);
    glVertex2i(x + wi, y + he);
    glVertex2i(x, y + he);
glEnd();
glLineWidth(line);
glBegin(GL_LINE_LOOP);
    glVertex2i(x, y);
    glVertex2i(x + wi, y);
    glVertex2i(x + wi, y + he);
    glVertex2i(x, y + he);
glEnd();

And here is the new one:

DrawBox(x, y, wi, he);
DrawLines(1.0f, x, y, wi, he);

You asking what the DrawLines command is?
Well this is it:

void DrawLines(float line, int x, int y, int wi, int he)
{
    glLineWidth(line);
    glBegin(GL_LINES);
        glVertex2i(x, y);
        glVertex2i(x + wi, y);
        glVertex2i(x + wi, y + he);
        glVertex2i(x, y + he);
    glEnd();
    glBegin(GL_LINE_LOOP);
        glVertex2i(x, y);
        glVertex2i(x + wi, y);
        glVertex2i(x + wi, y + he);
        glVertex2i(x, y + he);
    glEnd();
}

With the help of these new prefab functions you can compress your 500 line code, to draw your menu, into approximately 75 lines!





密码被盗,请联系cscheat取回
« 返回列表
发帖 回复