English 中文(简体)
开放式GL+GLUT 不要填充最重的独角大楼?
原标题:OpenGL+GLUT Not filling Topmost-Leftmost Polygon?

I m 碰到一个奇怪的开放式GL Bug。 开放式教育对我来说是很新的,但我们要求将其用于我的独立职业学校(因为教师实际上是制图教授)。

无论是哪种方式,情况都是:http://img818.imageshack.us/img818/422/reversiothello.png”http://img818.imageshack.us/img818/422/reversiothello.png/a。

这只发生在最顶端,最左.。 换言之,它发现最恶劣的多环形断裂,然后是最恶劣的,它确实如此。 (目前还不是从板上抹掉多角。)

我的展示职能是:

void display_func(void)
{
    glClearColor(0.0, 0.45, 0.0, 1.0); // Background Color (Forest Green :3)
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);

    draw_board();

    glFlush();

    glutSwapBuffers();
};

My draw_board function is this:

void draw_board()
{
    int size = 8;
    int stepX = WINDOW_XS / size;
    int stepY = WINDOW_YS / size;

    glColor3f(0.0,0.0,0.0); // line color black

    glBegin(GL_LINES);

    // Draw Columns
    for(int i = 0;i <= WINDOW_XS;i += stepX)
    {
        glVertex2i(i,0);
        glVertex2i(i, WINDOW_YS);
    }

    // Draw Rows
    for(int j = 0;j <= WINDOW_YS;j += stepY)
    {
        glVertex2i(0, j);
        glVertex2i(WINDOW_XS, j);
    }

    // Draw Circles
    for(int i = 0;i < 8;++i)
    {
        for(int j = 0;j < 8;++j)
        {
            if(engine->getOnBoard(i,j) == Reversi::PIECE_NONE) continue;
            if(engine->getOnBoard(i,j) == Reversi::PIECE_WHITE)
                glColor3f(1.0,1.0,1.0);
            if(engine->getOnBoard(i,j) == Reversi::PIECE_BLACK)
                glColor3f(0.0,0.0,0.0);

            int drawX = ((i+1)*64)-32;
            int drawY = 512-((j+1)*64)+32;
            gl_drawCircle(drawX,drawY,30);
        }
    }

    glEnd();
};

我的改变职能是:

void mouse_func(int button, int state, int x, int y)
{
    if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && x < WINDOW_XS)
    {    
        // row and column index
        x = (int)( x / (WINDOW_XS/8) );
        y = (int)( y / (WINDOW_YS/8) );

        std::cout << "Attempting to make a move at " << x << "," << y << std::endl;

        if(engine->makeMove(x,y))
        {
            glutPostRedisplay();
        }
    }
};

and my gl_drawCircle function is this:

void gl_drawCircle(float x, float y, float r)
{
    // http://stackoverflow.com/questions/5094992/c-drawing-a-2d-circle-in-opengl/5095188#5095188
    glBegin( GL_POLYGON );
    float t;
    int n;
    for(t = 0,n = 0; n <= 90; ++n, t = float(n)/90.f ) // increment by a fraction of the maximum 
    {
        glVertex2f( x + sin( t * 2 * PI ) * r, y + cos( t * 2 * PI ) * r );
    }
    glEnd();
}

谁能帮助我?

最佳回答

The only bug worth giving an answer that I can find is that your draw_board function doesn t use properly the glBegin and glEnd statements. You have to use a glEnd statement before calling gl_drawCircle, otherwise you ll get a nasty behavior.

Edit: 您首先使用“glBegin 被忽视(因为你在glBegin上)。 所有其他圈子都是ok,因为你在打上<条码>(glEnd前再读到<条码>。 第一圈是左上、最上层。

问题回答

You need a call to glEnd after drawing the rows. When you do not call glEnd, OpenGL ignores your call glBegin( GL_POLYGON ); and assumes you still want to draw lines.

So just adding glEnd (); after drawing the rows should solve it.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签